Page 1 of 1

sending multiple GPIO states to ESPeasy

Posted: Sunday 05 January 2020 20:13
by haden
Hi
I have a ventilation system i can control with an ESPEasy device, by sending URLs to it.
In Domoticz i have a multiselector switch and a LUA script like this:

Code: Select all

commandArray = {}

if devicechanged['Ventilation'] == 'Off'  then
    print ("Ventilation switched to Off")
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,13,1' --switch off High
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,12,1' --switch off Normal
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,14,1' --switch off Low
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,16,1' --switch off unit
elseif devicechanged['Ventilation'] == 'Low'  then
    print ("Ventilation switched to Low")
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,16,0' --switch on unit
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,13,1' --switch off High
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,12,1' --switch off Normal
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,14,0' --switch on Low
elseif devicechanged['Ventilation'] == 'Normal'  then
    print ("Ventilation switched to Normal")
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,16,0' --switch on unit
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,13,1' --switch off High
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,14,1' --switch off Low
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,12,0' --switch on Normal
elseif devicechanged['Ventilation'] == 'High'  then
    print ("Ventilation switched to High")
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,16,0' --switch on unit
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,12,1' --switch off Normal
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,14,1' --switch off Low
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,13,0' --switch on High
elseif devicechanged['Ventilation'] == 'Auto'  then
    print ("Ventilation switched to Auto")
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,16,0' --switch on unit
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,13,1' --switch off High
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,12,1' --switch off Normal
    commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,14,1' --switch off Low
end 

return commandArray
However it does not work, as it seems it only change the state of one of the GPIO. Typing the URL's directly in the browser works fine. So is my script right or is there some timing issues?

Thanks

Re: sending multiple GPIO states to ESPeasy

Posted: Monday 06 January 2020 1:02
by technick
-/-

Re: sending multiple GPIO states to ESPeasy

Posted: Monday 06 January 2020 3:08
by waaren
haden wrote: Sunday 05 January 2020 20:13

Code: Select all

commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,13,1' --switch off High
commandArray['OpenURL']='http://ventilation/control?cmd=GPIO,12,1' --switch off Normal
....
return commandArray
This will not produce the expected result. On the first line you create an entry in the Lua table commandArray with key OpenURL and value 'http....'
On the 2nd line you use the same key causing it to overwrite the value you entered in the firs line.
So you will end up with a commandArray with only one value. (The last one entered)

You should use something like:

Code: Select all

commandArray[#commandArray+1]={['OpenURL']='http://ventilation/control?cmd=GPIO,13,1' }  --switch off High
commandArray[#commandArray+1]={['OpenURL']='http://ventilation/control?cmd=GPIO,12,1' }
....
This will cause commandArray to be filled with sequential integer keys starting with 1, each pointing to a table with the OpenURL command and the values you entered. Domoticz will then process all of them.

Re: sending multiple GPIO states to ESPeasy

Posted: Monday 06 January 2020 17:13
by haden
Ahh thats wasn't clear when I read the documentation, but now I see it.
Thanks @waaren for great answer