I’m having trouble referencing a templated sensor I defined in another templated sensor. What is the appropriate way to do this?
Below I’m defining Time Since Last Activity which is appearing in the overview and template editor, but every way I try to reference it in my Household Status sensor or in the template editor returns None. What am I doing wrong here?
-template
-sensor
- name: Time Since Last Activity
state: >
{%-
set entities = [
states.binary_sensor.multiupperhall_motion_detection_2,
states.binary_sensor.multiliving_motion_detection_2,
states.binary_sensor.multisensor_6_motion_detection,
states.binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_2,
states.binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_3,
states.binary_sensor.lumi_lumi_sensor_magnet_aq2_opening
]
%}
{% for entity in entities %}
{% if as_timestamp(entity.last_changed) == as_timestamp(entities | map(attribute='last_changed') | max) %}
{{ as_timestamp(now()) - as_timestamp(entity.last_changed) }}
{% endif %}
{% endfor %}
- name: Household Status
state: >
{% if sensor.Time_Since_Last_Activity > 3600 %} # inactive for at least an hour
...etc.