I’m trying to create a template sensor that shows the number of minutes since last motion in the house.
This template works as expected when I try it in the Template Editor. But the template sensor with the exact same code always stays on value 0 whole day. Can you help?
- platform: template
sensors:
since_last_motion:
friendly_name: 'Minutes since last motion'
value_template: >
{%- set sensors = [states.binary_sensor.pir_woonkamer, states.binary_sensor.pir_toilet, states.binary_sensor.pir_hal, states.binary_sensor.pir_badkamer, states.binary_sensor.door_trapkast] %}
{% for sensor in sensors %}
{% if as_timestamp(sensor.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{{ (( as_timestamp(now()) - as_timestamp(sensor.last_changed)) / 60 ) | int }}
{% endif %}
{% endfor %}