Automation Mode: restart


I have an automation with the mode restart.
(See Automation Modes - Home Assistant)
When the power of my photovoltaic system is above XXX watts, a switch socket should be turned on. (I have some additional conditions in the automation).
Then there is a delay of e.g. 30 minutes and the switch is turned off.

By using the automation in restart mode, I create a kind of while loop. As long as the trigger fires, the timer is restarted again. This is much easier than negating the conditions in another script.

Home Assistant restarts this script every 30 seconds. Is it possible to set the restart to e.g. 5 minutes?


Post your automation please

alias: "Test photovoltaik"
  - platform: state
      - sensor.power_pv
  - condition: or
      - condition: and
          - condition: numeric_state
            entity_id: sensor.power_pv
            above: 100
          - condition: numeric_state
            entity_id: sensor.sensor_energy_this_hour_all
            above: 2.0
      - condition: and
          - condition: numeric_state
            entity_id: sensor.power_pv
            above: 500
          - condition: numeric_state
            entity_id: sensor.sensor_energy_next_hour_all
            above: 5.0
  - service: switch.turn_on
    data: {}
      entity_id: switch.test_switch
  - delay:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    data: {}
      entity_id: switch.test_switch
mode: restart

Yes, that automation will run and restart everytime sensor.pv updates. Sounds like it updates every 30 seconds.

There are several ways to solve that. First though what are you trying to make happen?

As written with PV updating it’ll never turn the switch off.

The script should turn on a switch as long as certain conditions are met.
After a certain delay the switch should be switched off. Unless the conditions still occur. Until then the timer should be restarted again and again.

As written with PV updating it’ll never turn the switch off.
OK, i think I’ve understood the problem. sh***
Then I need another idea :thinking:

Hi PeteRage,
a few days ago I’ve thought about my script again.
I think I’ll divide it into two seperate automations. First one to start when my thresholds are exceeded. Second one stops, when the trigger is below the thresholds.

My idea:
Trigger the stop script 30 minutes after the start script was triggered (automation_triggered). But there is the same problem as before:
It is not the trigger that is the key, it must be the successful execution of the automation.

Is there any way to get this as a trigger?

Just seeing this.

Let’s separate the logic. First create a binary_sensor template that is True when those conditions are true, false otherwise.

Second, create two automations. The first one will trigger when that binary sensor changes state from “off” to “on” and turns the switch on. The second one will trigger when the binary sensor is off for 30 minutes and turns the switch off.

Look hear for example on how to the the “for:” attribute on the trigger.