WTH - Just...WTH Attributes!

Attributes are the biggest single headache I have with HA.
Much discussion has gone into this topic and most of the posts end with someone pointing out that “eventually” attributes will disappear.
The reality seems to be that it will be years, if not decades, for every integration developer to fully convert attributes over to separate entities.

A potential solution would be to create a UI page that lists a device’s attributes and automate the process of creating template sensors and assign them to the host device.
This can currently be done with a tedious manual process in yaml but is not beginner friendly.

If users could easily create a helper that derived its value fr an attribute, that would be awesome. Bonus for nesting that derived sensor into the device of the entity that provides the attribute.

Currently you can do it with the template helper, but template helper doesn’t seem to have availability template.

1 Like

Attributes rather than metadata (like min-max, possible states, etc) should die. It’s just a bad design, entity is not a container - device is.

I just want to have a sensor based on an attribute. I could not make it happen with the complicated template stuff. It should be much easier.

I find attributes great.
I would not want them to go, they give us possibilities to add more data to one single sensor than just the state can hold.
It would be more or less impossible to have API connections with just states.

6 Likes

Template sensor helper, state template:

{{ state_attr('climate.my_heating', 'temperature') }}

That’s it. Admittedly there could be a UI solution that provides drop-downs and the like, but this is not “complicated”.

2 Likes

Some of them are a bit more complicated than that, like nested attributes.
But then again, if you have nested attributes then you could not do it without the attributes in the first place.
But the developer tools is a great place to learn and test how to set up a template.

Unfortunatelly not everywhere you can use templates, so creation of interim sensor is frequently a must. I’d rather love HA to automatically create sort of virtual entities based on attributes. So in case @Troon shown it would be sufficient to use entity name climate.my_heating.temperature and then HA would treat it as regular entity. It would make our lives so easier…

Thanks. i tried this already. In my entity the attributes names start with uppercase letters. I just changed it to lower case. now it works.
Even if you consider it easy, there are still some things to have an eye on.

You need to look in Developer tools to get the real names of attributes

1 Like

Watch out for the front end trying to be helpful. Depending where you looked, they might have been “translated”. Developer Tools / States gives the true picture:

1 Like

That is correct. But that makes things a little more complicated

Kind of agree. I think the frontend should display real values and not beautified, but just knowing to not look there is enough

1 Like

the state of an entity is limited to a max of 255 characters. Attributes are limited to (I think) 16k characters.

Attributes are a literal must have in certain instances.

The two examples I can think of are both weather related…

the forecast of a weather service would never be able to fit into a sensor state.

and I maintain a NWS severe weather alert integration that needs to have the alert information in the attributes. I’m fairly positive that even the info for 1 alert would exceed the 255 character limit of a sensor.

I’m sure there are many more examples but those are the most obvious off the top of my head.

I have never run into an attribute that I couldn’t extract from an entity.

3 Likes

Entity has been a data container forever. The UI may not show it, but it is.

Attributes are helpful if used in proper way.

The example of heating found a few posts above exploits this property in the wrong way.

For example

  • If current_temperature attribute changes, HA has to update the whole state.
  • To track this temperature with automation, the app must track state changes to look at possible temperature changes.

Also, updating state, or one of the attributes, means that all data of the sensor has to be updated in db.

In that way of using is… suboptimal.

1 Like

I have made a helper which is available in hacs which is more UI friendly than templates GitHub - gjohansson-ST/attribute_as_sensor: Home Assistant use an entity's attribute as a new sensor helper

1 Like

And what if all those was entities instead?
It would be very long names on some of the entities and it would clutter the developer tools.
Now you just have one big block you can scroll past

Personally I much prefer attributes over entities. Why? Because entity states are for some reason always a string, while state_attr immediately returns the “correct” variable type (number, date, whatever).

1 Like

not 100% true.
Json is not strict typed and has no validator as xml has.

Lot of developers put there strings picked directly from 3rd party APIs, not even trying to validate them or convert to normalized datatypes.

So… yes, if a developer puts there numbers or booleans… then they are numbers of booleans. Things gets less obvious in case of time. there is consensus about using ISO formatted time, but often found values don’t comply the standard.