How to create an "AND"

I've tried and failed to find any way to create a logical and in the rule machine.

What I want to do is set a virtual switch that I'll have a tile for on the dashboard. It will be 'on' when any of a series of lights is on. That part was easy. The other part is it will not be off unless ALL of the lights are off. I didn't see an 'all' or 'and' anywhere. Lots of confusing documentation that has groovy code in it, but nothing I could actually do in the rule machine.

How is this done?

You don't need Groovy; that's for writing your own apps, though that's certainly another option. Rule Machine is a built-in app (already written and installed for you). In Rule Machine, you need conditional actions. A common mistake is to look for "AND" in trigger events, but that won't work: trigger events are events, moments in time, and as such do not have truth values (e.g., a door opening). Conditions evaluate states--e.g., if a door is currently open--and can be used for this purpose, but it must be done in your actions (or as part of a predicate condition, new in Rule 5.0, that affects if/when a rule triggers, but that won't help you here, so we can ignore those).

So, what you want is something like this:

Trigger events: Switch 1, Switch 2, Switch 3 any *changes*

Actions to run:

IF (Switch 1, Switch 2, Switch 3 any on) THEN
  On: Virtual Switch
ELSE
  Off: Virtual Switch
END-IF

Since switches have only two possible states, on or off, and the logical opposite of "any on" is "all off," a simple ELSE will suffice for the second case. This would be equivalent to ELSE-IF (Switch 1, Switch 2, Switch 3 all off) if you felt like writing it that way for some reason (I wouldn't--more work for both you and the rule).

But I also might ask if you really want to manage this yourself. If not, the Groups and Scenes app sounds like it can do what you want. You can choose options in groups for how the group device represents the states of "members," so you should be able to make your "any on" vs. "all off" thing work there, too, and it's probably easier to set up: Groups and Scenes - Hubitat Documentation

9 Likes

Thank you so much for the information; I WILL play with groups.

I do want to manage it myself though. If a kid turns a light on by hand and leaves it that way, I want to know, and maybe turn it back off. There's other possibilities as well.

I need to go read up on 'predicate conditions" now.

So I just spent a couple of hours trying to get the example you put here. How the heck do people use this thing. Understand that I started this when Fortran and Cobol were the rage and prefer Python these days. I've dabbled in almost every language out there including lisp. The rule machine is incredibly hard to use.

If it were code, I would have been done yesterday or the day before.

I'm actually thinking about sending the states of the devices over mqtt to another machine where I can create a rule and handle it there sending back the desired result for the hub to forward to devices.

No wonder half the posts on here are about transferring data to another hub. I wondered about that.

Rule Machine exists so you don't have to write code to get custom automations, but if you want to write code, that's certainly another option. Documentation is a bit sparse, but the environment is substantially similar to that of the "classic" (Groovy) SmartThings environment, and those docs aren't too bad (though I recall people also poking fun at them).

If you do want to use Rule Machine, the docs are your friend. Everything must be done via the GUI, so if you just want to see that in action, you can look at Hubitat's videos like this: Rule Machine 2: Advance Conditional Rules - YouTube. Part of the issue may be remembering which actions fall under what "categories" in the drop-downs, which you'll eventually get used to, but in the meantime, the docs have you covered there, too: Rule-5.0 - Hubitat Documentation (see "List of Actions").

But if you're able to use a built-in or purpose-built custom app instead of a rule, that's often easier. I mentioned Groups and Scenes above, and it's not clear to me why you dismissed that suggestion since it seems to do exactly what you want in your example. In case I wasn't clear, the group app (and the group device it creates) will supplement your existing individual devices, not replace them, so you can use automations based on either. The group device will behave according to the options you set up in the app. I'd check it out! Not sure what else you want, and you might need RM eventually, but that should help for at least this part. :slight_smile:

(That being said, if you already have--or want--something like Node-RED set up, there is an unofficial integration for that. Some people also use webCoRE, which more or less executes on the hub except the cloud-only default IDE--but the automations it creates do, and the IDE can be hosted on your own server if you set that up. Some people prefer its interface. webCoRE more or less exists only because RM was originally written for SmartThings, then pulled--which we can now guess was because the devs got fed up with ST's problems and started their own hub. CoRE, and eventually webCoRE, was created to fill the void of custom automations without writing per se--and was eventually ported here, too.)

3 Likes

It does have a steep learning curve but once you kinda get the feel for it, it's pretty powerful. You forgot Pascal in your list of languages :slight_smile:

1 Like

RM itself is very straight forward and very easy to understand
(of course, if you have some programming skills).

But RM GUI is not very intuitive.
All this dynamic pages, tons of pull-down menus and gasilions
of mouse clicks drives me crazy.

2 Likes