WTH Trigger automation only once per "evening" or per "X-hours" to prevent repeating a message

Prevent automations keep triggering every time on “its warmer inside then outside”, “open the windows” text to speech kind of automations.
There are ways to prevent this repeating, but they ain’t easy or rudementary like using a 3hour timeout timer for example.

condition: template
value_template: "{{ now() - this.attributes.last_triggered > timedelta(hours=3) }}"

That would prevent your automation to run when it already did less than 3 hours ago

4 Likes

Meh error:

In ‘template’ condition: UndefinedError: ‘this’ is undefined

You have to be on a recent version of HA and the automation has to exist. I.e. save it if you’re using the UI.

Both are the case :slightly_smiling_face:

Home Assistant 2022.10.3
Supervisor 2022.10.0
Operating System 9.2
Frontend 20221010.0 - latest

The automation excists, i was adding it to the condition while the error pops up.

Are you trying to test the condition? That doesn’t work. You have to let the automation naturally run.

Also, be aware that the condition proposed by Fes will not work on brand new automations i.e. automations that have not triggered previously. For those you need to provide a default that will allow the template to render true.

condition: template
value_template: >
  {{ now() - this.attributes.last_triggered | default(today_at(), 1) > timedelta(hours=3) }}

Related WTH

As explained above, a Template Condition can prevent an automation from executing more than once per day (or whatever time period you need). However, if you consider a Template Condition to be “ain’t easy” how do you envision a “3hour timeout timer” would make it easier? Post an example of how an automation would use your proposed idea.