I have a problem. I only want my WakeUpLight to switch when it is OFF. I tried a few things to make this work but OpenHab keeps sending a ON command to my light. I have the feeling it is that the state of the item isn’t updating correctly.
My items:
Switch WakeUpLight "WakeUpLight" <light> ["switchable"] {mqtt=">[broker:cmnd/WakeUpLight/POWER:command:ON:1], >[broker:cmnd/WakeUpLight/POWER:command:OFF:0],<[broker:stat/WakeUpLight/POWER1:state:default]", autoupdate="false"}
DateTime Echo_Kamer_Gregory_NextAlarm "NextAlarm" {channel = "amazonechocontrol:echo:cf45e806:echo1:nextAlarm"}
DateTime Date "Date [%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM]" { channel="ntp:ntp:demo:dateTime" }
My rule
import org.joda.time.*
import org.openhab.core.library.types.*
rule "Alexa Wake Up Light"
when
Time cron "0 * * ? * *"
then
if(Date.state != NULL && Echo_Kamer_Gregory_NextAlarm.state != NULL) {
var DateTime Alarm = new DateTime((Echo_Kamer_Gregory_NextAlarm.state as DateTimeType).calendar.timeInMillis)
var DateTime Current_Time = new DateTime((Date.state as DateTimeType).calendar.timeInMillis)
if(Current_Time > Alarm.minusMinutes(30) && Current_Time < Alarm && WakeUpLight.getStateAs(OnOffType) != ON){
WakeUpLight.sendCommand(ON)
}
}
end