delay, pause, sleep script for xx seconds. how to?

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
bitzy
Posts: 36
Joined: Tuesday 18 April 2023 8:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

delay, pause, sleep script for xx seconds. how to?

Post by bitzy »

i need to pause or sleep or delay somehow a script for 120 seconds. someone can help me telling me how to do it?
i need a switch to turn on , a variable to get value 'true', then i need the script to wait for 120 seconds for the physical action to take place, then the var to take the 'false' value. i 'm not getting how pause/sleep works in domoticz !!!
something like this:

Code: Select all

moveRl.switchOn().forSec(120)
    valveResetInProgress.set('true')
     dz.log('Waiting for 120 seconds before setting valve position...', dz.LOG_INFO)
  
     sleep(120)
     valveResetInProgress.set('false')
solarboy
Posts: 345
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by solarboy »

You could try

Code: Select all

valveResetInProgress.set('true')
valveResetInProgress.set('false').afterSec(120)
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by HvdW »

Try to avoid using sleep()
Run your script every 2 minutes.
https://www.domoticz.com/wiki/Events
Bugs bug me.
bitzy
Posts: 36
Joined: Tuesday 18 April 2023 8:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by bitzy »

none of this is helpful. this is the full picture: i have a script that run every 2 minute (or 1 min, or 3, 10 ..) to control an actuator witch move a mixing valve to keep a constant temperature when a pump switch is on and a auto-manual selector is in auto state. when i turn off one of those 2, the regulating temperature script is stopped and the actuator move the valve all the way in max-down position (this way i do a synchronization between the physical valve position and the variable that keep the position of the valve in domoticz and protect the underfloor circuits of a temperature spike if the pump is starting at a temperature of 80 - 90 degree and the valve is in the open position). in those 120 seconds when the valve is moving down, if the regulating script is turned back on and start to move the valve, the reset of the valve is stopped and the physical position is way off from the position that domoticz know the valve have (max-down (-60). so, i need a way to make domoticz know that the valve is moving and to not start any other command on the valve's actuator while this is in motion from the reset command.
viewtopic.php?t=40261 here are the full script that control the actuator and the script that reset the valve.
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by hoeby »

What you can do is make a dz.openUrl with a callback function.
This dz.OpenUrl is then fired after X seconds. In your case the 120 seconds.

With the callback you can retrigger your script to do the thing it then has to do.

As far as i known. There is now real delay option in dzvents. Because a delay will pause all process of your system, what you don't want. This is kind of a work around, to retrigger the script after the seconds your programmed
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by hoeby »

Info about this option in dzvents wiki
https://www.domoticz.com/wiki/DzVents:_ ... d_handling

Do the dz.openUrl with a afterSec() added, that will work as a delay
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
solarboy
Posts: 345
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by solarboy »

hoeby wrote: Saturday 21 October 2023 23:08 Info about this option in dzvents wiki
https://www.domoticz.com/wiki/DzVents:_ ... d_handling

Do the dz.openUrl with a afterSec() added, that will work as a delay
Exactly and perhaps add the delayed switch as a "device trigger"
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
willemd
Posts: 642
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by willemd »

Did you solve your issue? I had a similar requirement and this is how I would translate my solution to your case:

1) You need to have either a device or a persistent variable to hold your red flag, so if this device or variable is true then no further action is allowed.
2) You set the red flag when you start the valve-reset action.
3) At the same time you run the command: domoticz.emitEvent('ResetRedFlag').afterMin(2)
4) You add 'ResetRedFlag' as a customEvents trigger to your script
4) Each time the script is started, it checks whether it was launched by one of the previous triggers or by the customEvent trigger.
5) If it was triggered by one of the previously existing triggers, it checks for the red flag and if the red flag was set, it stops, otherwise it continues.
6) If it was triggered by the customEvent, then it resets the red flag.
neveride
Posts: 8
Joined: Saturday 30 March 2024 10:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by neveride »

And where can I find a manual for the blockly commands? I see a "set after" block. I execute my script at e.g. 20:00 and I see in the logs that it was triggered. I set my ligts "On" after 60 seconds and then in the second action I set my lights "Off" after 120 seconds. I would expect my lights to turn on at 20:01 for one minute. But nothing happens.
User avatar
waltervl
Posts: 5842
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by waltervl »

Here is the wiki https://www.domoticz.com/wiki/Blockly

And here is the forum about blockly https://www.domoticz.com/forum/viewforum.php?f=62
Please make a new topic in that forum if you have specific questions about Blockly (search the subforum first!)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
neveride
Posts: 8
Joined: Saturday 30 March 2024 10:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: delay, pause, sleep script for xx seconds. how to?

Post by neveride »

OK, just to respond to my issue, because I solved it. Do not use diacritical signs in your devices' names (in Polish e.g. ę, ą, ć, ó, ż, ź, ć). Blockly will fail. I changed my device name to English and everything works as it should. Not sure it is mentioned somewhere, but I haven't stumbled upon it, so it cost me some nerves.

@waltervl: obviously I visited https://www.domoticz.com/wiki/Blockly, but I did not find information about how set after works...One can only assume that it's logical.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest