Insert pause into lua script

User avatar
blackdog65
Posts: 535
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi
Domoticz version:
Location: Norfolk, UK
Contact:

Insert pause into lua script

Postby blackdog65 » Friday 17 February 2017 13:53

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
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E

dlefol
Posts: 10
Joined: Monday 21 December 2015 17:35
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Insert pause into lua script

Postby dlefol » Friday 17 February 2017 15:14

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.

User avatar
jvdz
Posts: 784
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Insert pause into lua script

Postby jvdz » Friday 17 February 2017 17:42

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

User avatar
blackdog65
Posts: 535
Joined: Tuesday 17 June 2014 18:25
Target OS: Raspberry Pi
Domoticz version:
Location: Norfolk, UK
Contact:

Re: Insert pause into lua script

Postby blackdog65 » Friday 17 February 2017 19:47

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
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E


Return to “LUA”

Who is online

Users browsing this forum: No registered users and 1 guest