sleep command dzVents

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

Moderator: leecollings

Post Reply
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

sleep command dzVents

Post by poudenes »

Hi All,

I have add all scripts into 1. Easier way to manage local variables and device IDX. But now i see some problems.
It is working so fast that multiple IF statements are runs when its not good.

Is there a way to let the script sleep for een certain time ms or sec before it goes to next if or else if statement?

If this is possible the if statement that must run all commands can be done wait for 1 sec then goto the next.
The next if statement will only act if everything in the if is true or false.

On Internet see lot of options and this one seems only to work but don't know:

Code: Select all

function sleep (a) 
    local sec = tonumber(os.clock() + a); 
    while (os.clock() < sec) do 
    end 
end
But when i add this at end of the if statment i see that after 1 sec for example the commands are running. Not before and then the sleep action.

Cheers,
Peter
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sleep command dzVents

Post by waaren »

If the reason for the sleep is to base your logic on activated changes in domoticz devices then please be aware that dzVents ( and other event scripting systems ) send the commands back to domoticz after the script has finished. So the device state inside your script doesn't change.
So waiting for something to happen in domoticz inside your script is not working.
Last edited by waaren on Friday 30 March 2018 14:27, edited 1 time in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: sleep command dzVents

Post by poudenes »

Thanks for the info.

As writing and look at the script i see i have some scene switches into the devices = {}
That is not ok. Removed them and now the whole loop problems is gone.

Didn't saw the problem until now... grrr :lol:
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: sleep command dzVents

Post by dannybloe »

I really advice against putting everything in one script.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: sleep command dzVents

Post by poudenes »

And why? Because managing is much easier now... The script is working. Have split it in "by device" "nighttime ""daytime" and "every minute"


Verzonden vanaf mijn iPhone met Tapatalk Pro
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest