Since the update to 2025.4.0 I do receive an error that the state_class is missing for some template sensors.
If I do add a State class in the code it gives an error it is not allowed to give state class in template sensors.
my code:
If the availability template resolves to false because one of your source sensors is not returning a number then the state template is not evaluated (which would cause an error or odd reading) and the template sensor is marked as unavailable. Why an availability template is important for energy template sensors
I do like to ask another question about the new sensors if allowed.
I do have a lot of legacy build sensors, so I try to change them to the new standard.
Thats working well, but I do have one situation I do not understand:
I do have an old sensor:
Then I do receive an error in my card: ButtonCardJSTemplateError: TypeError: Cannot read properties of undefined (reading 'state') in 'if (states["sensor.mancave_licht"].state > 0) return <ha-icon icon=“mdi:lightbulb” …'`
What can be the reason for this error?
Yes sorry about that it was a string, but because the error I tried to change to number
I checked on entitie sensor.macave_licht. It is not existing, so not created by the sensor It is creating sensor.aantal_lampen_mancave instead
So I conclude that unique_id is not creating the sensor name
So my conclusion is that unique_id is doing nothing.
The sensor name is created from name.
At Unique Id the template description says:
The unique ID for this config block. This will be prefixed to all unique IDs of all entities in this block.
To be honest I do not understand what that means
Unique_id is an id in the system that lets HA know what configuration it is. It does not generate the entity_id unless you omit a name. The entity_id is generated from name. If you remove unique_id, you risk getting duplicate entities sensor.mancave_licht, sensor.mancave_licht_2, etc every time you reload templates. Unique_id prevents that and allows you to modify the entity in the UI.
Yes as your sensor has a unique id you can change the name in the UI without affecting the entity id.
Old way you could have a different name to entity id. New way the entity id is generated from the name. So if you want a different name to entity id you either have to use manual customization (not recommended) or make sure the sensor has a unique id so you can change the name to whatever you want in the UI.
I’m going to attempt to reintroduce this ability in the modern style templates. Not making any promises though, historically it’s been rejected. However it’s unclear if it was rejected because of the implementation or principle behind the field.
If it gets accepted, it will be in a future release (not 2025.4).