The sensor shows up with the correct motion sensor that last detected motion, but attributes day and time are showing null
Can anyone spot anything obvious?
- sensor:
- name: "last_motion"
state: >
{% set sensors = [states.binary_sensor.pir_lux_backyard_motion,
states.binary_sensor.pir_lux_barneys_door_motion,
states.binary_sensor.pir_lux_hallway_motion,
states.binary_sensor.pir_lux_kitchen_motion,
states.binary_sensor.motion_entry,
states.binary_sensor.motion_laundry,
states.binary_sensor.motion_living_room,
states.binary_sensor.pir_bedroom_occupancy,
states.binary_sensor.camera_backyard_motion_trigger,
states.binary_sensor.camera_barney_motion_trigger] %}
{% set t = sensors | map(attribute='last_changed') | max %}
{% set s = (sensors | selectattr('last_changed', 'eq', t) | list)[0] %}
{{ s.name }}
attributes:
day: >
{{ s.last_changed.timestamp() | timestamp_custom('%d %b %y') }}
time: >
{{ s.last_changed.timestamp() | timestamp_custom('%I:%M %p') }}
My old sensor looked like this using a value template. It worked but I wanted to split up the data and thought I may as well use the new sensor template.
- platform: template
sensors:
last_motion:
friendly_name: "Last Motion Detected"
value_template: >
{% set sensors = [states.binary_sensor.pir_lux_backyard_motion,
states.binary_sensor.pir_lux_barneys_door_motion,
states.binary_sensor.pir_lux_hallway_motion,
states.binary_sensor.pir_lux_kitchen_motion,
states.binary_sensor.motion_entry,
states.binary_sensor.motion_laundry,
states.binary_sensor.motion_living_room,
states.binary_sensor.camera_backyard_motion_trigger,
states.binary_sensor.camera_barney_motion_trigger] %}
{% set t = sensors | map(attribute='last_changed') | max %}
{% set s = (sensors | selectattr('last_changed', 'eq', t) | list)[0] %}
{{s.name + ' on '}} {{s.last_changed.timestamp() | timestamp_custom('%d %b %y at %I:%M %p') }}
Any help is greatly appreciated.