Can a single rule be run concurrently?


I'm trying to debug a Trigger that runs an Action and it appears that the Action is getting run twice concurrently. Before I dig a bunch is that even possible or like WebCore are rules always run serially?


App and driver code runs asynchronously, for every event a new app instance is loaded and executed.


Hrm, is there any way to serialize an action or do some sort of Compare-And-Set on the private boolean to act like a lock? I have an Action that is run by either a condition or a trigger. The action does "if private bool is false capture lights" then "if private bool is false set lights to 100" then set the private bool to true so that re-runs of the action won't re-capture the lights. The problem is I'm seeing concurrent runs if two events happen quickly enough the lights are re-captured after they are set to 100% and when the rule times out and restores the lights they just restore to 100%





You can set the rule's PB to false as the first action and then back to true again at the end. In most cases that has saved me from getting duplicate actions for triggers that repeat.


The problem is I need to do multiple thinks conditionally on the private boolean being toggled. Ideally I could have a single "if false" check that runs multiple commands under it:

  • If private boolean false
    • set private boolean true
    • capture devices
    • change devices

If I just set the private boolean to true first then I can't conditionally capture and change as well.

Maybe I need an additional global boolean so I can use the private boolean as my mutex and the global boolean to track capture state.


No, you wouldn't. You're overthinking it.


I'm not sure what you are referring to. Are you saying I can set the private bool to true as the first step and still have conditional checks on the previous state of that bool?


Why do you need conditional checks of the bool? Just enable the restriction.


I need conditional checking so that when the action is re-run before the delay timeout it won't re-capture the device state or re-do the dim set.

Lets say my new Action looks like the following and has a restriction to only run when private bool is false:

  1. set private bool true
  2. capture device state
  3. set dim 100
  4. delay 5m then restore device state
  5. set private boolean false

If this triggers on door unlock and then triggers 3 minutes later on presence arrival the second run will capture the device at "dim 100" overwriting the captured state I want restored. What I'm going to try is:

  1. set private bool true
  2. if global is_captured is false: capture device state
  3. if global is_captured is false: set dim 100
  4. set global "is_captured" bool to true
  5. delay 5m then restore device state
  6. delay 5m then set global "is_captured" bool to false
  7. set private boolean false

That gives me both a mutex for rule execution and prevents re-capture of the device state.


Again, you are overcomplicating it. Private boolean is a restriction that is built into RM. You don't have to use a conditional check. PB was around long before conditional actions. It's right here, under restrictions:

@bravenel does an excellent job summarizing it:


So how do I ensure steps 2 and 3 are only run if there isn't currently a delayed action without the conditional check? If you are sure you understand my requirements do you have an explicit suggestion on an alternative approach?


Do you understand how PB works?


Apparently not, but terse answers won't help me understand it. Can you please explain or am I supposed to just deduce it from questions?


I linked to an explanation. Did you read it? LOL


You want your run to run what, once every 5 minutes let's say. So, at the end of your actions, you would put two actions:
Set PB false for this rule.
Set PB true for this rule after a delay of 5 minutes.

Then you would enable the PB restriction for the rule, in the picture I posted earlier from within the RESTRICTIONS area of the rule , and you're done. The rule will only run once every 5 minutes. But, this also means that the false action will not run. No action of the rule will run while the PB is false.

If you are trying to use some other type of behavior, i would use a boolean global variable instead of the PB. The private boolean is only for that rule while the GV can be read anywhere.


I did read that tutorial and it describes exactly what I'd expected.

Going back up a level the highest level goal is:

  • Lights turn on when: a door is opened, lock unlocked, someone comes home.
  • Lights revert back to previous state 5 minutes after: the last door is closed, or lock unlocked, or someone comes home.

I need the action to re-run on each triggering event to reset the 5 minute delayed restore. Simply blocking action execution for 5 minutes means the light restore runs 5 minutes after the first trigger, not the last trigger.

#17're confusing your terms. There are triggers which trigger on events. And there are rules which look at conditions. You have a rule. So there is no trigger event. There are conditions that the rules look at. Okay?

So, I still don't understand what you are trying to accomplish. Once someone is present, the rule isn't going to go false until they leave again. You don't want a rule, you want a trigger.

And I still don't understand what you are trying to accomplish. If someone has just arrived, why do you have to trigger on the door opening? And if you are triggering on the door unlocking, why do you also have to trigger on it opening? Presumably it had to be unlocked before it could be opened, right? I think you are trying to get too broad with it.

I don't know what you mean by:

Do you mean that the 5 min delay should reset?


If you look at the first post I linked the three rules. I have an Action which is run either by a Condition (used for door open state) or a Trigger (used for unlock and arrival events).

I have a broad set of actions because they are the things I want to act on. If I drive up to my house at night and my presence changes to present lights should turn on. If I unlock the door my intent is likely to go outside, so my lights should turn on, I could just wait for the door to open here but triggering on unlock makes it more likely that the lights are on by the time I open the door and get outside.


Okay...and what about the other questions I posted? I'm trying to help you here man but if you don't want it, just say so and I'll leave you alone. LMAO


After a 5 minute delay restore the captured state. See bullet #5 in comment 9