Condition state of a switch

I want to condition the behaviour of a hue light based on the fact that it is daytime or night. In a different topic I found some code to determine ‘Daylight’ based on Astro binding

Everything works fine except I am unable to condition ‘Daylight’ in my rule that conditions the light

I already tried to add one the 3 possibilities below for the rule “TURN ON LIGHT 3 RED NIGHT” that I found in browsing the forum but nothing works.

// if  
//       (Daylight.state == OFF) 
//       (Daylight == OFF)
//       item Daylight == OFF

Any pointers that would help me to condition the rule based on the state of ‘Daylight’ would be appreciated. I know this is going to be something basic but I am giving up after searching the whole weekend …
Many thanks
Christophe


.items
// Astro
DateTime Sunrise_Time       "Sunrise [%1$tH:%1$tM]"  { channel="astro:sun:home:rise#start" }
DateTime Sunset_Time        "Sunset [%1$tH:%1$tM]"   { channel="astro:sun:home:set#start" }
Switch	 Sunrise_Event      ""	                                 { channel="astro:sun:home:rise#start" }
Switch	 Sunset_Event	      ""	                                 { channel="astro:sun:home:set#start" }
Switch	 Daylight	              "Daylight"

// Niko HomeControl
Switch        Gang                  "Gang"    <light> ["Lighting"]    {channel="nikohomecontrol:onOff:nhc:27:switch"}

// Hue Bulb3
Switch	Light3_Toggle		{ channel="hue:0210:0017886e4310:3:color" }
Dimmer	Light3_Dimmer		{ channel="hue:0210:0017886e4310:3:color" }
Color	Light3_Color		{ channel="hue:0210:0017886e4310:3:color" }
Dimmer	Light3_ColorTemp	{ channel="hue:0210:0017886e4310:3:color_temperature" }
String	Light3_Alert		{ channel="hue:0210:0017886e4310:3:alert" }
Switch	Light3_Effect		{ channel="hue:0210:0017886e4310:3:effect" }
.rules 

// ------------------------CONTROL DAYLIGHT

rule "Set Daylight"
when
    Item Sunrise_Event received update ON
then
    postUpdate(Daylight, ON)
end

rule "Set night"
when
    Item Sunset_Event received update ON
then
   postUpdate(Daylight, OFF)
end

rule "Start Daylight"
when
    System started
then
     if 
(now.isAfter((Sunrise_Time.state as DateTimeType).calendar.timeInMillis)&& !now.isAfter((Sunset_Time.state as DateTimeType).calendar.timeInMillis)) 

     { postUpdate(Daylight, ON) } 
else 
     { postUpdate(Daylight, OFF) }
end

// this is the rule that creates issues and where i need help as none of the 3 options for the IF work
rule "TURN ON LIGHT 3 RED NIGHT"
when 
	Item Gang changed from OFF to ON
then
    if  (Daylight == OFF) 
end
       { sendCommand(Light3_Color,HSBType::RED)}

// i tried any of the three below
// if      
//       (Daylight.state == OFF) 
//       (Daylight == OFF)
//       item Daylight == OFF

Please edit your Posting and add Code Fences … then is your Posting readable :slight_smile: and ready for good support :slight_smile:

46

Thanks Kevin for the newbie guidance!

1 Like

The below has done the trick

rule "TURN ON LIGHT 3 RED NIGHT"
when 
	Item Gang changed from ON to OFF
then
    if  (Daylight.state == OFF) 
       { sendCommand(Light3_Color,HSBType::RED)}
end