[SOLVED] Comparing Dates and times

Hi
I’m trying to make my own Wake-up light using openHab. I’m using the DateTime NextAlarm from my amazon echo and i want to compare it to the current time. When i try to do this i get: "no viable alternative at input ‘Date’. clearly I’m doing something wrong. can someone help me?

This is my Items file.

Switch WakeUpLight "WakeUpLight" <light> ["switchable"]  {mqtt=">[broker:cmnd/WakeUpLightt/POWER:command:*:default],<[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" }

And this is the rules file where i want to compare the 2 DateTime objects.

rule "Alexa Wake Up Light"
when
 Date == Echo_Kamer_Gregory_NextAlarm.minusMinutes(30)
then
    WakeUpLight.sendCommand(ON)

end

You are using this formula as a rule trigger, that is not possible. Please read Rule triggers

Oh thanks. I will try something different tomorrow.

So i changed my code and it works better now. I still 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.

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

Did you finally succeed? I’m also trying to make a wakeup sequence initiated fom alexa.