Lights go red on contact change

Hi Guys,

Recent smart things refugee, got the hub today and I'm playing with rule machine. I did have on smarthings via webcore a rule that if x contact sensor was changed to open it would capture the current hue lights state and colour. Then turn them red and dim to 50% when the contact closed it would restore the colour and state. I've currently got this

Capture: Kitchen lights, Office lamp
Set color: Kitchen lights, Office lamp ->Red ->Level: 50
IF (Bi Fold Door closed(F) [FALSE]) THEN
Restore: Kitchen lights, Office lamp

in rule machine, however it just turns the lights on and keeps them red. What am I missing? thanks for any help

That's only part of your rule--we'd need to see the triggers to know what's really happening. My ESP tells me you probably have a "contact open" trigger and should use "contact changed," then adjust your actions like:

IF (Contact open) THEN 
  Capture Lights
  Set Lights to Red at 50%
ELSE
  Restore Lights
END-IF 

That way, your rule actions will run when the contact is either opened or closed. The IF will match when it's opened, and the ELSE will match when it's closed (there are only two possible states). WebCoRE guesses at what event subscriptions to create based on your actions, including conditions; Rule Machine won't (there are times you may want conditionals in the rule just to test something), so you'll need to make whatever events you want to run the actions for part of your trigger.

1 Like

If your trigger is on the door opening, there is another way you could implement the same thing. Instead of using an If/Else configuration, you have the rule triggered by the door opening. Then after you set the red color, you add a Wait action where you wait for the event of the door closing. Just another way to do it. One of the blessings (and curses) or Rule Machine. :slight_smile:

thanks for the replys.......hubitat is very different to smart things and is taking some time getting used to! |I now have this with the trigger as changed like you've mentioned.

IF (Bi Fold Door open(F) [FALSE]) THEN
Capture: Kitchen lights, Office lamp
Set color: Kitchen lights, Office lamp ->Red ->Level: 50
ELSE
Restore: Kitchen lights, Office lamp

The lights go red on open however they don't restore. Any Ideas?

As mentioned....what is the trigger for the rule you are trying to write?

I've got this as the trigger

Select Trigger Events (ANY will trigger)

Bi Fold Door changed

And the contact sensor does change from Open to Close correctly? Can you enable logging for the rule and then try to open and close the door?

Seems to be

app:462020-01-24 03:21:35.212 pm infoAction: Restore: Kitchen lights, Office lamp
app:462020-01-24 03:21:35.208 pm infoAction: ELSE (do actions)
app:462020-01-24 03:21:35.206 pm infoAction: Set color: Kitchen lights, Office lamp ->Red ->Level: 50 (skipped)
app:462020-01-24 03:21:35.196 pm infoAction: Capture: Kitchen lights, Office lamp (skipped)
app:462020-01-24 03:21:35.187 pm infoAction: IF (Bi Fold Door open(F) [FALSE]) THEN (skipping)
app:462020-01-24 03:21:35.134 pm infoDoor open Triggered
app:462020-01-24 03:21:35.121 pm infoDoor open: Bi Fold Door contact closed
dev:112020-01-24 03:21:34.970 pm infoBi Fold Door: contact is closed
app:462020-01-24 03:21:30.477 pm infoAction: Restore: Kitchen lights, Office lamp (skipped)
app:462020-01-24 03:21:30.472 pm infoAction: ELSE (skipping)
app:462020-01-24 03:21:30.327 pm infoAction: Set color: Kitchen lights, Office lamp ->Red ->Level: 50
app:462020-01-24 03:21:30.247 pm infoAction: Capture: Kitchen lights, Office lamp
app:462020-01-24 03:21:30.237 pm infoAction: IF (Bi Fold Door open(T) [TRUE]) THEN
app:462020-01-24 03:21:30.186 pm infoDoor open Triggered
app:462020-01-24 03:21:30.172 pm infoDoor open: Bi Fold Door contact open
dev:112020-01-24 03:21:30.026 pm infoBi Fold Door: contact is open
app:462020-01-24 03:21:19.395 pm infoAction: Restore: Kitchen lights, Office lamp
app:462020-01-24 03:21:19.384 pm infoAction: ELSE (do actions)
app:462020-01-24 03:21:19.376 pm infoAction: Set color: Kitchen lights, Office lamp ->Red ->Level: 50 (skipped)
app:462020-01-24 03:21:19.366 pm infoAction: Capture: Kitchen lights, Office lamp (skipped)
app:462020-01-24 03:21:19.355 pm infoAction: IF (Bi Fold Door open(F) [FALSE]) THEN (skipping)
app:462020-01-24 03:21:19.297 pm infoDoor open Triggered
app:462020-01-24 03:21:19.284 pm infoDoor open: Bi Fold Door contact closed
dev:112020-01-24 03:21:19.151 pm infoBi Fold Door: contact is closed
app:462020-01-24 03:21:15.549 pm infoAction: Restore: Kitchen lights, Office lamp (skipped)
app:462020-01-24 03:21:15.545 pm infoAction: ELSE (skipping)
app:462020-01-24 03:21:15.384 pm infoAction: Set color: Kitchen lights, Office lamp ->Red ->Level: 50
app:462020-01-24 03:21:15.306 pm infoAction: Capture: Kitchen lights, Office lamp
app:462020-01-24 03:21:15.296 pm infoAction: IF (Bi Fold Door open(T) [TRUE]) THEN
app:462020-01-24 03:21:15.242 pm infoDoor open Triggered
app:462020-01-24 03:21:15.227 pm infoDoor open: Bi Fold Door contact open
dev:112020-01-24 03:21:15.181 pm infoBi Fold Door: contact is open

And it is not restoring the settings for the light? What is the setting for the light before you open the door? Did you turn the light off after modifying the rule or is it still set to Red?

I turn the light white every time i try it so it doesnt capture the red and then set it as red

Can you show the device edit page?

The logs from RM indicate to me that the rule is acting as expecting. Do your lights accurately report states back to Hubitat? You can verify by looking at the device page (for the lights, not the sensor) in real time as you open and close the sensor and the rule runs. I see two possible problems: either the lights aren't reporting good information back to Hubitat (e.g., it sees red when they're really white) and RM is capturing the wrong settings, or the restore is failing because the bulbs aren't receiving the new settings (you can verify this by whether the device page for the lights shows the expected changes and whether what's there matches the actual state of the lights--either could be a problem).

Also, what kind of bulbs are these? Some are known to behave poorly when directly connected to Hubitat in a "mixed" (bulb and non-bulb) Zigbee network. Even ones that are otherwise fine (e.g., Sengled) don't always seem to do well if receiving a bunch of commands at once, as they might when multiple bulbs get multiple commands at the same time like your Restore action might be doing (turn on, set level, set color/color temperature, etc.).

Sorry, I meant for the lights. What I am suspecting is that one of the attributes is not defined correctly and that's why it's not restoring.

The lights are on red. You said you changed them to white. I was also trying to see the device type but you cut that off from your screen shot.

Is this a hue bulb? when you say you set it back to white, are you doing so from the Hue app?

Yep its def on white now so it looks like its not being updated correctly. The lights are attached to the hue bridge and are hue lights. thanks for the help so far!

Now we're on to something. :slight_smile: By default, Hubitat's Hue Bridge Integration app only updates bulb states once per minute (the polling/refresh interval you can configure in the integration app). There is no way for the Hue Bridge to "push" changes to Hubitat immediately, so you'll have to wait for the refresh to happen until the Hubitat state is correct if you make changes outside Hubitat (e.g., via the Hue app).

If none of your automations rely on under-one-minute resolutions for changes you made outside Hubitat, you should be good. Capturing and restoring from Hubitat in under one minute should be fine as long as you either made the pre-capture change from Hubitat (so the attributes it captures are correct) or waited for the refresh interval to pass (to ensure the same for changes made via Hue directly).

I suggest this: try your rule again, but this time set the bulb to white from inside Hubitat first (or do it however you want but make sure the device page in Hubitat shows the correct attributes first). If you aren't sure how to do this from Hubitat, type "2700" into the "Set Color Temperature" box and click the button to send that command to the bulb, which will set the bulb to a default warm white similar to Hue's "Read" settings (this command takes a color temperature in Kelvin, so you could also use whatever value you wanted, e.g., 4000 for a cooler white).

OK so oddly it started working before i read your reply. It now turns red and then immediately turns back to the state it was in.

So basically, as long as nothing else uses the hue bridge and just hubitat it should work,