Help: Creating an automation that turns a light on for an hour and off for 30 minutes repeatedly 4 times

How are you testing it? The automation is triggered only when the binary_sensor’s state changes from one state to another (or when Home Assistant is restarted).

You can temporarily set the binary_sensor’s state via Developer Tools > States. Click binary_sensor.plant_light_test in the list and it will appear in a new section displayed at the top of the list. Change the value in the State field and then click the Set State button.

Here’s an example of what I mean using one of my binary_sensors called binary_sensor.holiday. I can temporarily change its state by replacing on with off and then clicking Set State.

1 Like

I was testing it by looking the state of the sensor using the template editor at Developer Tools > Template with the below template:

{{ states('binary_sensor.plant_light_one_timer') }}

And then adjusting the last sr + timedelta condition to reflect the current time

sr + timedelta(hours=10.5) <= now() < sr + timedelta(hours=11.5)

I saw the binary_sensor state as on in template editor’s result, but the socket didn’t turn on. I saw that it ran in the debug trace too.

But like you said when testing it by changing the binary_sensor states at Developer Tools > States the light turn on an off according to the on and off state of the binary_sensor.

I will leave this automation on again for tomorrow and report back. Hopefully everything should be fine and running now.

Edit

Ran the automation for a day and everything works as intended.