Hi Everyone,
I’m once again after assistance with my poor coding skills. Below is a rule I have in place, it’s in a logical order but I fear not the cleverest way of achieving my goal.
The aim of the rule is two fold. Firstly switch on my Kitchen light when the motion sensor is activated, the ON state. The second and more interesting part is to announce the latest weather information and train status via my Sonos speaker. The announcement only needs to be done the first time I enter the Kitchen and as I don’t work weekends there is no need for any train status then.
As you can see I’ve used a number of IF, ELSE statements. This works fine but isn’t likely to be the best method.
Any help and advice would be really appreciated.
rule "Kitchen Motion Sensor Activation"
when
Item Kitchen_SP3102_Motion changed from OFF to ON
then
postUpdate(Kitchen_Motion_Sensor_Last_Activation, new DateTimeType())
if(Time_Of_Day.state == "MORNING" || Time_Of_Day.state == "DAY") {
if(Outside_ST815_Lux_Level.state < 100) {
Kitchen_Strip_Light_Dimmer.sendCommand(35)
}
} else if(Time_Of_Day.state == "EVENING" && Hallway_SP3102_Motion.state == ON) {
Kitchen_Strip_Light_Dimmer.sendCommand(65)
} else if(Time_Of_Day.state == "NIGHT" && Hallway_SP3102_Motion.state == ON) {
Kitchen_Strip_Light_Dimmer.sendCommand(35)
} else if(Time_Of_Day.state == "BED" && Hallway_SP3102_Motion.state == ON) {
Kitchen_Strip_Light_Dimmer.sendCommand(25)
}
var String Morning_Brief = null
if(Is_It_The_Weekend.state == "NO" && Time_Of_Day.state == "MORNING" || Time_Of_Day.state == "DAY" && Morning_Announced.state != "Yes") {
if(Weather_Current_Min_Temp.state > 0) {
Morning_Brief = "Good Morning, The Morning Train is Currently;" + Morning_Train_Status.state + ". Today the expected high is;" + Weather_Current_Max_Temp.state + "degrees C." + ". The forecast for today is;" + Weather_Current_Condition.state
} else if(Weather_Current_Min_Temp.state < 0) {
Morning_Brief = "Good Morning, The Morning Train is Currently;" + Morning_Train_Status.state + ". Today is likely to be cold the expected high is;" + Weather_Current_Max_Temp.state + "degrees C." + ". With an expected low of;" + Weather_Current_Min_Temp.state + "degrees C." + ". The forecast for today is;" + Weather_Current_Condition.state
}
} else if(Is_It_The_Weekend.state == "YES" && Time_Of_Day.state == "MORNING" || Time_Of_Day.state == "DAY" && Morning_Announced.state != "Yes") {
val String Morning_Brief = "Good Morning, Today's high is expected to be;" + Weather_Current_Max_Temp.state + "degrees C." + ". The forecast is;" + Weather_Current_Condition.state
}
setMasterVolume(new PercentType(20))
say(Morning_Brief)
postUpdate(Morning_Announced, "Yes")
end