Alexa alarm to create event

With the https://www.openhab.org/addons/bindings/amazonechocontrol/ binding we can now get the datetime of the nextalarm on any of the alexa’s ! Which is superb but its hard to use it for something useful. I would like to start my heating 1h before the alarm goes off, but how can I implement this in OH?, I know when the alarm will go off but as far as I know I can not figure out a way to create an event that happens -1h before the datetime item. one solution is to have a cron rule to check current time vs alarm time every 5 min. But this will slow down the system or?

I know I can probably do things through ifttt but I would rather do it internally and not relay on them …

The cron approach that polls the alarm time compared to the current time is a common approach. It isn’t super efficient but it won’t consume enough resources to cause any real problems.

Personally, as a programmer, I’m allergic to polling. :wink: So what I would do is trigger a Rule when the DateTime Item changes, at System started, and a tad after midnight. In this Rule, I’d set a Timer to go off one hour before the DateTime to turn on the heater.

How do you set a timer to go off? In the rule:

rule "alarm Tracker" when
System started or alexa_Bedroom_nextAlarm changed then
 how to set the timer?
 timer goes off then vTimeOfday.postupdate("PREHEAT")
end

end then of course I have a seperate heating rule that tracks changes of time of day…
see Heating Boilerplate

Thanks, then it would look like this:

rule "alarm Tracker" when
System started or alexa_Bedroom_nextAlarm changed then
    var Timer myTimer = createTimer(alexa_Bedroom_nextAlarm.minusMinutes(60), [ |
        logInfo("rules", "Timer activated to " + alexa_Bedroom_nextAlarm.state)
        vTimeOfday.postupdate("PREHEAT")
])

end

How can I reschedule the timer if someone cancel the alarm or reschedule it?

manual say something like this:

reschedule(AbstractInstant instant)

but unsure how to implement it.

First make myTimer be a global variable (i.e. put the var Timer myTimer before all of your Rules in that file). Then you just call myTimer.reschedule(newTime).

One thing I do notice though is you will have to convert the DateTimeType to a Joda DateTime for use in the call to createTimer. Luckily that is easy enough.

val heatTime = new DateTime(alexa_Bedroom_nextAlarm.state.toString).minusMinutes(60)
myTimer = createTimer(heatTime, [| ...