Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

attributes on binary_sensor contain unit inside the state #68

Closed
1 task done
Mariusthvdb opened this issue Feb 12, 2023 · 3 comments · Fixed by #69
Closed
1 task done

attributes on binary_sensor contain unit inside the state #68

Mariusthvdb opened this issue Feb 12, 2023 · 3 comments · Fixed by #69
Labels
enhancement New feature or request

Comments

@Mariusthvdb
Copy link

Mariusthvdb commented Feb 12, 2023

Did you read the instructions?

The request

when using a template on the attributes of the binary_sensor.knmi_zon, there are 2 issue, of whihc 1 is really of importance since it impacts use of that attribute:

{{state_attr('binary_sensor.knmi_zon','Zonkans vandaag')}}

contains the unit %, which is not as it should.

Scherm­afbeelding 2023-02-12 om 15 10 52

The attribute really should only contain the value, so we can use it in other Dashboard cards, or even template/automation logic

please consider taking out the unit of the state of the attribute.

compare Buienradar entity for that:

Scherm­afbeelding 2023-02-12 om 15 25 15

secondary suggestion: consider the attributes names to use underscores and lower characters only. Frontend takes care f showing those correctly, but it would be following HA design better to be able to use:

{{state_attr('binary_sensor.knmi_zon','zonkans_vandaag')}}

thanks for considering

Additional information

this is an example of a config that wont show:

      - type: custom:mini-graph-card
        show:
          graph: bar
        entities:
          - entity: binary_sensor.knmi_zon
            name: Vandaag
            attribute: Zonkans vandaag
          - entity: binary_sensor.knmi_zon
            name: Morgen
            attribute: Zonkans morgen
          - entity: binary_sensor.knmi_zon
            name: Overmorgen
            attribute: Zonkans overmorgen

or eg the bar card:

      - type: custom:bar-card
         title: Kans op zon
        show:
          labels: true
         severity:
           - color: Grey
             from: 0
             to: 25
           - color: Skyblue
             from: 26
             to: 50
           - color: Gold
             from: 51
             to: 100
        entities:
          - entity: binary_sensor.knmi_zon
            name: Vandaag
            attribute: Zonkans vandaag
          - entity: binary_sensor.knmi_zon
            name: Morgen
            attribute: Zonkans morgen
          - entity: binary_sensor.knmi_zon
            name: Overmorgen
            attribute: Zonkans overmorgen

which seemingly shows the correct attribute, but not the graph nor the color... because the value is not as it is expected to be,

Scherm­afbeelding 2023-02-12 om 15 19 06

@Mariusthvdb Mariusthvdb added the enhancement New feature or request label Feb 12, 2023
@golles
Copy link
Owner

golles commented Feb 12, 2023

I agree it makes sense for automations/graphs that the unit is omitted for state attributes.

Be aware that in your example, comparing Buienradar, you're comparing a state with an attribute (unit_of_measurement) to something that is called extra_state_attributes, used by this integration.

I'm not sure if I want to rename the attributes (underscore), as that would be a breaking change. There are also built-in integrations that have spaces in attribute names, so I don't think it's really an issue.

@Mariusthvdb
Copy link
Author

Mariusthvdb commented Feb 12, 2023

hi, thanks for your feedback!

sure, I am aware I showed the deducted Buienradar entity, and not an attribute. Was merely trying to bring across the separated unit from the state.

on the naming of the attributes entity_id's: indeed, not a true 'issue' in that it causes a problem. tbh I can not find the exact dev design rules on this in https://developers.home-assistant.io/docs/core/entity#entity-naming

just that it is uncommon to do so.

what they do state in extra_state_attributes is that we should minimize those. so maybe break out those attributes into entities?

but, most importantly: please take out that unit ;-)

@golles golles linked a pull request Feb 12, 2023 that will close this issue
@golles
Copy link
Owner

golles commented Feb 12, 2023

I'm a little allergic to "too many sensors", hence setting relevant values into attributes :-)

Version 1.3.7 will be soon available with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants