I am new to Rule Machine, and I have spent a lot of time reading articles, but I am still on a steep learning curve. I have just implemented the code below and it is operating correctly. When the Garage door is open, a beeper goes off every 15-seconds and a Relay/Lamp switches ON. When the Garage door is closed the beeper stops and the Relay/Lamp switches OFF.
I feel that there is probably a more elegant way to do this, in particular not turning on the relay every repeat-cycle and stopping the repeat-cycle.
Can someone suggest a code improvement please?
Select Trigger Events (ANY will trigger) – K-Z12 Garage Door contact open
Select Actions for Garage Conditional Rule Test #2 OK
Repeat every 0:00:15 (stoppable)
IF (K-Z12 Garage Door contact open(F)) THEN
On: K-Z00 ChirpPiezo
On: K-Z07 Switch for Relay/Lamp 1
Off: K-Z07 Switch for Relay/Lamp 1
Stop Repeating Actions
If you don't want to turn the relay on with every repeat (though unless that relay has anything special, like an auto-off/momentary thing, commanding something that is already on to turn on is generally harmless), could you just move that "On" up out of the repeat? Your rule only triggers when the contact sensor is open, so I don't think you need to have that part inside a conditional that tests for it.
Regarding the stopping of your repeat, that part looks good! Rule 5.1 (and maybe 5.0; I can't remember when this was introduced) introduce some arguably more synactically elegant ways to do some things with "Repeat While," but what you have is logically equivalent and would also work--and this also gives you a chance to do something else when the contact closes, though I suppose with a "Repeat While," you'd also get effectively the same opportunity in the lines after the repeat since you won't reach them until the condition(s) is no longer met. But, again, no reason to change!
Thanks for the response. BTW I am using RM5.1. The posts I was reading were on RM5.0 and I got confused. I concur with your reasoning. Agreed there will be no damage to the switch/relay. I was more concerned with "inefficient coding" and wasting processing time on the hub.