Lua commandArray with multiple devices issue
Moderator: leecollings
-
- Posts: 7
- Joined: Friday 26 May 2017 1:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Lua commandArray with multiple devices issue
Hi,
I'm completely stumped with a lua scripting issue whereby attempting to switch on multiple devices via the commandArray doesn't always work.
I have 2 switches, I can switch them on and off OK through the switches tab.
However, with lua, when I try switch them both on, only 1 of the 2 will activate. It seems as though domoticz isn't processing all of the entries in commandArray:
commandArray ["BedroomSwitch1"] = "On"
commandArray ["BedroomSwitch2"] = "On"
I have confirmed that the commandArray is correct by running this debug before the script exits with a "return commandArray" :
for i, v in pairs(commandArray) do
istr = tostring(I)
vstr = tostring(v)
print (istr, vstr)
end
The output from above shows both device names correctly and the On status.
There are no errors in the log, and the log displays a message that it's switching them both on (but it doesn't).
I also tried adding the 2 switches into a Group via the web interface. Again I am able to toggle both switches OK via the Group using the Scenes tab. However Lua has the same problem, when it activates the group only one of the two switches is toggled.
So it seems the issue is that domoticz doesn't process all of the entries in the commandArray.
I'm on domoticz 3.5877
Can anyone offer any help?
Thanks
I'm completely stumped with a lua scripting issue whereby attempting to switch on multiple devices via the commandArray doesn't always work.
I have 2 switches, I can switch them on and off OK through the switches tab.
However, with lua, when I try switch them both on, only 1 of the 2 will activate. It seems as though domoticz isn't processing all of the entries in commandArray:
commandArray ["BedroomSwitch1"] = "On"
commandArray ["BedroomSwitch2"] = "On"
I have confirmed that the commandArray is correct by running this debug before the script exits with a "return commandArray" :
for i, v in pairs(commandArray) do
istr = tostring(I)
vstr = tostring(v)
print (istr, vstr)
end
The output from above shows both device names correctly and the On status.
There are no errors in the log, and the log displays a message that it's switching them both on (but it doesn't).
I also tried adding the 2 switches into a Group via the web interface. Again I am able to toggle both switches OK via the Group using the Scenes tab. However Lua has the same problem, when it activates the group only one of the two switches is toggled.
So it seems the issue is that domoticz doesn't process all of the entries in the commandArray.
I'm on domoticz 3.5877
Can anyone offer any help?
Thanks
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Lua commandArray with multiple devices issue
multiple command for the same device can/should be done in a different way
but... keep in mind the command is executed NOT in the moment the script is compiled, but at the end of it (at the return commandArray line) so, they are all issued in the same moment
or
if you write something like:
the 4th line will overwrite the other 3...
have a look to http://domoticz.com/wiki/Events to better understand how a script works
ciao
M
but... keep in mind the command is executed NOT in the moment the script is compiled, but at the end of it (at the return commandArray line) so, they are all issued in the same moment
Code: Select all
commandArray = {}
commandArray[1]={['Lamp']='On'}
commandArray[2]={['Lamp']='On'}
commandArray[3]={['Lamp']='On'}
return commandArray =
Code: Select all
commandArray = {}
commandArray[#commandArray +1]={['Lamp']='On'}
commandArray[#commandArray +1]={['Lamp']='On'}
commandArray[#commandArray +1]={['Lamp']='On'}
return commandArray =
Code: Select all
commandArray = {}
commandArray[1]={['Lamp']='On'}
commandArray[2]={['Lamp']='On'}
commandArray[3]={['Lamp']='On'}
commandArray['Lamp']='On'
return commandArray =
have a look to http://domoticz.com/wiki/Events to better understand how a script works

ciao
M
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
-
- Posts: 7
- Joined: Friday 26 May 2017 1:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua commandArray with multiple devices issue
So remember I'm activating two different lamps, not the same lamp twice i.e
commandArray ["BedroomSwitch1"] = "On"
commandArray ["BedroomSwitch2"] = "On"
Are you saying the above syntax means Switch2 will overwrite Switch1?
I don't think that is the case because the domoticz log file definitely shows it trying to turn on both switches , and on the webpage the switches tab shows them both go ON, however one of them didn't physically switch on.
Domoticz can communicate fine with both switches if I don't use lua.
Thanks
commandArray ["BedroomSwitch1"] = "On"
commandArray ["BedroomSwitch2"] = "On"
Are you saying the above syntax means Switch2 will overwrite Switch1?
I don't think that is the case because the domoticz log file definitely shows it trying to turn on both switches , and on the webpage the switches tab shows them both go ON, however one of them didn't physically switch on.
Domoticz can communicate fine with both switches if I don't use lua.
Thanks
- jvdz
- Posts: 2335
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Lua commandArray with multiple devices issue
So it looks like it is sensitive to switching them close after eachother. What type of hareware is this? Zwave/RFX/ Other?
Maybe you could try to switch each switch a couple of times with the logic emme provided?
Jos
Maybe you could try to switch each switch a couple of times with the logic emme provided?
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Re: Lua commandArray with multiple devices issue
Can you upgrade first and try again?mortyone wrote:I'm on domoticz 3.5877
And post your script?
-
- Posts: 7
- Joined: Friday 26 May 2017 1:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua commandArray with multiple devices issue
Hi,
My transceiver is a RF Link Gateway USB v46.0 from nemcom.nl.
I think the hardware is fine, otherwise I would not be able to turn the switches on and off from the web GUI.
Below is a simplified version of my device script, which has the same issue. In this simplified example, any PIR motion anywhere should turn on the 2 bedroom switches.
script_device_pirs.lua
Here's a screenshot from the dashboard which logically shows that Domoticz *thinks* it has turned on the 2 switches:-
v3.5877 still seems to be the latest stable build?
I tried upgrading to BETA 7366, however things became even worse - NONE of the lua scripts would run after the upgrade.
So I tried reverting back to 5877 but the lua scripts still won't run, no event information appears in the logs.
I have confirmed that the Event System is not disabled under the Setup menu. Interestingly, through the web GUI I can still turn switches on and off, and my PIRs also show new "last seen" times, so the issue seems to be localised to lua and the upgrade has left some additional residual issue which now prevents scripts running at all.
I also tried renaming the domoticz directory to domoticz_old and reinstalling, but same issue, no lua scripts will run since the beta upgrade.
What is the correct way to cleanly uninstall Domoticz before doing a fresh install on a pi?
Thanks
My transceiver is a RF Link Gateway USB v46.0 from nemcom.nl.
I think the hardware is fine, otherwise I would not be able to turn the switches on and off from the web GUI.
Below is a simplified version of my device script, which has the same issue. In this simplified example, any PIR motion anywhere should turn on the 2 bedroom switches.
script_device_pirs.lua
- Spoiler: show
Here's a screenshot from the dashboard which logically shows that Domoticz *thinks* it has turned on the 2 switches:-
v3.5877 still seems to be the latest stable build?
I tried upgrading to BETA 7366, however things became even worse - NONE of the lua scripts would run after the upgrade.


I have confirmed that the Event System is not disabled under the Setup menu. Interestingly, through the web GUI I can still turn switches on and off, and my PIRs also show new "last seen" times, so the issue seems to be localised to lua and the upgrade has left some additional residual issue which now prevents scripts running at all.
I also tried renaming the domoticz directory to domoticz_old and reinstalling, but same issue, no lua scripts will run since the beta upgrade.
What is the correct way to cleanly uninstall Domoticz before doing a fresh install on a pi?
Thanks
-
- Posts: 7
- Joined: Friday 26 May 2017 1:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua commandArray with multiple devices issue
UPDATE - my original issue is not resolved, but I have managed to get lua scripts running again through 2 steps:-
1) run the shell script /home/pi/domoticz/updaterelease (v3.5877)
2) created a dummy BLOCKY scipt, which seemed to kick start the event system and start running lua scripts again in /home/pi/domoticz/scripts/lua/
I've since also removed my lua scripts and used BLOCKY only, the same issue persists i.e. the Domoticz web GUI shows the 2 switches turn on (and the log also shows them switch on) but this physically doesn't happen in real life.
From the web GUI I can still turn the switches on and off, so the transceiver is working.
In summary, this looks like an Event System issue, it's not fully executing the commands from lua or Blocky?
Any help greatly appreciated, I'm at an absolute loss as to what to do next.
Thanks
1) run the shell script /home/pi/domoticz/updaterelease (v3.5877)
2) created a dummy BLOCKY scipt, which seemed to kick start the event system and start running lua scripts again in /home/pi/domoticz/scripts/lua/
I've since also removed my lua scripts and used BLOCKY only, the same issue persists i.e. the Domoticz web GUI shows the 2 switches turn on (and the log also shows them switch on) but this physically doesn't happen in real life.
From the web GUI I can still turn the switches on and off, so the transceiver is working.
In summary, this looks like an Event System issue, it's not fully executing the commands from lua or Blocky?
Any help greatly appreciated, I'm at an absolute loss as to what to do next.
Thanks
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: Lua commandArray with multiple devices issue
Unlikely Lua and Blockly device handling doesn't work otherwise we would all have noticed.
The big difference is the timing between GUI and scripting. With the web interface there will be seconds between the 2 commands to the 2 devices, whereas script wise will be instant.
You haven't described your set up fully. I know with my system with LightwaveRF multiple switches / sockets these share a reciever, so if I send commands to two switches only the first will operate, so In groups and scenes I separate the commands by putting in another device.
Two things to try:
1. Create a group for 2 devices and rest switching that on and off, I think you will have the same problem as you see with the scripts.
2. Add a 1 second on delay to the second switch, I think this should remove the problem.
If these don't show any differences then please add some more details of your system.
The big difference is the timing between GUI and scripting. With the web interface there will be seconds between the 2 commands to the 2 devices, whereas script wise will be instant.
You haven't described your set up fully. I know with my system with LightwaveRF multiple switches / sockets these share a reciever, so if I send commands to two switches only the first will operate, so In groups and scenes I separate the commands by putting in another device.
Two things to try:
1. Create a group for 2 devices and rest switching that on and off, I think you will have the same problem as you see with the scripts.
2. Add a 1 second on delay to the second switch, I think this should remove the problem.
If these don't show any differences then please add some more details of your system.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
-
- Posts: 7
- Joined: Friday 26 May 2017 1:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua commandArray with multiple devices issue
Hi,
Thank you for your advice, very much appreciated, I tested the 1 second delay you suggested and that did the trick perfectly, very interesting.
Earlier today I also found a different hacky workaround - I introduced a user variable which is initialised to 3 when the PIR detects motion and activates the 2 switches. Then when script_device_pirs.lua is called again for the switch 1 state change if the variable is > 0 it will again turn on switches 1 and 2 and subtract 1 from the variable etc so basically it attempts the ON command 3 times. Somehow this gets the signal through.
Main thing for me now is that I have working solution, even if it is a little rough around the edges.
Thanks again for your help.
Thank you for your advice, very much appreciated, I tested the 1 second delay you suggested and that did the trick perfectly, very interesting.
Earlier today I also found a different hacky workaround - I introduced a user variable which is initialised to 3 when the PIR detects motion and activates the 2 switches. Then when script_device_pirs.lua is called again for the switch 1 state change if the variable is > 0 it will again turn on switches 1 and 2 and subtract 1 from the variable etc so basically it attempts the ON command 3 times. Somehow this gets the signal through.
Main thing for me now is that I have working solution, even if it is a little rough around the edges.
Thanks again for your help.
- luberth
- Posts: 34
- Joined: Friday 27 April 2018 7:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: Bangert 30 Andijk Nederland
- Contact:
Re: Lua commandArray with multiple devices issue
Hello
do not understand why i have to make 2 lua scripts to get it working
2 temperatures from weather service
but update 2 from 1 script does not work
log print is ok
http://test:[email protected]:8080/#/Floorplans
above is not working when updating 2 temperatures
should be
do not understand why i have to make 2 lua scripts to get it working
2 temperatures from weather service
but update 2 from 1 script does not work
log print is ok
http://test:[email protected]:8080/#/Floorplans
Code: Select all
commandArray = {}
now=os.date("*t")
-- http://jsonviewer.stack.hu/#http://json.buienradar.nl
if now.min % 1 == 0 then
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- API call
local config=assert(io.popen('curl "https://api.buienradar.nl/data/public/2.0/jsonfeed"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
--temp_berkhout = jsonData.actual.stationmeasurements[3].temperature
--station1= jsonData.actual.stationmeasurements[3].stationname
--print (" "..station1)
--print (" "..temp_berkhout)
--commandArray['UpdateDevice']='14|1|'..temp_berkhout
temp_stavoren = jsonData.actual.stationmeasurements[38].temperature
station2 = jsonData.actual.stationmeasurements[38].stationname
print (" "..station2)
print (" "..temp_stavoren)
commandArray['UpdateDevice']='16|1|'..temp_stavoren
end
return commandArray
above is not working when updating 2 temperatures
should be
Code: Select all
commandArray = {}
now=os.date("*t")
-- http://jsonviewer.stack.hu/#http://json.buienradar.nl
if now.min % 1 == 0 then
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- API call
local config=assert(io.popen('curl "https://api.buienradar.nl/data/public/2.0/jsonfeed"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
temp_berkhout = jsonData.actual.stationmeasurements[3].temperature
station1= jsonData.actual.stationmeasurements[3].stationname
print (" "..station1)
print (" "..temp_berkhout)
-- commandArray['UpdateDevice']='14|1|'..temp_berkhout
temp_stavoren = jsonData.actual.stationmeasurements[38].temperature
station2 = jsonData.actual.stationmeasurements[38].stationname
print (" "..station2)
print (" "..temp_stavoren)
--commandArray['UpdateDevice']='16|1|'..temp_stavoren
commandArray[#commandArray+1] = {['UpdateDevice'] = '14|1|'..temp_berkhout}
commandArray[#commandArray+1] = {['UpdateDevice'] = '16|1|'..temp_stavoren}
end
return commandArray
Last edited by luberth on Monday 05 November 2018 20:40, edited 2 times in total.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Lua commandArray with multiple devices issue
Here the 2nd commandArray would overwrite the first one. Tryluberth wrote: ↑Monday 05 November 2018 20:04Code: Select all
commandArray['UpdateDevice']='14|1|'..temp_berkhout commandArray['UpdateDevice']='16|1|'..temp_stavoren
Code: Select all
commandArray[#commandArray+1] = {['UpdateDevice'] = '14|1|'..temp_berkhout }
commandArray[#commandArray+1] = {['UpdateDevice'] = '16|1|'..temp_stavoren }
Last edited by waaren on Monday 05 November 2018 21:44, edited 1 time in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- luberth
- Posts: 34
- Joined: Friday 27 April 2018 7:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: Bangert 30 Andijk Nederland
- Contact:
Re: Lua commandArray with multiple devices issue
thank you verry much for the fast and working reply
this code is working in 1 lua script
groet luberth
http://test:[email protected]:8080/#/Floorplans
this code is working in 1 lua script
groet luberth
http://test:[email protected]:8080/#/Floorplans
Code: Select all
commandArray = {}
now=os.date("*t")
-- Domoticz lua timed script
-- like the next jsonviewer when you use top left button [View] it gives a nice overview of the json
-- http://jsonviewer.stack.hu/#http://json.buienradar.nl
-- http://test:[email protected]:8080/#/Floorplans
-- php can handle "http://json.buienradar.nl"
-- LUA needs the real path "https://api.buienradar.nl/data/public/2.0/jsonfeed"
if now.min % 1 == 0 then
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- API call
local config=assert(io.popen('curl "https://api.buienradar.nl/data/public/2.0/jsonfeed"'))
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
temp_berkhout = jsonData.actual.stationmeasurements[3].temperature
station1= jsonData.actual.stationmeasurements[3].stationname
print (" "..station1)
print (" "..temp_berkhout)
-- next line is not correct for updating multiple devices from 1 script
-- commandArray['UpdateDevice']='14|1|'..temp_berkhout
temp_stavoren = jsonData.actual.stationmeasurements[38].temperature
station2 = jsonData.actual.stationmeasurements[38].stationname
print (" "..station2)
print (" "..temp_stavoren)
-- next line is not correct for updating multiple devices from 1 script
--commandArray['UpdateDevice']='16|1|'..temp_stavoren
-- this is ok for updating multiple devices
commandArray[#commandArray+1] = {['UpdateDevice'] = '14|1|'..temp_berkhout}
commandArray[#commandArray+1] = {['UpdateDevice'] = '16|1|'..temp_stavoren}
end
return commandArray
Who is online
Users browsing this forum: No registered users and 1 guest