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

Ok so I'm trying to operate a window a/c connected to a Tradfri outlet and a CT100 thermostat.

Desired outcome

A/C on conditions:

  • Thermostat state goes to cooling
  • Humidity reaches 58%

A/C off conditions:

  • Humidity reaches 48% but not if thermostat state is still in cooling
  • Thermostat state goes to idle
  • A/C has been operating continuously for 1hr (just in case something goes wrong the A/C will stop eventually).

I probably could figure out how to write this out in code (I have some coding experience) but I can't figure out how to accomplish the same thing with the UI. I figure I would need a timer of some sort as a global variable that would start when the a/c on rule executes but the only time-related global variable I can find is a particular time of day. Also I can only seem to do OR rules but not nested conditions. I see people make pretty complex rules and from their screenshots it almost looks like typed code. How are they doing this?

I find creating the the RM4 entries in a text file before even trying to code RM4 works best for me.

For instance:

Select Trigger Events
When time is 11:16 PM EDT
OR
Illuminance of Multisensor_6(2051) becomes < 350
OR
When time is 1:00 AM EDT

Select Actions to Run

IF (Illuminance of Multisensor_6(2051) is < 350 r AND
Time between 4:00 PM EDT and 10:00 PM EDT(T)     THEN
     Activate scenes: Accent_LIghts

ELSE-IF (Time is 11:16 PM EDT AND
     NOT Mode is PartyMode(T)      THEN
     Dim: Accent Light (Dining Room), Accent Light (Foyer), Accent Light (Console), Accent Light (LR East
Wall), Accent Light (FP Left), Accent Light (FP Right), Fibaro RGBW Controller, Accent Light (FP WallWash): 0

ELSE-IF (Time is 1:00 AM EDT,: THEN
     Dim: Accent Light (Dining Room), Accent Light (Foyer), Accent Light (Console), Accent Light (LR East
Wall), Accent Light (FP Left), Accent Light (FP Right), Fibaro RGBW Controller, Accent Light (FP WallWash): 0
     Mode: NormalMode

END-IF
1 Like

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

That was actually very helpful. I think I got it.

Close! That first rule will need a "Basement A/C changed" trigger instead of "Basement A/C turned on"; otherwise, the ELSE section will never run (the switch turning off won't do this--no trigger matches that event; "changed" for a switch is basically the same as having an "on" and "off" trigger), so your delay won't get cancelled. There should really be a built-in app that does this...seems like something a lot of people request. Anyway.

The second one looks good! To be complete, I'd add an END-IF as your last action, though RM will infer one where you can (so basically just here where it would be your last action), but it's a good habit to get into regardless. :slight_smile:

1 Like

Ok I did those corrections. Now I just need to wait and see how it works. Seems okay so far.

I think I may also need to create a rule that polls the CT100 at regular intervals because it doesn't seem very chatty when it comes to reporting humidity.

Just don't get too carried away with the polling. I've seen a lot of instances where polling causes issues.

1 Like

Ok this ended up becoming a bit more complicated. I had created a rule to poll/refresh the thermostat every 20 mins because it doesn't seem to update much on it's own. That was causing problems with the dehumidify rule because it would trigger the conditional check for idle status and end up turning the a/c off before the dehumification target was reached.

So I ended up creating 2 global booleans. One for a cooling cycle, and the other for a dehumidify cycle. Then i created separate rules for cooling and for dehumidification. Each checks the other rule's global boolean to make sure a cooling or dehumidify cycle isn't running before performing it's own action. This should hopefully prevent the rules from interfering with each other.




This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.