(Not so) simple motion rule with scenes

Hi all,

I'm trying to do the following:

  1. When motion is detected, capture the state of XLIGHT to TEMPSCENE.
  3. After 2 minutes of no motion, activate TEMPSCENE on XLIGHT.

Simple! Well I thought it would be, until I tried it.
Thank you in advance for any advise on how I could achieve it.

As far as I know there isn't a lot of support to "capture" device settings natively in hubitat (because you are talking about scenes in particular that might be in there I don't really use the scenes part of the groups and scenes app.) So, the way I do this is with global variables, Make a global variable for each state of XLIGHT, so a global variable each for its brightness, hue, saturation, and color temperature. Then, make a trigger with that motion detector activating as a condition which has the following actions:

set the global variables to the state of XLIGHT


have a 2 minute delay and set the state of XLIGHT using the global variables which your rule set in the beginning.

I don't know what I did wrong at first, but it's working fine now.

Your question made me curious so I looked in rule machine, there is a capture and restore action so you could do away with the making of the global variables and just use that.

1 Like

I think that with testing, I was in too much of a hurry so that the HE didn't have time to sync the scene with Hue bridge... Or I just made a mistake somewhere...

The capture restore in RM is just for the switch capability. What you want to do is create an actual scene with the devices and enable the capture device within the scene.


Then, when motion is detected, you first want to turn on the switch that will be label with the scene's name plus "capture". This will capture the state of the lights to that scene. Then go ahead and enable the scene that you want.

Then, after the two minutes of inactivity you'll just activate the scene you captured earlier.

1 Like

Thank you, Ryan. This was exactly what I was looking for!

This isn't quite right. The action Capture Devices uses the switch capability to select the devices to capture, just as Scene does. But the action itself captures all possible states of the devices, including color, color temperature, level, etc. And Restore Devices restores all of them.

So, Capture Devices and Restore Devices can be used, in effect, to capture a scene on the fly, and restore it later, without having to use Scene. In fact it uses the exact same code that Scene does to accomplish this.

But there was an issue you investigated related to this function within HSM. Was that also worked into RM? Because I was seeing inconsistent behavior in RM, that's why I was using the Groups and Scenes.

That was some time ago. All of those bugs were resolved.

Okay, that's good. I knew they'd been fixed in HSM but I wasn't aware that it was working in RM too.
It's tough to know what's still a bug and what's been fixed sometime. :slight_smile: Thanks!!

The captures of the light states are working fine. Both capturing scenes and capturing devices. Unfortunately it only works well if the motion trigger is activated once. If it happens a second time, the capture is done again, which leads to the "daylight scene" overwriting the "temp scene". :frowning:

I still have to figure out how I can achieve what I want. I can't imagine that I'm the only one wanting this... Any suggestions, anybody?

Okay, now I've changed the Rule into a Triggered Rule. Capturing the first time only works now, but the rest not. When single motion, the "Daylight scene" stays on. With multiple motion, the FALSE part is used, but only for the first minute, the lights go off, regardless of motion after one minute...

Is there a way to gracefully shut down the "Actions for True" section? Or a way to just force the "Actions for False" to execute, after the "Actions for True" part? (I'm using a Hue motion sensor, it is set to 10 sec)

And with consecutive motion, just keep the (false) actions going...

I'm not a programmer and I can see my lack of programming skills. Please be patient with me...

I think you've gone astray.

Is what you want to happen that when the Keuken Sensor becomes active, that you capture the state of some lights, then set the Scene Keuken_Scene_Daglicht; then when the sensor becomes inactive restore the lights to the way they were before?

Yes! :slight_smile: Should be easy... or not? Sorry for the strange language! keuken=kitchen daglicht=daylight :slight_smile:

You should use Capture and Restore in a Rule, like this:

Condition: Keuken Sensor Active
Rule: Keuken Sensor Active (autofills)
Actions for True: Capture [select all lights to capture], Activate Scene: Keuken_Scene_Daglicht
Actions for False: Restore after a delay of 0:01:00

I've done this now. Problem is that when there is a second motion trigger (in the minute, before false is registered) , the lights are captured a second time in "daylight" scene.

That is why I recommended using the scene instead. That way, you can have the lights on event being a trigger:

Trigger event: motion Active
Condition: Some condition that is different from the scene your are activating. Either a dimmer level or CT...something that will distinguish itself form when the scene Keuken_Daglicht is active. The intention is that if the motion trigger event happens again the condition will be false causing the rule to not re-capture.
True: Turn on capture device
Activate scene

Then for lights off you have a rule:
Condition: Motion inactive
True: Activate Captured Scene with delay of 1 min with cancel on Truth change.

This way, there will be no re-capturing.

I'm going to have a look at that.
CT, is that color temperature? I was looking for a place where I could use color temperature as a condition, but I couldn't find it (I didn't look into Global Variables...)

I will be home in a few hours, then I'll test and report back.

Yes, that stands for color temp. You're right, color temp isn't available as a condition but dimmer level is.

@bravenel is there any way that color and color temp could be added as conditions to Rule Machine?