Automations once a day!

Hellis81,

Many many thanks. I will try when I get home :grin:

/Thekholm

You have to be careful using an automation’s last_triggered attribute. If the automation has never fired, it will be None, which will cause an error in the condition:

  - condition: template
    value_template: >-
      {{ now().timestamp() -
      as_timestamp(state_attr('automation.ventilate_game_room',
      'last_triggered')) > 14400  }}

which would prevent it from ever running.

Try this instead:

  - >
    {% set last = state_attr('automation.ventilate_game_room', 'last_triggered') %}
    {{ last is none or (now() - last).total_seconds() > 4 * 60 * 60 }}

In fact you could put both conditions into one template:

  - >
    {% set nw = now() %}
    {% set last = state_attr('automation.ventilate_game_room', 'last_triggered') %}
    {{ 17 <= nw.hour < 21 and
       (last is none or (nw - last).total_seconds() > 4 * 60 * 60) }}
8 Likes

Could you elaborate on that? Is it possible to set this up via UI or is yaml the only way?

Just wanted to say thank you- this helped me prevent an automation that notifies me when our pool reaches a certain temperature- the notification was occurring multiple times a day since the temperature would reach the desired temp, go below, and then return to the desired temp.

This is the template I ended up using to only send it every 12 hours, which results to once per day ultimately:

    {% set last = state_attr('automation.pushover_pool_temperature_90_degrees', 'last_triggered') %}
    {{ last is none or (now() - last).total_seconds() > 12 * 60 * 60 }}

Screenshot of this for @EdwardEnglish

Am surprised such a simple function in smart things not available in home assistant without over complex ymal set up.

1 Like