[SOLVED] Rule should fire at the date of a DateTime item

Tags: #<Tag:0x00007f617fabc628> #<Tag:0x00007f617dd67668>

I have a DateTime-Item, which gets populated externally:

.items

DateTime Event_StartTime

now I want to perfom an action at the exact time given in that item. and only once… :wink:
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?

Use a timer

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?

No, create a Timer with the time from the item (you may have to convert it) the timer lambda will execute at that time

oh. I didn’t get that all that years!?
If I use

createTimer(Event_Starttime.state, [ |
		// my Commands here
    ])

the timer is created and executed not within the rule anymore, but in the system? That’s cool.

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.

2 Likes