Condition for last time automation triggered

I want to create a condition in my autiomation (or a template sensor to check the state of) and have it check if an automation has been fired recently and not let the autoamtion run if it was run in say the last 5 minutes.

I got the template as far as pulling the last triggered state. However, it doesn’t give the string I was expecting so I am a bit stuck.

{{ states.automation.turn_off_htpc_when_away.attributes [“last_triggered”] }}

returns

2017-01-07 14:33:34.968004+00:00

Not sure how to work with that. Was hoping for a seconds or minutes or hours readout. Im assuming ill either have to add an or statement or have another option to allow the automation to run if the result is ‘None’

It’s a UTC timestamp.
You can use the as_timestamp function to convert it.

'{{ as_timestamp(states.sun.sun.attributes.next_setting)  | timestamp_custom("%H:%M") }}'

See it in use here:

https://github.com/Danielhiversen/home-assistant_config/blob/master/automation/lighting.yaml#L297

2 Likes

Thanks @daenny and @Danielhiversen!

I assume that the condition has to be ‘true’ for the automation to tigger? If its false it will not trigger?