Automation to run every two hours


I have problem and i dont get it why it doesnt work.
Thing i want to make is keep my sonoff boot every two hours and keep 10sec pause while “booting”.

Here is how i have done it.
I made two automations.
First shuts down sonoff every two hours.

Second automation should check uf sonoff has been off for 10sec, then turn it on.

At the moment it keeps booting every ten seconds.
Can someone explain me what im doing wrong?

Here is the automations…

  • action:
    • data:
      entity_id: switch.sonoff_pistorasia_3
      service: switch.turn_off
      alias: NoiseSensor Off 2 tunnin välein
      condition: []
      id: ‘1521710909379’
    • hours: ‘2’
      platform: time

  • action:
    • data:
      entity_id: switch.sonoff_pistorasia_3
      service: switch.turn_on
      alias: NoiseSensor ON
      condition: []
      id: ‘1521712602187’
    • entity_id: switch.sonoff_pistorasia_3
      seconds: 10
      from: ‘on’
      platform: state
      to: ‘off’

Formatting aside…

Here’s what those automations are doing:

Top one -

Triggers every 2 hours and unconditionally turns the switch off

Bottom one -

Triggers 10 seconds after the switch is turned off, turn it back on again.

I’m interpreting it a little different than mf_social. I think your first automation is set to trigger every second as long as the hour is 2. So between 2:00 and 3:00, your first automation would trigger every second.

I’d suggest you check the docs for automations, specifically the time trigger. I think what you are looking for is the example called ‘automation 3’, using an interval.

I think you could perhaps do with one automation, using a 10 seconds delay in the action part. Something like:

  - service: switch.switch_off
    entity_id: switch.sonoff_pistorasia_3
  - delay:
      seconds: 10
  - service: switch.switch_on
    entity_id: switch.sonoff_pistorasia_3

But I’m not entirely sure what you are trying to do so perhaps I am mistaken :slight_smile:

For triggering once every 2 hours, you can try this, it’ll run the action at 2:00:00, 4:00:00, etc.

- id: Restart Monitor
    - platform: time
      hours: "/2"
      minutes: "00"
      seconds: "00"

Time can be triggered in many ways. The most common is to specify at and trigger at a specific point in time each day. Alternatively, you can also match if the hour, minute or second of the current time has a specific value. You can prefix the value with a / to match whenever the value is divisible by that number.

1 Like

I think this will trigger it at the next whole hour and every second hour afterwards, so if now is 6:30 it will trigger at 7:00, 9:00 etc.

1 Like