Help with LUX rule for Light Command

Hi,

I have set up the following rules:

rule "Turn Sidelight On_LUX"

when
Item Outdoor_Lux changed
then
if (Outdoor_Lux.state < 200){
LivingSideLightRM.sendCommand(ON)
FamilySideLight.sendCommand(ON)
}
end

rule “Turn Sidelight Off_LUX”
when
Item Outdoor_Lux changed
then
if (Outdoor_Lux.state > 350){
LivingSideLightRM.sendCommand(OFF)
FamilySideLight.sendCommand(OFF)
}
end

But it is flooding the events log with commands to turn the lights off when they are already off and also when already on its trying to send on commands.

is there any way to tame it down with the switch requests by saying if its already on do not send another request?

Thanks

Sorted…

Creating a group for the Lights and Adding the Light switch state removes the switch requests.

rule "Turn Sidelight On_LUX"
when   
	Item Outdoor_Lux changed
then
 	if (GroundLights.state == OFF && Outdoor_Lux.state < 346 ){
	GroundLights.sendCommand(ON)
	}
end

rule "Turn Sidelight Off_LUX"
when   
	Item Outdoor_Lux changed
then
 	if (GroundLights.state == ON && Outdoor_Lux.state > 360){
	GroundLights.sendCommand(OFF)
	}
end

I now have the problem that after the lux value is below 346, if i turn the lights off the lights with come on again at the next LUX value update.

As ive got a cron timer to turn all lights off at 2330 Is there a way to tell the ‘ON’ Rule to only operate between the hours of 0700 and 2330? Example bellow (TIME CRON line 5), but doesnt like it :frowning:

Will if(now.getHourOfDay() >= 7 && now.getHourOfDay() < 9){ suffice??

rule “Turn Sidelight On_LUX”
when
Item Outdoor_Lux changed
then
if (GroundLights.state == OFF && Outdoor_Lux.state < 80 && Time cron < “0 30 23 ? * *”){
GroundLights.sendCommand(ON)
sendBroadcastNotification(“Side Lights ON”)
}
end

rule “Turn Sidelight Off_LUX”
when
Item Outdoor_Lux changed
then
if (GroundLights.state == ON && Outdoor_Lux.state > 110){
GroundLights.sendCommand(OFF)
sendBroadcastNotification(“Side Lights OFF”)
}
end

You can work with times in several ways, here is one option:

val not_before_time = now.withTimeAtStartOfDay.plusHours(7).millis 
val not_after_time = now.withTimeAtStartOfDay.plusHours(23).plusMinutes(30).millis 

then you can use this in your if statement:

if (GroundLights.state == OFF && Outdoor_Lux.state < 80 && now.isAfter(not_before_time) && now.isBefore(not_after_time) )

Disclaimer: I am sure others know more elegant ways to do this…

1 Like