Events Sleep/Wait command

Moderator: leecollings

Post Reply
SilasAT
Posts: 3
Joined: Monday 02 November 2015 15:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Events Sleep/Wait command

Post 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
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Events Sleep/Wait command

Post by tozzke »

you could create an extra dummy switch with a switch off delay and use that in the next 'else if'-block
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Events Sleep/Wait command

Post by Egregius »

Or you use php for scripting. Usleep and sleep are standard functions for microseconds or seconds wait time.
SilasAT
Posts: 3
Joined: Monday 02 November 2015 15:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Events Sleep/Wait command

Post by SilasAT »

Can you explain how these methods works?
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Events Sleep/Wait command

Post 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.
SilasAT
Posts: 3
Joined: Monday 02 November 2015 15:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Events Sleep/Wait command

Post by SilasAT »

But we are creating it in the GUI :-) So can we make a combination of php and GUI?
raym
Posts: 81
Joined: Tuesday 03 November 2015 5:07
Target OS: Linux
Domoticz version: beta
Contact:

Re: Events Sleep/Wait command

Post 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.
grelle
Posts: 7
Joined: Thursday 28 November 2013 11:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Sweden / Östersund
Contact:

Re: Events Sleep/Wait command

Post 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
Sweden / Östersund
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Events Sleep/Wait command

Post by tlpeter »

Never mind, didn't work well
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest