I have a DateTime-Item, which gets populated externally:
now I want to perfom an action at the exact time given in that item. and only once…
Is there a simple way in a rule for this? Or is it only possible with a cron based rule and the help of a proxy-item, which sets “event fired” on TRUE, if the event was already fired?
you mean, if I catch the update on the DateTime-item, I should setup a timer counting down for the event? How much memory does a timer use? I know, it uses much less than Thread::sleep… But is it OK to let it run for a few hours?
Close. You will need to convert the DateTimeType to a Joda DateTime to pass it to createTimer.
myTimer = createTimer(new DateTime(Event_Starttime.state.toString), [ |
// my commands here
You will probably want to save that Timer to a global variable so you can cancel it, reschedule it, and otherwise manage it. You will probably also want to make sure that Event_Starttime gets persisted with restoreOnStartup and have a System started Rule run to recreate the Timer when OH restarts.
No, you misunderstand the timer element.
createTimer() allows you to define a block of code to be executed at to some future date and time.
So you set the timer up once when your target datetime changes, like setting an alarm clock.
Note, the Alarm Clock Rule rule template which can be installed from the Marketplace (available in recent versions of OH snapshots) implements just this. You give it a DateTime Item and a rule to run and everything else is handled for you.