OH3 using thread sleep

Hi All,
I’m trying to do looping on alarm sound and read lots of topic and mostly recommend thread sleep. I tried to see when I can put the thread sleep command but nowhere to be found. Is it in the rule? I saw most topic have if, then command but when I check the rules code it is not the same command line ( if then rules). Can I know where I can be put the thread sleep command in rules

That command needs to be executed in a script. So in the “Then” section of your rule you need to add “Execute Script”. But i’m not sure if a thread sleed would be good here. Try using timers instead

Thanks. Any idea how I use timer? For example when a sensor trigger alarm it keep ringing until I off… Do I do timer in rules? Which section?

All my rules were built in openhab 2.5 and I migrated them across to OH3 as rules files (rather than using MainUI). I define the timer at the very top of the rules file, along with any other parameters:

// Parameters
        val filename = "commands.rules"
        val intInterval = 5000
        val intShortInterval = 2000
        val intIntervalSec = 5
        val intShortIntervalSec = 3
        // Create variable for timer for each room with a delay switch
        var Timer tLounge = null

And then set up the timer when I need to in the relevant section of the rule. Like this:

postUpdate(Message, 'Setting Lounge to Tuner...')
postUpdate(Lounge, 'Tuner')
iLounge = 0
tLounge = createTimer(now.plusSeconds(intShortIntervalSec), [
	iLounge =iLounge + 1
	switch iLounge {
		case 1: {
		case 2: {
		case 3: {
		default: {
			tLounge = null
			postUpdate(Message, '-')

So the above sends 3 commands with a time delay of 3 seconds(intShortIntervalSec) between each command.

Hope that helps…

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