sending multiple GPIO states to ESPeasy Topic is solved

Moderator: leecollings

Post Reply
haden
Posts: 7
Joined: Sunday 28 February 2016 17:11
Target OS: Windows
Domoticz version:
Contact:

sending multiple GPIO states to ESPeasy

Post 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
technick
Posts: 5
Joined: Wednesday 12 July 2017 3:20
Target OS: Linux
Domoticz version:

Re: sending multiple GPIO states to ESPeasy

Post by technick »

-/-
Last edited by technick on Monday 06 January 2020 21:48, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sending multiple GPIO states to ESPeasy

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
haden
Posts: 7
Joined: Sunday 28 February 2016 17:11
Target OS: Windows
Domoticz version:
Contact:

Re: sending multiple GPIO states to ESPeasy

Post by haden »

Ahh thats wasn't clear when I read the documentation, but now I see it.
Thanks @waaren for great answer
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests