I did a full restart on my HA install a few months ago, and as I’ve had time I’ve added back automations, sensors, etc that I missed.
Anyway, finally got my motion sensors set back up and I used to use this
last_motion:
friendly_name: 'Last Motion'
icon_template: 'mdi:walk'
value_template: >
{%- set sensors = [states.binary_sensor.bedroom_motion_sensor, states.binary_sensor.first_floor_motion_sensor, states.binary_sensor.master_bedroom_closet_motion_sensor, states.binary_sensor.great_room_occupancy, states.binary_sensor.outdoor_motion_sensor] %}
{% for sensor in sensors %}
{% if as_timestamp(sensor.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
{%- set short_name = "(".join(sensor.name.split("(")[1:]) %}
{{ ")".join(short_name.split(")")[:-1]) }}
{% endif %}
{% endfor %}
and now it does not work. I seem to remember that there may have been changes with timestamps or templates in the past few months, but cannot seem to find anything specific.
This template above had been working for me for quite a while. So I’m pretty confident that the concept is good.
Is the remainder of your template designed to extract a string that exists within ( ) in the entity’s friendly_name? If that’s what it does then I can offer another way to do it.
I’ll be 100% honest. I think I got help from someone here years ago, and it just worked. I understood enough to know it was looping through the sensors looking for the last_changed attribute and comparing time stamps, but not much more than that.
I feel like I pretty much just used what had worked, (changed a few sensor names) and now it does not work, but since I never 100% understood what it was doing, I could not understand why it did not work.