Page 1 of 1

Events Sleep/Wait command

Posted: Monday 02 November 2015 15:53
by SilasAT
Hello, we want to control a heater with the help of eventes (Blockly) but we are missing a Sleep/Wait command were we can define how many ms or seconds we want to wait before proceding to the next block. All help would be appreciated.

Silas :D

Re: Events Sleep/Wait command

Posted: Monday 02 November 2015 22:15
by tozzke
you could create an extra dummy switch with a switch off delay and use that in the next 'else if'-block

Re: Events Sleep/Wait command

Posted: Tuesday 03 November 2015 6:48
by Egregius
Or you use php for scripting. Usleep and sleep are standard functions for microseconds or seconds wait time.

Re: Events Sleep/Wait command

Posted: Tuesday 03 November 2015 7:38
by SilasAT
Can you explain how these methods works?

Re: Events Sleep/Wait command

Posted: Tuesday 03 November 2015 20:35
by Egregius
You mean in PHP? Simple, just add sleep(5) where you want the script to sleep 5 seconds. Or usleep(500000) for half a second.
But that requires that your whole script is in PHP offcourse.

Re: Events Sleep/Wait command

Posted: Wednesday 04 November 2015 6:10
by SilasAT
But we are creating it in the GUI :-) So can we make a combination of php and GUI?

Re: Events Sleep/Wait command

Posted: Tuesday 10 November 2015 8:03
by raym
Hi, I've been trying to understand this myself lately. I realise putting delays in LUA scripts is not recommended but is it OK to put delays in a php or bash script (for example)? This won't block DZ from processing other requests will it?

What's the recommended approach for putting delays between device calls?

Thanks.

Re: Events Sleep/Wait command

Posted: Wednesday 11 November 2015 19:36
by grelle
I have a similar problem and maybe we can get an answer that suits us both...

My 1-wire counter seemes to post the same thing twice with in milliseconds. This makes my LUA script trigger twice and destroy my actual watt calculation. Gaaaah, why is 1-wire posting twice and why can't I use the sleep function I have tried in my LUA script ?

Code: Select all

2015-11-11 19:31:09.043 (1-Wire) RFXMeter (Total Energi)
2015-11-11 19:31:09.271 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_counter_vp.lua
2015-11-11 19:31:09.138 (1-Wire) RFXMeter (VP Energi)
2015-11-11 19:31:09.332 (1-Wire) RFXMeter (Total Energi)
2015-11-11 19:31:09.610 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_counter_vp.lua
2015-11-11 19:31:09.502 (1-Wire) RFXMeter (VP Energi)

Code: Select all

--Domoticz Script to get medium actual energy between energy counter readings and puts it on a dummy device

--First create a dummy energy meter and two user variables as numbers.
--Then enter the details below

--Name of the real energy counter
energyCounter = 'VP Energi'
newValue = tonumber(otherdevices_svalues[energyCounter]) * 10
--ID of the created dummy energy meter with the new actual value
dummyEnergyMeterid = 65
hour = 3600
--The names of two user variables to keep track of previous value due to wrong values from dummy in otherdevices_lastupdate and other$
userVariableTimestamp = 'LastEnergyTimestamp'
userVariableLastCount = 'LastEnergyCount'

commandArray = {}
if devicechanged[energyCounter] then
        --calculate new actual value
        actual = ((newValue) - tonumber(uservariables[userVariableLastCount])) * hour / ((os.time()-uservariables[userVariableTimesta$

        --update dummy energy meter
        commandArray[1] = {['UpdateDevice'] = dummyEnergyMeterid .. "|0|" .. actual .. ";" .. newValue}

        --update user variables
        commandArray[2] = {['Variable:'..userVariableTimestamp] = tostring(os.time())}
        commandArray[3] = {['Variable:'..userVariableLastCount] = tostring(newValue)}

        -- print("DummyEnergy: " .. actual .. " W, " .. newValue .. " kWh")

function sleep(n)
        n = 1
        os.execute("sleep " .. tonumber(n))
end

end

return commandArray

Re: Events Sleep/Wait command

Posted: Thursday 28 July 2016 15:17
by tlpeter
Never mind, didn't work well