Extending or shortening the repeat timer

Help on improving my code (extending or shortening the repeat timer)

I would like to start saying I am not a developer and I am new on Hubitat. I have done my best after reading several examples on this forum

Goal: I would like to start a timer within certain time range to alternate between on and off for an power outlet on fixed timer:

On for 10 mins and off for 20 mins

And rest of the day outside the time range to be off

First, I tried to start easy, by creating a code that will alternate on and off every 15 mins. As follows

It does the job for what its intended. I don’t know if this is an optimized one for resources consumption

Next, I would like to make off for 20 mins and on for 20. I thought by extending the repeat timer it would work. But the delay command only delays execution the code rather than add time to a repeater timer.

Is there a command to add more time to counter? Or I am going at it wrong way.

Other option I thought off is just create a repeater for 30 mins then

  • Turn on
  • Delay 10 mins
  • Turn off

But I was hoping to use a more structured if commands so I can add later on more interactions with other devices such as weather, temperatures and movements and other rules

I would really appreciate any advice.

The repeat interval is fixed when you create the rule action (I just tested that you couldn't use a variable for this--I wasn't sure myself). I'd go with putting the delay in your repeat. (You could actually use a "Wait for events: elapsed time" instead so that you don't have to worry about cancelling the delay if/when your rule re-triggers, but I don't see that being a problem with what you've described.)

I think a good way to write your rule would be something like:

Trigger: specific time (time you want things to start)


IF (Time is before time you want to stop) Repeat every 30 minutes
  On: Switch
  Off: Switch --> delayed 0:10:00

Here, I used a simple conditional on the beginning of the "repeat" block so that it will test this condition before starting again, which gives you a way out when your desired time is up. Since these actions repeat every 30 minutes, the switch will essentially be on for 10 minutes (explicit in these actions) and off for 20 (implied by the preceding two facts). There are certainly other ways you could handle this, but this seems easy enough and was the first thing that came to my mind.

I came up with almost the same solution but not as fast as @bertabcd1234.

Thank you alot guys
Got it working, i over complicated it. your solutions are much easier. cheers!