I have few time script that runs for more than 1 minute (they ping some devices and retry if they are not availble... so it could take time)
Because it is supposed to trigger switches in Domoticz, I have the issue that the script runs twice because a minute pass and it strats while the old one is still running.
This results in double actions... I don't like it!
So, unless there is no a clear way to avoid a script to run in case it has not finished yet, I create a not-so-complex workaround I'm going to show you:
Example:
script_time_dostuff.lua
Code: Select all
commandArray = {}
os.execute('sleep 65')
return commandArray
SOLUTION:
CREATE:
string variable called dostuff_running (0-not running, 1-running)
script_time_dostuff_running.lua
Code: Select all
commandArray = {}
os.execute('sleep 2') --this to ensure the other script starts
if uservariables['dostuff_running'] == '0' then commandArray['Variable:dostuff_running'] = '1'
return commandArray
Code: Select all
commandArray = {}
if uservariables['dostuff_running'] == '0' then
os.execute('sleep 65')
end
commandArray['Variable:dostuff_running'] = '0'
return commandArray
ciao
M