TLDR: Is there a known two-second delay when an RM5.1 rule calls "Run Actions" on another RM5.1 rule? Is there a known delay upon returning from such a call? And is there a reason why it could take an RM5.1 rule several seconds to perform a handful of numerical comparisons in IF-THEN rules? (Note: none of these rules contain any wait or delay actions). FWIW this is on a C-8 Pro version 2.4.0.145.
Okay, here's the long version... Note that if you can answer the questions above, no need to read through all of the below! If I can understand WHY the delays are happening, I can figure out workarounds...
So I wrote a bunch of rules to cycle through lighting "scenes" (which for now I've implemented as Rule Machine 5.1 rules, because I need to set state at the end and "real" Scenes don't allow that) at the touch of a button, and I was all proud of myself until I realized that it could take up to 8 seconds between the button press and the lights changing!
I've instrumented my rules with logging, so I can tell where the delays occur, but I'd like to understand why they occur before I decide on a new approach to implementing my design.
-
The first type of delay is when an RM rule calls "Run Actions" on another rule: between the caller making the call and the callee starting up, there's a delay of just over two seconds, which I interpret as likely exactly two seconds plus the time it takes to write my log line. Is this a known issue? (Note that when a button controller rule calls "Run Actions", as opposed to when another RM rule does it, I don't see a delay.)
-
The second type of delay is on returning from a "Run Actions" call, again between two RM rules. This one's less constant: my return from level 3 to level 2 "subroutine" is almost instantaneous, but from the level 2 rule logging its end to the level 1 rule logging the return from the "subroutine" call takes just over 4 seconds.
-
The third type of delay is within one of the rules, where a series of IF-THEN, ELSE-IF statements matches a numerical state to the correct rule call to set the scene I want next. It seems to me that numerical comparisons ought to take no time at all, but the rule takes longer the further it has to go through the series of conditionals - up to 3 seconds to fall through to ELSE after going through three tests. I was originally testing against a hub variable, then when I read that the oldstyle "global" variables could be slow, I changed the code to read the hub variable into a local variable once at the top, then test against this local variable - no change. Why would it take several seconds to perform a bunch of integer comparisons?
The structure of my set of rules is (indented by call level):
- (BC) Test button
- (RM) SCENE-TOGGLE: UP kitchen lights
- (RM) SCENE-TOGGLE: DOWN kitchen lights
- (RM) SCENE-SET: kitchen lights per Kitchen_scene_requested
- (RM) SCENE: kitchen lights 0: off
- (RM) SCENE: kitchen lights 1: full on
- (RM) SCENE: kitchen lights 2: mood lighting
- (RM) SCENE: kitchen lights 3: mood + dishwasher bright
- (RM) SCENE-SET: kitchen lights per Kitchen_scene_requested
The test button triggers a button controller which calls one of "SCENE-TOGGLE UP" or "SCENE-TOGGLE DOWN" depending on which button was pressed. The button press is received quickly, and the appropriate SCENE-TOGGLE rule starts up quickly. That SCENE-TOGGLE rule reads the current state from a hub variable, calculates the desired next state, stores that in a hub variable, and calls SCENE-SET. I see a two second delay between the parent (SCENE-TOGGLE) logging that it's about to call the child, and the child (SCENE-SET) logging its start.
SCENE-SET copies the desired next scene number from the hub variable to a local variable, and using a series of IF-THEN, ELSE-IF, ELSE tests on that local variable, it decides which "SCENE" rule to call, and calls it. Oddly, the numerical tests are taking a non-trivial amount of time to perform. And again I see a two-second start-up delay on the "Run Actions" call to the child.
I've left the following log extract in reverse chronological order just as it appears in the live log, but I've split the times to make it easier to see the seconds go by, and I've inserted asterisks where there are large delays:
app:156 2025-01-14 20:07: 08.198 info DEBUG: END RULE: SCENE-TOGGLE: UP kitchen lights
app:156 2025-01-14 20:07: * 08.194 info DEBUG: RETURN FROM RULE: SCENE-SET: kitchen lights per Kitchen_scene_requested
dev:62 2025-01-14 20:07: 04.218 info Kitchen undercabinet lights (right of sink) was turned off [digital]
dev:61 2025-01-14 20:07: 04.166 info Kitchen undercabinet lights (left of stove) was turned off [digital]
app:157 2025-01-14 20:07: 04.146 info DEBUG: END RULE: SCENE-SET: kitchen lights per Kitchen_scene_requested
app:157 2025-01-14 20:07: 04.141 info DEBUG: RETURN FROM RULE: SCENE: kitchen lights 0: off
app:153 2025-01-14 20:07: 04.125 info DEBUG: END RULE: SCENE: kitchen lights 0: off
dev:50 2025-01-14 20:07: 04.115 info Kitchen undercabinet lights (left of sink) was turned off [digital]
app:153 2025-01-14 20:07: 04.065 info Setting scene: kitchen lights off
app:153 2025-01-14 20:07: * 04.062 info DEBUG: START RULE: SCENE: kitchen lights 0: off
app:157 2025-01-14 20:07: * 02.036 info DEBUG: CALLING RULE: SCENE: kitchen lights 0: off
app:157 2025-01-14 20:06: 58.997 info Selecting scene: kitchen scene #0
app:157 2025-01-14 20:06: 58.992 info DEBUG: END READING GLOBAL: Kitchen_scene_requested
app:157 2025-01-14 20:06: 58.980 info DEBUG: START READING GLOBAL: Kitchen_scene_requested
app:157 2025-01-14 20:06: * 58.976 info DEBUG: START RULE: SCENE-SET: kitchen lights per Kitchen_scene_requested
app:156 2025-01-14 20:06: 56.915 info DEBUG: CALLING RULE: SCENE-SET: kitchen lights per Kitchen_scene_requested
app:156 2025-01-14 20:06: 56.901 info Toggling kitchen lighting scene: 3 -> 0
app:156 2025-01-14 20:06: 56.859 info DEBUG: START RULE: SCENE-TOGGLE: UP kitchen lights
dev:60 2025-01-14 20:06: 56.768 info Test button button 1 (•) was pushed [physical]
Here is a sample of each type of rule:
Any insights?
Anne.