please let me get back on this automation @petro
Ive given up using the now() variant when needing the last_triggered attribute. It simply would only work if triggered once before… the as_timestamp variant works solidly.
Still have a second issue though.
Ive setup the automation to trigger every 5 minutes:
trigger:
- platform: time
minutes: '/5'
seconds: 00
I would expect the following template to max on 5 minutes, ie 300, because of that:
{{ as_timestamp(now()) -
as_timestamp(state_attr('automation.low_light__hallway_motion_sensors','last_triggered')) }}
but it only records the timestamp of the automation being actually executed:
is that to be expected? Or does it mean my trigger isn’t working.
could be the trigger is somewhat magical, because I tested another variant with this trigger:
trigger:
- platform: time
minutes: '/1'
and it triggered each second…
must add this system is on 84.3 so the new time_pattern isn’t yet needed.
Update
thought id try something that has always lingered in my mind after @NotoriousBDG shared his thoughts on another automation technique: put all conditions in the action part. This was mainly to be able to test the conditions.
I can confirm this also actually updates the last_triggered attributes correctly now. Apparently the last_triggered is in fact last_run, or last_came_into_action…
anyways, extra note to my self: when in need for an automation last_triggered template in an automation, have the conditions set in the action part, so one can truly work with the last_triggered attribute, not depending on the actual full actionability of the automation conditions…
it also enables the possibility using now(), with which I started this thread. So it all boils down to HA/the automation not setting the attribute last_triggered before it arrives at the action part. Which is a real architectural issue imho.