Help with Repeats in Rules

I am a little confused with Repeat Actions, I am trying to create a rule that converts Watts to Amps to display on a Dashboard. I want to calculate the amps three times in a row when the switch turns on or off (because I want to watch the variability in those first 15-20 seconds after the switch changes). Then check again every 15 mins while the switch is on. The second repeat worked fine, but when I added the first repeat, it now goes on forever. What am I misunderstanding?

Check the events on the switch events, but.if i had to guess the refresh is causing a new on /off event and the rule is re-firing. It all depends on how the driver handles the refresh events.

'Refreshes' don't seem to be creating new "on/off" switch events. Just 'Refresh' events over and over.

Does it work if you use Run Actions? Turn on logging and post the logs. Also, the IF around the While seems redundant.

Thanks in advance for the advice and help. And 'thank you' on the redundancy. That makes sense. New version:
image

And here is a link to a word doc where I have copied logs from A) 'Run Actions' in Rule Machine with switch off. B) turning on switch, C) turning off switch, and loop starts...

Looks like @kahn-hubitat is right, the refresh is triggering another 'off'. The device driver Is "GE 40 Amp Smart Switch". Not sure how to solve that. Is there a better way for me to accomplish this? Thanks for your help.

Use the Private Boolean in the Required Expression.

Required Expression:
Private Boolean is true

Actions to Run:
Set Private Boolean False
Repeat 3 times...
    .....
END-REP
While(...
    .....
END-REP
Set Private Boolean True

Not sure I understand, but I will try that (and then try and learn about why it works :)). Thanks.

On a related note: I noticed the log returns Amps, but I don't see Amps as an attribute. Is that because the drive doesn't surface them? (which is why I am calculating them).

So, maybe I did this wrong (admittedly I don't know what Private Boolean's are:

but now the actions don't seem to run at all. log just shows switch changes but no other actions from rule.
image

When you define a Required Expression, that condition must be true for the trigger to fire. When the trigger fires the first time the first action sets the PB to false. When the Refresh happens and tries to re-trigger the rule the PB is now false and the rule won't trigger. Once all actions are completed the PB is set back to true and the rule is ready to fire again.

Oh I see.

Only problem is, if I manually turn the switch off before the 15 mins REP, it won't run again because the private boolean is still set to False. Am I thinking of that right?

That's correct. You can try and put the PB actions before and after the refresh, instead of at the beginning and the end, to try to prevent them from re-triggering the rule. For example

Repeat 3 times every 0:00:04 (stopable)
    Set Private Boolean False
    Refresh: Snowmelt Back Guitar 
    Set Private Boolean True
    Delay 0:00:01
    .....
END-REP

You could also make the rule two separate rules. One for turns on, one for turns off, and keep the PB at the beginning and the end. For the off rule, you wouldn't need the while loop at all.

Oh, that's true. I think I will try the PB, as you mentioned, just for learning's sake. Thanks!

1 Like

Download the Hubitat app