How to trigger a rule only once if anything in a group changes?

I have a rule that is attempting to capture a scene changing, a particular switch being flipped, everything turning off, etc., then (most importantly) triggering only Once.

I've tried setting the trigger to watch a Group for anything to change. However, if something in the group is on, and a physical switch if flipped or another scene is activated, the group doesn't change and nothing is triggered.

I then tried to watch for changes in every single member of the group, but in the case of all turning off or a scene changing, it causes the trigger to fire multiple times.

Any suggestions on how to detect one or more changes in a group and only cause a trigger to fire once?

I greatly appreciate any insight on how to achieve it.

Thanks,
Marty

Use the private Boolean. Set to true when rule starts, and false when it ends.
Set a Required expression of private Boolean to be false.

That should prevent it from double triggering at the same time.

1 Like

Thank you for your quick response. I appreciate the help!

I must be missing something.

Here's the rule attempting to detect a change for anything in the room and only fire once:

However, the rule seems to fire 2-3 times before the private boolean can get set to false.

I'm probably just dense, but could you point out what I need to change to get the rule to fire only once?

Thanks,
Marty

The solution I came up with for a similar situation was to use an external system to throttle the activation and to use two separate rules.

TLDR:
I have the first Hubitat rule make a http request that triggers a Node Red flow. The Node Red flow receives the http requests from the Hubitat, passes them to a trigger node that only allows one message through every couple seconds, and then makes a http request back to a http enpoint on the Hubitat to trigger the second rule. No matter how many times the first rule triggers during that time period, only one callback to the endpoint will be made.

The Node Red flow looks like this:

The first node in the flow sets up the listener on "http://[node-red-ip]:1880/debounce". You can send parameters in the request like "http://[node-red-ip]:1880/debounce?a=1&b=2". In Node Red you can then refer to those parameters as msg.req.query.a, msg.req.query.b, etc. So the first Hubitat rule makes a request and passes the endpoint of the second rule as a request parameter.

To use this I first set up the action rule (the second rule) with a single trigger event of "http endpoint". I always copy that endpoint and paste it into the rule notes so I can find it later. Now that I have the endpoint URL, I can set up the first rule.

For example, if the endpoint is "http://[hubitat_ip]/apps/api/1234/trigger?access_token=xxxxxxxx-edd5-447b-b2d4-xxxxxxxxxxxx"...

The first rule with multiple triggers will have an action to send the following 'http get':

"http://[node-red-ip]:1880/debounce?callback=1234/trigger?access_token=xxxxxxxx-edd5-447b-b2d4-xxxxxxxxxxxx

This calls the Node Red listener and passes a query parameter of "callback" that contains the last part of the endpoint URL. In Node Red that is stored in the msg.req.query.callback variable.

The next node is a throttle node that will only pass one message every two seconds for any given msg.req.query.callback. That means multiple rules can call different endpoints multiple times in the same two seconds and the throttle node will pass one message for each endpoint. It can be set to pass the first or last message. I have it set to pass the last (most recent) message at the end of the 2-second delay.

The function node just sets up the outbound request by appending the 'callback' string onto the first part of the endpoint URL with the following code:

msg.url='http://[hubitat_ip]/apps/api/'
msg.url += msg.req.query.callback
return msg;

So this creates the full endpoint URL from the query that was received. The last node calls that URL, triggering the second rule on the Hubitat.

I'm using this to send notifications when my car's tire pressures are low. The trigger on the first rule is for any of the 4 tires being below a threshold. Often when it gets cold overnight, all 4 of them report low at the same instant the next time the car is moved. With this method, I get only a single notification when that happens.

IIRC I tried to use one rule calling a virtual switch which triggered another rule to accomplish the same thing completely in Hubitat, but even when I used a virtual switch, the system was seeing the virtual switch turn on more than once when the triggers went off in rapid succession.

IDRC (I do remember correctly). Here it is: Preventing double/concurrent activation - #7 by bravenel

At the end of that thread Bruce posted a link to some Groovy code that could be modified to do this entirely on the Hubitat. At the time I wasn't comfortable trying to modify Groovy and I was already using Node Red for other things, so I went the Node-Red route.

Its running twice concurrently, not a good way to stop that.
Is it a problem if it runs twice?

Also, not totally sure what you are doing exactly but it looks way more complicated than it probably needs to be. Are you sure you cannot just do this in the Room Lighting app?

You have a race condition. Since you have more than one device triggering the rule at the same time, then the rule is being trigger multiple times before the private boolean gets set to false.

This is probably much better suited for Room Lighting.

Thank you. Maybe I am missing some features of Room Lighting to achieve what I am after with multiple rules.

Plain English:
If the Lux is low, there's no lights on in the room, and motion is detected, turn on a nightlight.
Keep the light on as long as there is motion and for 3 mins after there's no.
If, while the room is dark or the night light on, if a switch is changed or scene activated, keep it on until there is no motion for X during Day, Y during Evening, Z during Night.
If the lights are turn off with a switch or group-switch-off (via Alexa) turn off all the lights.

Is the above in-scope for Room Lighting?

I took a quick look...

Couldn't quite figure out how to do this in RL, but I'm far from an RL expert. Pretty much everything else seemed possible.

You can't vary the motion sensor timeout based on time directly in Room Lighting, but you can use the activator device that it creates in a rule to set your varying timeouts with motion.

Or you can use a virtual motion sensor, then setup the same type of rule to mimic your real motion sensor. Then use the virtual in RL.

1 Like

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