Timer/delay in rules in OH3

Hi guys
As always, I have tried to search first, but I’m getting just old style (OH2) samples, so I would really appreciate a bit of help.
I have have upgraded from OH2.5 to 3 and pretty much lost all my home automation I did in 2.5. It’s no big deal, as I think I figured out main issues is with time and date, so once I figure out how to convert these things to OH3 compatible style, it’s just a matter of find and replace. But I would need some help with figuring out how to convert those timers to OH3 style :slight_smile:
Whole bunch of my rules for controlling blinds include timers for delays, which currently looks like:

var int WaitDuration1 = (10)
var DateTime endTest1 = now.plusSeconds(WaitDuration1)
createTimer(endTest1)
[| 
    logDebug("f1-kitchen-sunrise","Kitchen blind set to 10")
]

With this it would have 10sec delay after previous command to execute next command (for sample command is just LogDebug). It worked perfectly in OH2.5, but after upgrading to OH3 this doesn’t work anymore.
Anyone who would have similar timer done the way it would work in OH3? I went through time/date explanations but honestly didn’t really get idea how to change this to work with Java time instead of old Jodatime.
Thanks for help!

Don’t do that
var endTest1 = now.plusSeconds(WaitDuration1)
It’s usually best to let the rules interpreter sort out types.
System variable ‘now’ is a different type in OH3, but has most of the same behaviours.

To answer my own question, as I was a bit too fast with asking… I needed to change variable EndTest1 from DateTime to ZonedDateTime and include import for java.time.ZonedDateTime at start of the rule, and timer works just like it did before in OH2.5.
In case someone needs it (or if someone will correct it to make it more proper one, as I’m anything but programming expert :slight_smile: ), here’s rule that works in OH3:

import java.time.ZonedDateTime
rule "Test timer"
when
   	Item testSwitch1 received update
then
	var int WaitDuration1 = (10)
	val ZonedDateTime endTest1 = now.plusSeconds(WaitDuration1)
	createTimer(endTest1)
	[|
		logDebug("f1-kitchen-sunrise","Kitchen blind set to 10")
	]
end

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.