Semi complicated if this then that rule

Hi,

I've got a problem where by the HE can not capture the on off and colour state of a Phillips hue bulb. It was the main reason for buying HE and feel this is my last attempt before i send it back

dicussed here for info Lights go red on contact change

I'm now thinking some sort if then and that rule may be able to over come the problems however the rule ive got currently always turns the light off whether its on or off before the rule kicks in. I know there is probably a better way to lay the rule out as I've just thrown it together. Any help is appreciated. Thanks

Rule I currently have in place

IF (Bi Fold Door open(F) AND
Office lamp(on) is on(T) [FALSE]) THEN
Capture: Office lamp
Delay 0:00:01
Set color: Office lamp ->Red ->Level: 50
ELSE
IF (Bi Fold Door closed(T) [TRUE]) THEN
Delay 0:00:02
Restore: Office lamp
END-IF
END-IF
IF (Bi Fold Door open(F) AND
Office lamp(on) is off(F) [FALSE]) THEN
On: Office lamp
Capture: Office lamp
Delay 0:00:00.3
Set color: Office lamp ->Red ->Level: 50
ELSE
IF (Bi Fold Door closed(T) [TRUE]) THEN
Restore: Office lamp
Delay 0:00:00.4
Off: Office lamp
END-IF
END-IF

What's the trigger?

I assume you are using RM 4 & these are the Actions in your Rule. What is trigger?

Also, you can use a series of ELSE-IFs and only 1 ENDIF to decrease the number is lines in your rule.

The trigger is bi fold door contact changed. RM4 is being used. How do i layout a series of this what would be the overall format? Its all new to me at this stage!

might be easyer to do

If open then
  if lamp on then
    actions..
  else (ie lamp off) then
    actions
end if
if closed ....

@mark.cockcroft perfect that was what i was looking for. Will give it a go and let you know thanks

nope still struggling! Its to do with the how the lamp is treated once the contact sensor is closed. I need the lamp to either stay on if the lamp was on. However if the lamp was off at the time the rule runs i need the lamp to turn off. Whereas the rule i've made up turns it off no matter if it was on or off. Nearly there though....I think

can you put up a screen shot of the rule

also can you see the captuerd state, is saving properly?

Also, can turn on logging in Rule for Events, Triggers, and Actions and post that too? I think between seeing both, it would help everyone else try to follow HE's logic in your rule.

I'm not at home now so I can't check, but I think if you insert poll before capture then the device will restore correctly. I think He talks to the Hue hub every minute or so.

1 Like

I mentioned in the other thread that I think the reason the "restore" is failing isn't because it isn't capturing all the correct settings but rather because Hue doesn't accept color/level commands when off, so if it was white and off when captured, it can't restore the state to white and off in one step and will probably just do the "off" part.

I proposed a workaround in my latest post in that thread.

As I mentioned in the other thread, the capture isn't likely to be the problem but rather the restore if the original state was off. The Hue Bridge will not accept color or level commands for "prestaging" when a bulb is off, or nor will it obey color and level commands sent in conjunction with a command to turn a bulb off. This isn't really a Hubitat thing, but you can work around it by capturing and restoring an "on" bulb, then manually adjusting the "on" state yourself if needed. Take a look at the rule I just posted in the other thread. It's not the only way you could do this, but it looks a lot simpler than the above. :slight_smile:

@bertabcd1234 Thanks i'm at work at the mo but when i get i'll test the code. Looks like what you've posted is exactly what i need :slight_smile:

after watching the device page it seems like the restore function is just not working at all and the command is getting lost no matter what i do when the bulb is in the off state.

Care to enlighten us on what you see before and after that leads you to this conclusion? :slight_smile: Your capture/restore should always capture the "on" state if your rule is as written above--you're turning it on before the capture and taking care of that yourself.

Something else you might consider: look at what RM actually captures by clicking the cogs/app info icon (in the upper right in your rule or to the left of the rule in list view) and see what it says for "capturedDevs" under "Application State." It should capture what your device page says, but this would be one way to see for sure.

Had a look under this and it does seem to be capturing the what ever colour the bulb is on before the rule takes place

capturedDevs {4={satValue=91, colorTempValue=6536, CM=RGB, switchState=off, dimmerValue=91, hueValue=86}}

this was the pink colour i set before running the rule. This is so frustrating, took all of about 10 mins to do in smarthings with webcore. We'll stick to using this forum post :slight_smile:

That's definitely pink, but it's also off. Did "Current States" report "switch: off" at the time of capture? If done in your rule, you should be turning the bulb on before capture and so it should be on, but I guess it wouldn't hurt to insert a small delay--or a large one when for the purposes of testing so you have time to check the state before the rule captures and then changes it to red--just to be sure it doesn't say this.