Lights + Switch + Sensor + Hue Hub

Hello! Newbie here, I've likely mis-configured something and hopefully can be set on the right path :slight_smile:

What I Have:
Philips Hue Lights - connected to Hue Hub which is connected to Hubitat
Philips Hue Switch - Connected to Hubitat
Philips Hue Sensor - Connected to Hubitat
Wifi Plug (Tasmota) connected to dumb lights - Connected to Hubitat
Alexa for voice control

Setup - When motion is detected, sensor turns on lights and plugs, waits a minute, then turns back off, unless the switch is turned on, which case the sensor will not act again until the lights are turned off by the switch.

Use - I've configured this to work fine by using a Rule Machine on the switch and sensor with 2 global variables, which update depending on what is happening.

Problem - This works perfectly except when the Hue App or Alexa is used to change the state of the lights. For example, if I turn off the lights by Alexa, my global variables aren't changed so the sensor won't resume working until I hit off on my switch again.

Global variables are
Basement_Kitchen_Dimmer (0-100) used for storing brightness (Not important here)
Basement_Kitchen_Sensor - True/False used to determine if sensor should change lights.

Switch - On Button:
IF (Variable Basment_Kitchen_Dimmer() = 0(F) []) THEN
Dim: BW110-Kitchen 2, BW101-Kitchen 1, BW118-Kitchen 3, CC101-Desk, BW119-Kitchen 4: 100 --> fade: 0
END-IF
IF (Variable Basment_Kitchen_Dimmer() = 25(T) []) THEN
Dim: BW110-Kitchen 2, BW101-Kitchen 1, BW118-Kitchen 3, CC101-Desk, BW119-Kitchen 4: 75 --> fade: 0
END-IF
IF (Variable Basment_Kitchen_Dimmer() = 50(F) []) THEN
Dim: BW110-Kitchen 2, BW101-Kitchen 1, BW118-Kitchen 3, CC101-Desk, BW119-Kitchen 4: 50 --> fade: 0
END-IF
IF (Variable Basment_Kitchen_Dimmer() = 75(F) []) THEN
Dim: BW110-Kitchen 2, BW101-Kitchen 1, BW118-Kitchen 3, CC101-Desk, BW119-Kitchen 4: 25 --> fade: 0
END-IF
Set Basement_Kitchen_Sensor to false
Add 25 to Basment_Kitchen_Dimmer
IF (Variable Basment_Kitchen_Dimmer() = 100(F) []) THEN
Set Basment_Kitchen_Dimmer to 0
END-IF

Switch - Off Button:
Dim: BW110-Kitchen 2, BW101-Kitchen 1, BW118-Kitchen 3, CC101-Desk, BW119-Kitchen 4: 0 --> fade: 0
Set Basment_Kitchen_Dimmer to 0
Set Basement_Kitchen_Sensor to true

Sensor:
IF (Variable Basement_Kitchen_Sensor() = true(F) []) THEN
Dim: BW110-Kitchen 2, BW101-Kitchen 1, BW118-Kitchen 3, BW119-Kitchen 4: 100 --> fade: 0
Set Basment_Kitchen_Dimmer to 100
Wait for event: --> elapsed time: 0:01:00
IF (Variable Basement_Kitchen_Sensor() = true(F) []) THEN
Dim: BW110-Kitchen 2, BW101-Kitchen 1, BW118-Kitchen 3, BW119-Kitchen 4: 0 --> fade: 15
Set Basment_Kitchen_Dimmer to 0
END-IF
END-IF

I'm probably overly complicating things, but any thoughts on how I could solve?
Thank you and sorry if this is just a TERRIBLE set up :slight_smile:

Could you just add another rule that triggers on the Hue lights turning off and sets the Basement_Kitchen_Sensor variable to true? (It would take a few seconds or minutes for the bulbs to get their state updated from a Hue Bridge, depending on your settings, and it won't be able to tell the difference between a Hubitat change vs. a Hue change--whether the Hue app or Alexa, etc.--but I don't see how that would matter.) This assumes, of course, that you would always want the sensor to trigger the lights again, no matter how they are turned off. There may be some aspect of your situation I did not think through. :slight_smile:

1 Like

Delay would be perfectly fine there!

Being a total newb and still learning my way around in here, is there a way I could poll the lights to see if they were turned off from Alexa or the Hue app?

No, the stock Hue Bridge Integration (as well as any community integration I'm aware of) does not distinguish between "on" and "off" switch events that are known to come from Hubitat versus from the outside, nor does the Hue Bridge itself provide that information (so the only way this could really be done is with a Hubitat driver that guesses whether this "off" came from that same device/driver, which should work pretty well, but I'm guessing no one's done this since the use case isn't clear).

1 Like

Thank again for the response! I think I worded that incorrectly there. I don't actually care who updated the state (Hubitat, Hue app or Alexa) just the end result.

I guess what I mean to ask is, would you have a suggestion on how to update the variable when they have been switched off regardless of source?

You got me to take a look, so I could use something along the lines of
IF (Light that is in the group () = 0.0() [FALSE]) THEN

I think this should be able to do it, thank you for getting me to check out a new state type!!! I really appreciate your help!

That you can do! I'm not exactly sure what you're suggesting here:

...but if you're checking whether the "level" attribute is 0 to see if the light is off, that won't work. The "level" attribute will show either the current level (if the switch is on) or the last known level (if the switch is off). To check on/off state, use the "switch" attribute/capability instead--same idea, just a slightly different condition or trigger in your rule.

You should also be able to use either the Hue group (if you have that imported into Hubitat) or, as you suggest, any of the "member" bulbs. In case it matters, Hubitat's stock integration will show the group device as "on" if all member bulbs are on and off in all other cases.

1 Like

I really appreciate the follow up on it, you've been more than helpful on this newbs question!

I'll try using the switch attribute instead!

Edit
Looks like Controlling a Group in Hue updates the Groups Switch status in Hubitat, and updating a individual light in Hue will update the Switch Status in Hubitat. Controlling a Group in Hue however does not update the individual light Switch stats in Hubitat. I can work with that!

Original reply
Tried your solution, which looks awesome, however it looks like the attribute of switch doesn't appear to get updated in my Hubitat when it is controlled by the Hue App or Alexa. Might be a config issue with it, but set to 1 minute timing in the integration app and only lights that were previously directly controlled by Hubitat show a last activity greater than when I installed the integration.