What I am trying to do is that the icon should be updated based on the door’s status. The status comes from a dummy unit in the form of a dimable light (light.door_status). The icon changes when I lock / unlock the door, but if the door is unlocked and I open the door, the icon does not change.
Does anyone have a tip on how to do this if it is even possible?
there’s too many unknowns here. Where are you getting this light.door_status entity? Are you certain the light brightness is changing when you open the door or close the door?
I am 100% sure that those dim levels are correct, they come from z-wave Id-Lock and Telldus Z-net v2. The only time icon changes is when i lock/unlock the door. I would like the icon to change even when i open/close the door without locking it.
It seems that the icon only updates when state changes.
I understand that but the problem is clearly with the light.door_status portion of all your code. None of the statements using is_state_attr('light.door_status', 'brightness', x) are resolving to true. Otherwise you’d get a door open / door closed.
So with that being said you need to figure out what the true value for that attribute is.
It state true when i set value to current “brightness” and false if i set it othervise. An if i paste the entire template it tells me correct mdi:icon.
What i try to find out is if there are any setting och function to force update even if state dont change. I made a sensor with exact that templat and it works.
Changing attributes is considered a state change. But if you just want to force it, you can use the homeassistant.update_entity service. Documented on the template sensor page
I found a solution, i changed "value_template: “{{ is_state(‘switch.doorlock’, ‘on’) }}” to “{{ is_state(‘sensor.door_status’, ‘Låst’) }}” and use the sensor that worked.
Now the switch react to every event.
There were no misspelling, seems as if the icon only update when value_template change.
By the way, do you know if there is possible to add a sensor value as attribute in template switch?
Never tried. From what I remember, back in the day you used to be able to set attributes via the customize section. But I don’t know if you can change them on the fly. Might require an automation. Also, if you are getting that complex, you can just make your own components.
I wish, i have tried to check that with custom_component and such. My head starts to spin on an instant and i give up.
Maybe i dig in to that some day.