Need help creating a complex rule in RM 4.0. UI seems limited

First, if you aren't familiar with how to "click around" in the RM UI and think a video might help, I'd look at two recent-ish videos on Hubitat's YouTube channel:

I would also recommend the Rule 4.0 docs, which can be found on the docs (look for Rule 4.0, not Rule Machine) or this forum most, which is my preferred location since the screenshots and later commentary may be helpful: [Released] Rule 4.0

Second, it may be helpful to know some RM terminology. Triggers and conditions are different. Triggers are events; they are things that happen (e.g., a motion sensor changing its "motion" attribute to "active," a switch turning on or off, etc). They cannot be "nested" or combined with Boolean logic because that doesn't make sense; they are events and do not have a truth value. (RM puts an "OR" between them as a hint that any trigger matching will make the actions run.) Conditions, however, are states, and they do have truth values. You can combine as many as you like in whatever way you want, but the place to do that is in your actions, not your triggers.

RM puts the triggers first in the UI, but you could write the actions first and then come back to the triggers if that makes it easier to figure out what they should be (again, any time a trigger matches, the actions will run). The only connection between events and conditions is that an event could cause a condition to become true or false. Therefore, it's often the case that anything beyond a simple rule will use conditionals based on devices/attributes in the triggers (and often more that aren't).

Back to what you're asking to do, most of it should be do-able in one rule that goes something like:

Triggers: Thermostat operating state changed OR Humidity changed

Actions:

IF (Thermostat operating state is cooling OR Humidity >= 58%) THEN
  On: Trådfri AC
ELSE-IF (Thermostat operating state is idle OR Humidity <= 48%) THEN
  Off: Trådfri AC
END-IF

...but you'll need something to turn it off after 1 hour. Another rule like this would do that easily:

Trigger: Trådfri AC *changed*

Actions:

IF (Trådfri AC is on) THEN
  Delay 01:00:00 (cancelable)
  Off: Trådfri AC
ELSE
  Cancel Delayed Actions
END-IF

(this might look a little more complicated than it needs to be, but the "extra" stuff resets the 1-hour timer if the AC is turned off and back on within that timeframe; also note that it may look like I ignored the "thermostat state is NOT cooling" in the ELSE-IF, but only one IF, ELSE-IF, or ELSE block will execute, and we already know it's not cooling if this one gets executed because cooling would have matched the previous block.)

Alternatively, you may have seen some people mention a "new" rule paradigm staff have suggested recently. Under this paradigm, the first rule could be done as something like:

Triggers: Thermostat operating state becomes cooling OR Humidity becomes >= 58%

Actions:

On: Trådfri AC
Wait for events: Thermostat operating state is idle OR Humidity <= 48% --> timeout 01:00:00
Off: Trådfri AC

Unlike the other one, this won't also automatically turn the outlet off after 1 hour regardless of how it got turned on, but it will turn it off 1 hour after this automation turns it on (which would be due to either the thermostat operating state becoming "cooling" or the humidity sending a value >= 58%--not just the first such value, BTW, but any matching value). You wouldn't need the second rule if that's all you want. I also didn't think this one through as much, so there might be some holes in the logic. Same for the first, really, but I think I thought that one through a bit more. :slight_smile:

Hope this helps a bit!

PS - RM displays something that looks like pseudo-code, but the only way to generate it is, indeed, to use the drop-downs and other inputs in the UI.

2 Likes