Page 1 of 1
Insert pause into lua script
Posted: Friday 17 February 2017 12:53
by blackdog65
Hiya,
I have a couple of scripts that look like this
Code: Select all
commandArray = {}
if devicechanged['Trigger'] == 'On'
then
commandArray['Device_1']='On'
commandArray['Device_2']='On'
commandArray['Device_3']='On'
commandArray['Device_4']='On'
end
return commandArray
Most of the time all 4 devices would work... sometimes just 3 as I assume the signals clash.
I've now added a 5th device and things got MUCH worse.
Is there a way to insert a tiny pause (10ms?) between each device being told to turn on?
many thanks
Sean
Re: Insert pause into lua script
Posted: Friday 17 February 2017 14:14
by dlefol
If I understand correctly how the commandArray works in domoticz, all the commands are sent only once your return the commandArray at the end of your LUA script. Adding a sleep of 10 ms between each of your lines commandArray['Device_XX']='On' would therefore do nothing special since it would just means you wait before adding the second device in the commandArray but the 4 or 5 ON commands would still be executed at the same speed by domoticz once you return the commandArray.
The only solution I can think of to put a delay between each ON command would be to use the 'On AFTER XX' command which enables you to send the command after XX seconds or minutes. I am not sure however this will help with you specific problem.
By the way for doing this kind of script I advise you to look at the dzvent project (search in domoticz forum). It simplifies a lot the scripting in LUA for domoticz I find.
Re: Insert pause into lua script
Posted: Friday 17 February 2017 16:42
by jvdz
dlefol is correct.
The only option I can think of you have is to use ON AFTER x, to make one lamp go On after the other.
Code: Select all
commandArray['Device_1']='On'
commandArray['Device_2']='On AFTER 1'
commandArray['Device_3']='On AFTER 2'
commandArray['Device_4']='On AFTER 3'
This will take 3 seconds in total to switch them on.
One other option is to do it this way, sending the command twice:
Code: Select all
commandArray[#commandArray + 1] = {['Device_1']='On'}
commandArray[#commandArray + 1] = {['Device_2']='On'}
commandArray[#commandArray + 1] = {['Device_3']='On'}
commandArray[#commandArray + 1] = {['Device_4']='On'}
commandArray[#commandArray + 1] = {['Device_1']='On AFTER 2'}
commandArray[#commandArray + 1] = {['Device_2']='On AFTER 2'}
commandArray[#commandArray + 1] = {['Device_3']='On AFTER 2'}
commandArray[#commandArray + 1] = {['Device_4']='On AFTER 2'}
Jos
Re: Insert pause into lua script
Posted: Friday 17 February 2017 18:47
by blackdog65
Thanks or the replies guys,
I've been meaning to try DZVents for a while now, maybe I'll find the time this weekend.
For now, I'll give your idea a try Jos
Sean