Automations once a day!

Hi all,

How to set an automation to trigger just once a day.

I’am coming from SmartThings, there it where just a switch to get the automations to trigger just once.

Help needed, thanks!

/Thekholm

Solution 1 :

create a input boolean.

In your automation, input must be a condition state at off. At the end of the automation, set it to on.

And create another automation at midnight to set it to off.

Solution 2:

At the end of the automation, disable it.
And create another automation at midnight to enalble it.

That way your automation will trigger once a day only

2 Likes

Solution 3:
Trigger the automation to start at a specific time (i.e. to reset stuff…)

- id: 'echo_reset'
  alias: 'Echo reset'
  initial_state: 'on'
  trigger:
  - at: '21:00:00'
    platform: time
  condition: []
  action:

Yes but i suppose that the trigger is not the time here but a sensor

Thanks for the reply Djal & Dixey. So I have to create two automations for a simple task?

What I rellay need is a automation to run once between two times (my time will be 17-21).

/Thekholm

Maybe give us some more details of what you want to achieve, then we can help better.

Hi Datamonkey,

I want to make a automation with my air quality sensor Co2 & TVOC. When they get to a point, which is really high I want to use TTS to say that its time to open a window. I want to do that between 17-21 and just once a day, otherwise it could go of every now and then.

Best regards
Thekholm

It i what i do yes. anyway i already have a midnight automation to reset some stuff.

The fourth way is to look at the last time the automation was run and have a condition that it must be more than five hours ago.
That way even if it runs at 17:00 it can’t run for the rest of the day.

However, there is an issue with this option.
If the automation runs at 17:00 then you restart HA at 17:30 the last run will not be preserved and it will fire it again.

Perhaps not enough of an issue?
But that is a one automation setup.

What do you want to happen if the “point” is passed before 1700 or after 2100?

Should it still trigger the TTS at 1700 if it happens before then? Or should it not trigger at all that day?

What do you expect to happen if it doesn’t pass the “point” until after 2100? Should it wait until 1700 the next day to trigger the TTS? or should it trigger the TTS at 2100 no matter if the “point” is passed or not for the day?

depending on the answers to these questions you have a couple of avenues to go down.

I just want it to trigger between 17-21 just once. If the points is high before or after doesn’t really matters.

Is a game/TV room for my kids, they are in there most often between 17-21. Other times the air quality is often great and doesn’t need to trigger. If the points is high for other reason I get a push notification.

Thanks for all input :grin::pray:

/Thekholm

You will need two automations for this.

The first will trigger on the high point of the air quality sensor. It will have 2 conditions: the time, as well as an input boolean created for this purpose. The action will be to make the TTS announcement and then turn off the input boolean.

The second will turn the input boolean back on after the time period is over.

Together, these two automations will ensure that the announcement only happens once a day, in the time range, and only if air quality is poor. The input boolean is the key to making sure it only happens once. If you’re okay with getting multiple TTS announcements (if air quality is bad, the TTS announcement happens. Then, if air quality returns to a good range, and then goes back to the bad range and still in the time frame specified, it’ll make the announcement again) then you can just use one automation. Otherwise the second automation is needed to inform the system that it’s okay to make the announcement again.

You can do this with just one automation.

- mode: single
  max_exceeded: silent
  trigger:
    - platform: template
      value_template:
        {{ 17 <= now().hour < 21 and
           states('sensor.CO2_TVOC')|float > N }}
  action:
    - service: WHATEVER
      data: ...
    - delay:
        hours: 4

This will run at 17:00 if, at that time, the levels are high, or between 17:00 and 21:00 when the levels rise above the threshold.

Once it fires it will not fire again for four hours (which will put it outside the time range.)

As mentioned above, it’s possible the automation might fire a second time during the time period if HA restarts. But this would only happen if the levels went below the threshold after the automation fired and before HA restarted. If the levels were still high when HA restarted, it would not fire again (because a template trigger will only fire when the template evaluation changes from false to true.) But I think there is probably a relatively low probability this would happen, so I doubt it would be an issue for you.

6 Likes

Yet another way with one automation is to create a helper date time with only date.

At the end of the automation you set the date time helper to today’s date.
And as a condition in the automation you use {{ states('input_datetime.datetime') != states('sensor.date') }}
This will only trigger once a day and will survive a restart.

3 Likes

Wow, thanks to all!

I have some testing to do :grin:

/Thekholm

I prefer this approach I was told by someone else here.

Have a Template Condition that checks to see if the automation has already been run today, using the value template

{{as_timestamp(state_attr('automation.XX','last_triggered'))|timestamp_custom('%-d') != as_timestamp(now())|timestamp_custom('%-d')}}

This basically converts the last_triggered time of the automation to a day and compares that to today’s day, and only allows the automation to run if they’re different.

There are lots of other variations of this - e.g. use this trigger to check if a device hasn’t been updated within the last 30 minutes (1800 seconds):

{{ as_timestamp(states.sensor.date_time_iso.state) | round - as_timestamp(state_attr('sensor.XX','last_seen')) | round > 1800 }}

Or this condition to only allow the automation to run if not within the last 60 minutes:

{{ as_timestamp(states.sensor.date_time_iso.state) | round - as_timestamp(state_attr('automation.XX','last_triggered')) | round > 3600 }}

In my view, these are much better approaches as you don’t need additional helpers, multiple automations, etc.

13 Likes

Thanks for the input DerekO,

That I don’t understand much about, well over my head. I’am coming from SmartThings and there it were a switch and all was good (other big problems on the platform).

I will try and see if I can get some of the suggestion here to work, even yours :grin:

Best regards
Thekholm

If you decide whether a restart should preserve the “automation state” or not and give us details about the media_player name, sensor name and such then I believe people can give you a copy paste answer to your problem.
But as long as we don’t know the exact details then we can only give you general answers.

Hi Hellis81,

This is my sensors and things I want to use for this automation:

Air quality sensor - sensor.airthings_tv_wave_co2
Air quality sensor - sensor.airthings_tv_wave_voc
TTS player - media_player.tv_hub
Mobile - notify.mobile_app_huawei

I want it to say that the air quality is bad on the TTS speaker and send me a message on the phone.

I want it to happpen once a day between 17:00-21:00.

If the HA restart under that time and it annouces it once more, if the air quality is bad is not the end of the world :slight_smile:

Many thanks!

Best regards
Thekholm

This is the first suggestion I posted.
One automation looking at the previous trigger time.

alias: Ventilate game room
description: ''
mode: single
trigger:
  - platform: state
    entity_id: sensor.airthings_tv_wave_co2
    to: '100'
  - platform: state
    entity_id: sensor.airthings_tv_wave_voc
    to: '100'
condition:
  - condition: time
    after: '17:00:00'
    before: '21:00:00'
  - condition: template
    value_template: >-
      {{ now().timestamp() -
      as_timestamp(state_attr('automation.ventilate_game_room',
      'last_triggered')) > 14400  }}
action:
  - service: tts.cloud_say
    data:
      entity_id: media_player.tv_hub
      message: Open window in game room
  - service: notify.mobile_app_huawei
    data:
      message: Open window in game room
      title: Kids need air!

There are some unknown. Such as the trigger values, tts service name and the name of the automation.