I’m trying to create a rule or two that controls when my living room lights are switched on and off. Using the time of day, whether or not the TV is switched on and the light level being reported or when motion is detected as I enter the living room.
So far I have the two rules below. Hopefully the rule name explains it well. I’m not a great fan of IF statements, but not being great at coding I have to live with what I have. Or as in this case, ask for some help and ideas.
I’m sure that is a far more efficient means of doing what I want, by building on the two rules below. My aim would be to achieve the same light level regardless of what triggers the event to switch the lights on or off.
Thanks for taking a look and any advice offered.
rule "Light Level Changed"
when
Item Outside_ST815_Lux_Level changed
then
if(now.getHourOfDay < 9 || Time_Of_Day.state == "MORNING") return;
if(Outside_ST815_Lux_Level.state > 110) return;
if(Outside_ST815_Lux_Level.state > 100) {
Living_Room_Floor_Lamp_Switch.sendCommand(OFF)
Living_Room_Table_Lamp_Switch.sendCommand(OFF)
Living_Room_Twig_Lights.sendCommand(OFF)
Kitchen_Bloom_Lamp_Switch.sendCommand(OFF)
} else if(Outside_ST815_Lux_Level.state > 80 && Outside_ST815_Lux_Level.state < 100 && Living_Room_TV_Switch.state == ON && Time_Of_Day.state == "DAY" || Time_Of_Day.state == "EVENING") {
Living_Room_Floor_Lamp_Dimmer.sendCommand(40)
Living_Room_Table_Lamp_Dimmer.sendCommand(50)
Kitchen_Bloom_Lamp_Dimmer.sendCommand(100)
} else if(Outside_ST815_Lux_Level.state < 80 && Time_Of_Day.state == "DAY" && Living_Room_TV_Switch.state == ON) {
Living_Room_Floor_Lamp_Dimmer.sendCommand(50)
Living_Room_Table_Lamp_Dimmer.sendCommand(75)
Living_Room_Twig_Lights.sendCommand(ON)
} else if(Outside_ST815_Lux_Level.state < 50 && Living_Room_TV_Switch.state == ON) {
Living_Room_Floor_Lamp_Dimmer.sendCommand(60)
Living_Room_Table_Lamp_Dimmer.sendCommand(100)
} else if(Outside_ST815_Lux_Level.state < 50 && Living_Room_TV_Switch.state == OFF && Time_Of_Day.state == "DAY" || Time_Of_Day.state == "EVENING") {
Living_Room_Floor_Lamp_Dimmer.sendCommand(40)
Living_Room_Table_Lamp_Dimmer.sendCommand(50)
Kitchen_Bloom_Lamp_Dimmer.sendCommand(100)
}
end
rule "Living Room Motion Sensor Activation"
when
Item Living_Room_SP3102_Motion changed from OFF to ON
then
postUpdate(Living_Room_Motion_Sensor_Last_Activation, new DateTimeType())
if(Outside_ST815_Lux_Level.state < 110 && Living_Room_TV_Switch.state == OFF && Time_Of_Day.state == "EVENING" || Time_Of_Day.state == "NIGHT") {
Living_Room_Table_Lamp_Dimmer.sendCommand(50)
}
end