Thank you very much for comming back to me on this. I have worked hard to get to this point but i think i might have made a code that can work. If any of you can have a look at it, maybe you can spot somthing i might not yet kno about programming. However, i did seem to work the first fiew minutes i tested it. Thank you again
var Timer timer = null
rule "demo rule LOOP1"
when
Item Wallplug_greenhouse_Humidity received command
then
if (receivedCommand == ON) {
// first ON command, so create a timer to turn the light off again
timer = createTimer(now.plusSeconds(30)) [|
sendCommand(Wallplug_greenhouse_Humidity, OFF)
]
} else if (receivedCommand == OFF) {
// first off command, so create a timer to turn the light ON again
timer = createTimer(now.plusSeconds(30)) [|
sendCommand(Wallplug_greenhouse_Humidity, ON)
]
}
end
You need to make sure that NO other rule or UI will send a command to this item or you’ll end up with interloping timers all over the place
var Timer timer = null
rule "demo rule LOOP1"
when
Item Wallplug_greenhouse_Humidity received command
then
if (receivedCommand == ON) {
// first ON command, so create a timer to turn the light off again
timer = createTimer(now.plusSeconds(30)) [|
Wallplug_greenhouse_Humidity.sendCommand(OFF)
]
} else if (receivedCommand == OFF) {
// first off command, so create a timer to turn the light ON again
timer = createTimer(now.plusSeconds(30)) [|
Wallplug_greenhouse_Humidity.sendCommand(ON)
]
}
end
Oh thank you, i took your script and put it on my system! works great! Read your link and kinda understood. Im probably still to new to all of this. What i did take out of it is to change the syntax. I pretty much just copy past some code i found, entered my own variables tweaked a little and made it work. However, i am not a programmer so i basically do not know what im doing! Haha
Wondering, should i be killing the timer at the end of the script? Would there be a benefit in having 2 diffeent scripts for each state (on/off)?
For anyone interested, i grow mushrooms. oster mushrooms. I already got some mechanical controlers on it but would love more options to play with. so im going to try and use openhab to control the flowering chamber
This veers just a little off topic, but in Scripted Automation you can define a scriptUnloaded function that does get called when the file is unloaded. This is a great place to cancel any running Timers you may have.
There is no equivalent to this in Rules DSL and therefore, when you reload a .rules file that has a Timer active, that Timer will become orphaned and when it finally does expire you will see an error in the logs (it will have “Procedures$Procedure” in the long complicated message. You can ignore this error.
I have noticed that sometimes my rooter wifi stops and reboots. I have also noticed that sometimes this makes my script stop. Is there some way that i could use a second triger here maybe:
when
Item Wallplug_greenhouse_Humidity received command
Thank you for any insight!
Sorry for not responding before @rlkoshak not really sure of hat you here saying and how it applied to my case…
There is a way to cancel the running Timers if you use Scripted Automation instead of Rules DSL. If you use Rules DSL, you have to expect and accept that you will see errors in the logs when your .rules file reloads.
If all your Rules are stopping you have a lock or Thread::sleep somewhere that blocks a Rule from exiting when your router goes offline. You can only run five rules at the same time so when you have five Rules blocked, none of your Rules can run.