I have an illumination sensor that I use to control when lights come on and switch off. I’m using it in quite a basic way, which is where my downfall is likely to be. Not being great at coding, I’m at a lose as to how to solve an unforeseen issue with my present code.
The basics of the issue is that because I run the below rule every time the illumination sensor reports a change I get my lights switching on and off seemingly randomly. The reason being that when it starts to get dark in the evening the light level dips and switches on the lights, but also brights up again slightly and therefore switches the lights off once again.
What I think I need is a way to buffer when I switch the lights on or off. So I’m looking for suggestions or ideas how I can solve this issue.
rule "Lights"
when
Item Porch_ST815_Lux_Level changed
then
if(now.getHourOfDay < 9 || Time_Of_Day.state == "MORNING") return;
if(Porch_ST815_Lux_Level.state > 200) return;
if(Porch_ST815_Lux_Level.state > 150) {
gLiving_Room_Lights.sendCommand(OFF)
logInfo("org.openhab", "Living Room: Lights Off. TV Status is unknown. Lux Level @ " + Porch_ST815_Lux_Level.state)
} else if(Porch_ST815_Lux_Level.state > 130 && Living_Room_TV_Power.state == ON) {
Living_Room_Floor_Lamp_Dimmer.sendCommand(55)
Living_Room_Table_Lamp_Dimmer.sendCommand(55)
LivingRoom_Twig_Lights_Switch.sendCommand(ON)
logInfo("org.openhab", "Living Room: Lights On. TV Status is On. Lux Level @ " + Porch_ST815_Lux_Level.state)
} else if(Porch_ST815_Lux_Level.state > 115 && Living_Room_TV_Power.state == ON) {
Living_Room_Floor_Lamp_Dimmer.sendCommand(60)
Living_Room_Table_Lamp_Dimmer.sendCommand(60)
logInfo("org.openhab", "Living Room: Lights On. TV Status is On. Lux Level @ " + Porch_ST815_Lux_Level.state)
} else if(Porch_ST815_Lux_Level.state > 100 && Living_Room_TV_Power.state == ON) {
Living_Room_Floor_Lamp_Dimmer.sendCommand(65)
Living_Room_Table_Lamp_Dimmer.sendCommand(65)
Kitchen_Bloom_Lamp_Dimmer.sendCommand(100)
logInfo("org.openhab", "Living Room: Lights On. TV Status is On. Lux Level @ " + Porch_ST815_Lux_Level.state)
} else if(Porch_ST815_Lux_Level.state < 100 && Living_Room_TV_Power.state == ON) {
Living_Room_Floor_Lamp_Dimmer.sendCommand(70)
Living_Room_Table_Lamp_Dimmer.sendCommand(100)
logInfo("org.openhab", "Living Room: Lights On. TV Status is On. Lux Level @ " + Porch_ST815_Lux_Level.state)
} else if(Porch_ST815_Lux_Level.state < 100 && Living_Room_TV_Power.state == OFF) {
Living_Room_Floor_Lamp_Dimmer.sendCommand(65)
Living_Room_Table_Lamp_Dimmer.sendCommand(65)
Kitchen_Bloom_Lamp_Dimmer.sendCommand(100)
logInfo("org.openhab", "Living Room: Lights On but the TV is Off. Lux Level @ " + Porch_ST815_Lux_Level.state)
}
end