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. 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.
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)
How can I reschedule the timer if someone cancel the alarm or reschedule it?