Hello guys, I need a piece of advice about filtering in templates. I have defined multiple input datetime sensors in the list object. I can’t handle the maximum value of the timestamp attribute.
{% set sensors = [
states.input_datetime.bathroom_sensor_motion_last_motion,
states.input_datetime.hall_sensor_motion_last_motion,
states.input_datetime.kids_room_sensor_motion_last_motion,
states.input_datetime.kitchen_sensor_motion_last_motion,
states.input_datetime.main_room_sensor_motion_last_motion]
|reject('none')|list %}
This doesn’t work probably because it is a list object:
{{ sensors | map(attribute='timestamp') | max }}
Result:
UndefinedError: 'homeassistant.helpers.template.TemplateState object' has no attribute 'timestamp'
I can get the attribute timestamp for an individual sensor in the loop:
{%- for sensor in sensors %}
{{ sensor }}
---> {{ sensor.name }}, {{ sensor.attributes.timestamp }} <---
{% endfor %}
Result of the first step:
<template TemplateState(<state input_datetime.bathroom_sensor_motion_last_motion=2020-12-07 01:48:19; editable=False, has_date=True, has_time=True, year=2020, month=12, day=7, hour=1, minute=48, second=19, timestamp=1607302099.0, friendly_name=Last Motion Bathroom, icon=mdi:motion-sensor @ 2020-12-07T01:55:49.212502+01:00>)>
---> Last Motion Bathroom, 1607302099.0 <---
I feel like a fool but how do I get the maximum value of the timestamp attribute using a filter?