Help with rule 5.1

Hey Guys I need some help with a rule to turn some lights on, I want the rule to keep trying until the lights are on.
Below is my code which still seems to fail sometimes, so I was wondering if the code is not correct ?

IF (Bedside Lamp 2, Bedside Lamp 1(on, on) any is off(F) [FALSE]) THEN
On: Bedside Lamp 2, Bedside Lamp 1 (Command only switches that are off)
Repeat 10 times every 0:01:00 (stoppable)
Until (Bedside Lamp 2, Bedside Lamp 1(on, on) all on(T) [TRUE])
END-REP
END-IF

The repeat is in the wrong position. I think it needs to be further up. It will only repeat the actions between the 'Repeat 10 times...." and the 'End-Rep' I think.

Yep I think you are right, the loop wants to start before the On:Bedside Lamp... line

You mean like this

IF (Bedside Lamp 2, Bedside Lamp 1(on, on) any is off(F) [FALSE]) THEN
Repeat 10 times every 0:01:00 (stoppable)
On: Bedside Lamp 2, Bedside Lamp 1 (Command only switches that are off)
Until (Bedside Lamp 2, Bedside Lamp 1(on, on) all on(T) [TRUE])
END-REP
END-IF

Do I need the Until line ?

Well the Until would stop it going on repeating once the lights were already on. If you don't mind the rule trying to go on turning them on for no reason then the line can go.

On second thoughts maybe you do need it. What if 5 minutes after turning them on you wanted them off and turned them off manually. The next time round the loop they'd come back on again.

Ok the Until stays, I’ll test this routine although it would be good to repeat the command until the lights are ON not limited to 10 repeats.

It's safer to have some limit on the repeats as it prevents tying the hub up in knots. You could increase the number of repeats, or at the end of the rule test once more if the lights are not in the right state and then send a notification so someone can see what's wrong.

How about using a while loop?

IF (Bedside Lamp 2, Bedside Lamp 1 any is off) Repeat 10 time every 0:01:00
    On: Bedside Lamp 2, Bedside Lamp 1
END-REP

How would I implement that in my code ?
I like the idea just don’t know how to use it.

Just replace the six lines in the OP with the three lines of this while loop and you should be gtg. Note that the IF of the while loop is a simple condition and not an IF-THEN.

1 Like

Thank you guys it seems to be working with the 3 lines of code.

If you need to do this in the first place it points to problems with your mesh.

I agree, but I can’t seem to improve it even with repeaters installed

Download the Hubitat app