Conditionals in Rule Machine

I have to admit that though I was a programmer most of my life, I can't figure out how to do conditionals in Rule Machine. It just doesn't make sense. The pseudo code for what I want to do is:

If (CERTAIN_SWITCH == on) THEN {
TURN OFF ANOTHER_SWITCH
WAIT 2 MINUTES
TURN ON ANOTHER_SWITCH
} ELSE {
TURN ON ANOTHER_SWITCH
WAIT 2 MINUTES
TURN OFF ANOTHER_SWITCH
}
END IF

I mean, I've coded in Fortran, C, C++, JAVA, etc. etc. etc. and I just can't get the GUI to allow me to do this. I have looked for a tutorial. And man would I have love to pop open a file in vi and go to town.

Anyway, can anyone point me in the right direction? I seem to get stopped in "there's nothing I can do from this screen" mode every time.

Thanks in advance for helping this decrepit old programmer.
Jay W

1 Like

Seems like you may just have issues figuring out how to use the GUI. In that case, perhaps a video would be helpful. Here is one that's a couple years old now and for Rule 4.0, but the Rule 5.1 (current version) interface isn't that different with regards to conditional actions, so it will still be applicable:

I'd also suggest trying again with a new rule if you haven't already--just in case you got the one you're working on now into some weird state that messed up the display.

Good luck!

2 Likes

YES! That video was very helpful. What was hanging me up was the distinction between defining conditions and defining actions. Kind of odd syntax. But after watching the video, I got it. Was able to finally do this sort of complex rule.

Many thanks to you for taking the time to reply.
Jay W

2 Likes

No birds have been harmed in this rule.

1 Like

Correct. Only annoyed. :wink: "Sunshine" is retractable awning controlled through a BOND interface. Weirdly, when it's "on" it's retracted, when it's "off" it's extended. So we turn the sunshine on/off for two minutes several times a day to keep them from building a nest under the awning cover. Every spring we go though this and I finally got around to automating the bird annoyance system.

1 Like

That's a cool idea. And a great use of automation.

Hi, looking for a little help. I want to speak when the furnace is on and a door is open for gt 15 sec
Q1. Is there an option to have and AND in the triggers?
Q2.Assuming not, it appears that the furnace turning on will trigger even though the door has not been open 15 sec...
Q3.Because of that I added the condition that the door had to be opened for 15 sec but I'm concerned that it says (UNUSED)... is it really unused?
Q4. Will this rule do what I want or what do I need to change.
Thanks !!

You could simplify if you make the furnace being on a required expression.
That way changes in the door would be ignored otherwise.

I'll comment quick here about #3... Yep, that condition is unused. I realize it's confusing since it looks very similar to the trigger you are using, but they are subtly different.

Triggers are actions, whereas conditions are states.

Your trigger is the action of the contact being open for exactly 15 minutes -- it'll trigger at that 15-min mark (not before, not after).

If you were to use it in the rule, your condition would be true at and anytime past 15 min. It's just the state of the contact being open for longer than 15 min.

thanks for trying to explain....
so do I have the trigger be JUST the furnace turning on
and then the condition being door open for gt 15 sec

im guessing that each time the furnace turns off then on and the door is still open it would talk again

You can “Use Required Expression” and put in: FurnaceHeat contact closed

That will “disable” the entire rule unless it is true.

Make your trigger the door open for 15 seconds

This will only “fire” when the Required Expression is TRUE.

1 Like

ahh, in that scenario I would only get the voice once (until door is closed and opened again)

Thanks