Assistance with simple automation to run a scene repeatedly, if I'm home, during certain hours

Hi, I’m attempting to construct my first automation and hope someone can provide some simple guidance.

I have properly configured my cell phone location so that HA is aware when I am home and not.

I would like my presence at home, during certain hours of the day, to trigger a scene with a smartplug.

The plug will run for 2 minutes, then stop. Then I would like it to wait 20 minutes, then run again. Repeat until either the specified time ends, OR I leave home.

So far, I have this:


I believe this should confirm I am home, and haven’t left for 5 minutes.

Here’s where I get lost in the weeds and the limits of my minimal programming knowledge become obvious. I think I want to run a loop, but it should check if I’m home and then exit if I’m not.

Do the initial “When” and “And if” parameters get checked continously, and if I leave, that would stop the loop?

I tried doing a Choose between 2 conditions, but that didn’t seem quite right either.

No. The trigger (“When”) is a distinct event that happens. The conditions (“And if”) are checked only once right after the trigger initiates the automation. If all the conditions pass, the action sequence starts.

If you want actions to repeat, you need to use one of the Repeat actions with its own conditions. For what you described you will probably want a While loop.

Another option is to use timers as shown in this example.

1 Like

Ahh, thank you. The WHILE command is exactly what I was looking for, and your example is very similar to my situation. This is what I’ve come up with:

I am presuming after the last entry with the 22 minute delay, it goes right back to the start of the repeat loop.

Does the switch turn itself off? If not you need to incorporate that.

Good eye. Yes, that imported scene causes the switch to turn itself off after 2 minutes.

I just realized I may have an issue involving the initial trigger. It looks like it activates when my cell phone enters the home zone. So if I’m already at home before 1015, it would never trigger?

If that’s the case, I do need a better way of activating this.

Just add a Time trigger.

So multiple WHEN conditions are considered as an OR situation?

Yes, triggers are logically OR.

1 Like