Hoping for some help getting a template sensor to update when it should.
I have a simple template sensor to return the min and max values of a couple of other entities, as attributes:-
- sensor:
- unique_id: sensor.ipad_white_battery_info
name: iPad White battery info
icon: mdi:battery-alert
variables:
HAPP: "{{ states('sensor.ipad_air_white_battery_level') | int }}"
ICLOUD: "{{ states('sensor.ipad_white_battery') | int }}"
state: "{{ states('sensor.ipad_air_white_battery_state') }}"
attributes:
lo: "{{ min(HAPP,ICLOUD) }}"
hi: "{{ max(HAPP,ICLOUD) }}"
unit_of_measurement: "%"
The above is from an included templates: file. The templates are correct, work in the Template tester and when 'Template entities' are reloaded, the above sensor returns the correct values in the attributes. My problem is that they never update, even when the entity states on which they're based have changed - until I reload the 'Template entities'.
My understanding is that changes in those states should trigger an update to the sensor, but that appears to not be the case.
Thinking that to trigger an update, the sensor's 'state' value needs to change, I added the values of the other entities' states into this sensors 'state':-
- sensor:
- unique_id: sensor.ipad_white_battery_info
name: iPad White battery info
icon: mdi:battery-alert
variables:
HAPP: "{{ states('sensor.ipad_air_white_battery_level') | int }}"
ICLOUD: "{{ states('sensor.ipad_white_battery') | int }}"
MINIMUM: "{{ min(HAPP,ICLOUD) }}"
MAXIMUM: "{{ max(HAPP,ICLOUD) }}"
state: "{{ MINIMUM|string+'<'+states('sensor.ipad_air_white_battery_state')+'<'+MAXIMUM|string }}"
attributes:
lo: "{{ MINIMUM }}"
hi: "{{ MAXIMUM }}"
unit_of_measurement: "%"
That will work I thought as my sensor's 'state' is now dependent on the values of those other entities 'states' and so should update when they change.
But the sensor still doesn't update when those other entities' states change.
I must be misunderstanding something here. If the state value changes for any other entity that is used in this sensor's 'state' template, should this sensor not update?