Rule for Hue Light

I have a very simple rule that works if I attach it to my z-wave kitchen light, but doesn’t work if I attach it to my Hue light.
KitchenStatus is a z-wave switch
Nightstand is a Hue bloom

Items File:

	Color Nightstand "Nightstand" <hue> (Master_Bedroom, Lights) {hue="3"}
        Switch   KitchenStatus "Kitchen Light" (Kitchen, Lights) {mios="unit:house,device:109/service/SwitchPower1/Status"}

Rule that works - pauses the TV when the kitchen light turns on:

rule "Pause Harmony"
when 
	Item KitchenStatus changed to ON
then
	HarmonyHubPause.sendCommand("Pause")
end

Rule that I’m trying to make work:

I am guessing that an item type of ‘Color’ doesn’t have states of ON/OFF, but I can figure out what to put. I’ve tried “changed from OFF to ON”, "changed to “ON”, “received update ON” and none of them seem to work. I even tried to move it to a Hue white dimmer light, but had the same trouble.

rule "Pause Harmony"
when 
	Item Nightstand changed to ON

then

	HarmonyHubPause.sendCommand("Pause")

end

I should note that if I change the rule to “Item Nightstand received update”, it will work. However, “Item Nightstand received update ON” and “Item Nightstand received update to ON”, do not work.

Thanks in advance!

The state of a colour item is in the format “hue. Saturation.brightness” and as you said won’t be comparable to on or off.

You can make an item of switch type and bind it to the same thing. Or you can split the color state up ‘state.split(",").get(2)’, convert it to an integer and make an if statement to test if it’s >0

OK. Can you please clarify?

I tried the code below and it still doesn’t work.

rule "Pause Master Harmony"
when 
	Item Nightstand received update
then
 

  if(Nightstand.brightness > 50) HarmonyMasterPause.sendCommand("Pause")
  else if (Nightstand.brightness < 50) HarmonyMasterPlay.sendCommand("Play")
	
end

The state of a color item is a string: For example “40,100,50” each number representing hue, saturation and brightness respectively.

If your bulb is switched off via the hue bridge, then your your brightness is zero, i.e. “40,100,0”, therefore the state of that color item will never be litterally OFF. The easiest way to remedy this problem is by adding an item that deals with the ON/OFF states, i.e.

Item:

Switch Nightstand_Toggle "Nightstand Switch" <hue> {hue="3"}

Rule:

rule "Pause Harmony"
when 
	Item Nightstand_Toggle changed to ON
then
	HarmonyHubPause.sendCommand("Pause")
end

Otherwise you can use the state of Nightstand to get it’s brightness property i.e:

rule "Pause Master Harmony"
when 
	Item Nightstand received update
then
	var HSBType currentState = Nightstand.state
	var PercentType bright = currentState.getBrightness()

	if(bright > 50) HarmonyMasterPause.sendCommand("Pause")
	else HarmonyMasterPlay.sendCommand("Play")
end

At least I think that last example will work, I can’t try it on this end.

I get the error below when I enter this rule:

Incompatible types. Expected org.openhab.core.library.types.HSBType
   but was org.openhab.core.types.State

whoops, forgot to cast it to a HSBType…

rule "Pause Master Harmony"
when 
	Item Nightstand received update
then
	var hsbValue = Nightstand.state as HSBType

	if (hsbValue.getBrightness() > 0) HarmonyMasterPause.sendCommand("Pause")
	else HarmonyMasterPlay.sendCommand("Play")
end

Thanks SO much Ben!! Works perfectly!!