Simple Rule Machine Rule - Controlling Multiple Switches

Hi There

I'm not a developer and have never done things like this before. I have a use case that I think is very simple but for the life of me I cannot get something to work.

I have a dashboard with 4 switches - the switches each control other functionality outside of this request for help.

I am trying to create a single rule that when one of the switches is turned on then the others all turn off.

I've tried a number of ways of doing this (at the moment I have it broken into 4 different rules). When I try to create the single rule I create the trigger events as each of the switches turning ON. I then create a set of IF THEN Rules that say if Button 1 Is On then Turn off Buttons 2, 3 and 4 etc.

When I press the buttons in the dashbaord.... it doesnt work. Like it isnt stopping the rule when its finished each IF and undoing itself, I've tried adding exit commands or End Ifs but they seem to have no affect.

I suspect the answer is quite straightforward - please can someone suggest something?

There is some odd structure going on here (all of your IFs are indented with an ELSE inside, whereas the use of an ELSE-IF would make this much more readable; you are also missing several END-IFs at the end, though RM is nice enough to not break if that's where it happens). However, since that should logically have the same outcome, that is not your problem.

It's hard to say what the problem might actually be without seeing your entire rule, including trigger events. I would also suggest enabling all logging and checking the output of "Logs" (filtered to just this rule) to get an idea of what is happening when. That may help you figure it out on your own, but both would be helpful for someone else looking at your rule.

I would also consider either doing this in separate rules (this would be very easy--no need for conditionals inside your actions then), though I understand the appeal of trying to do it all in one. For that, you wouldn't even need Rule Machine; Basic Rule can handle that with ease. But for RM troubleshooting, the above would be the most helpful.

The ELSE IF vs. ELSE + IF isn't actually a functional difference, it just looks weird. What you're missing here is that you're looking at whether switches are on rather than which switch turned on. So if 1 was previously on and 3 gets turned on, your desired behavior is to turn off 1; your current rule turns off 3.

What you want is something like this, using a variable eventSwitch:

  • Trigger: 1, 2, 3, or 4 turn on
  • Actions:
    • Set eventSwitch to "%device%" (this gets the name of the switch that was just turned on)
    • IF eventSwitch contains 1:
      • Off: 2, 3, 4
    • ELSE IF eventSwitch contains 2

...and so on.

I don't really like doing that in rules, because it makes the rule break if you rename the switch. The name is normally only a display element. However, I don't know a better way to do this short of writing a custom app/driver.

(I have a custom driver that does exactly this, actually, but it only works on its own child switches, so it doesn't work for your scenario exactly. Might be worth porting it to an app...?)

Actually, that was really simple to port to an app. Here.

1 Like

Thank you for everyones responses and taking an interest in this. I have been able to do quite a few things with Hubitat that I am quite proud of (Heating, Lighting, Security and Home Alerting etc). To do all this I have been following instructions and taking my time but I dont consider what I have been doing to have been very elegant and as such I have multiple rules and devices to achieve what I sometimes think could be done with a simpler solution or approach.

I've been going through the process of migrating everything to a second hub and at the same time trying to consolidate things and remove anything crude.

I was actually worried that someone would point out to me a really simple option I had missed, I feel better that this was less obvious (although probably not difficult in the grand scheme of everything that gets done in Hubitat).

I've installed the App and replied in the other section.

Thanks once again

1 Like

Download the Hubitat app