Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Problems with the dot in the device attribute name #1795

Closed
il77781 opened this issue Aug 3, 2024 · 6 comments
Closed

Problems with the dot in the device attribute name #1795

il77781 opened this issue Aug 3, 2024 · 6 comments

Comments

@il77781
Copy link

il77781 commented Aug 3, 2024

Hello. I have a Xiaomi Mijia Smart Evaporative Cooling Fan (dmaker_p44). After adding it through this integration, there is a dot in the name of many of its attributes:
IMG_20240803_144020
These are, for example, "fan.on", "fan.fan_level", "fan.mode" and so on...
I want to use the Button Card by @RomRider (https://github.com/custom-cards/button-card ), but when I try to extract the value of such attribute using Javascript Templates,

type: custom:button-card
name: |
  [[[
    return states['fan.dmaker_p44_7a6c_fan'].attributes.fan.fan_level
  ]]]

nothing works!
I assume that the reason for this is that the java script template format used in this card does not allow for correct processing of attribute names that contain a dot.
The question is, is there any way to make the names of these attributes not contain dots?

@RomRider
Copy link

RomRider commented Aug 3, 2024

Use states['fan.dmaker_p44_7a6c_fan'].attributes['fan.fan_level'] in that case

@il77781
Copy link
Author

il77781 commented Aug 4, 2024

@RomRider, thank you very much! Yes, in that case everything works!
Maybe there is some source where I could familiarize myself with other similar nuances of the syntax available for use in java script templates for your button-card?

@il77781 il77781 closed this as completed Aug 4, 2024
@RomRider
Copy link

RomRider commented Aug 4, 2024

It's just javascript syntax, nothing specific to button card. So you'll have to look for javascript tutorials.

@il77781
Copy link
Author

il77781 commented Aug 4, 2024

@RomRider, I understand you, thank you very much again!
Unfortunately, I couldn't find a solution earlier, although I watched various tutorials... I probably should have looked deeper...
Now, however, I noticed that not all attribute values are displayed using the method described above... Although, at the same time, values for all these attributes are displayed in Developer Tools - States... But there are no errors in the card, just an empty field is displayed on the card instead of the attribute value... Perhaps it has some other reason...

@SodaWithoutSparkles
Copy link
Contributor

SodaWithoutSparkles commented Aug 5, 2024

uh, why not state_attr('entity_id', 'attribute_name') as said in the home assistant jinja docs?

Edit: just realized that you aren't using jinja. You can either create a helper/templated entity from the above, use a different card, or use the browser developer tools to inspect available attributes

@il77781
Copy link
Author

il77781 commented Aug 5, 2024

@SodaWithoutSparkles, because the @RomRider provides a different syntax for getting the attribute value...
I do everything as described here: https://github.com/custom-cards/button-card
Do you use the Button Card by @RomRider yourself?
I do not know why @RomRider decided to do as he did, but the fact remains... Perhaps you can ask him about it personally...
Before the @RomRider answered here, I solved this problem exactly as you suggested - I created the appropriate helpers sensors. But then the @RomRider wrote here what syntax to use - and it works!
Yes, for some reason, as I described above, not all values of attributes are displayed on the card. But in fact, I do not use the getting values of attributes for direct output of values of attributes on the card, but I use it, in particular, in if statements like this:

hold_action:
  action: call-service
  service: xiaomi_miot.set_miot_property
  data:
    entity_id: fan.dmaker_p44_7a6c_fan
    siid: 2
    piid: 6
    value: |
      [[[
        if (states['fan.dmaker_p44_7a6c_fan'].attributes['fan.air_cooler'] === true) return false
        else return true
      ]]]

Here I have given an example for the value of attribute (fan.air_cooler)that is not directly displayed on the card for some reason - but this, oddly enough, works...

use the browser developer tools to inspect available attributes

To be honest, I didn't quite understand what you were suggesting... Just look at values of attributes using Developer Tools? This is not suitable at all - I need these values so that the elements on the card work properly - accordingly, I need to receive these values so that they are processed in Javascript Templates of the Button Card by @RomRider...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants