I have a sensor set up that changes after if a motion detector hasn’t been triggered for some time:
The template evaluates correctly however the sensor always shows the sensor to be on since hass version 29.6.
Any idea?
configuration.yaml:
binary_sensor
- platform: template
sensors:
hall_movement:
friendly_name: Hall Movement
value_template: '{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.hall_motion.last_changed) <= 1800) and is_state("binary_sensor.hall_motion","off")}}'
I noticed the same behavior since I updated from 28.x.
The GUI is not updated in the same frequency as before it seems as the template renders to the expected value in the developer tools but on the GUI it remains on the same value.
I track the status of a MQTT device based on when the last update was done using:
{{ relative_time(states.sensor.study_heartbeat.last_changed) }}
This in the GUI always renders to 0 seconds but under the developer tools it shows the correct value.
@balloob is there something changed in the way the GUI is updated here?
Cheers Daniel for pointing this out.
Not sure what the status is though as I see several opinions on this issue
Adding a time sensor to make sure time sensitive sensors are updated regularly is hopefully an interim work around as it defeats the automation objective here…
The problem is not only with relative_time but with anything you do on the GUI with time functions, eg:
{% if states.switch.valve_1.state == ‘on’%}Opened {{((as_timestamp(now()) - as_timestamp(states.switch.valve_1.last_changed)) / 60) | round(0) }} minutes ago{% else %}Closed{% endif %}
Shows Closed or Opened based on based on the state but the as_timestamp(states.switch.valve_1.last_changed) will always result in zero in this case so it will always show “Opened 0 minutes ago”