arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.2k stars 4.81k forks source link

Method to retrieve ALL possible GPIO components via MQTT, including assigned #6407

Closed jziolkowski closed 5 years ago

jziolkowski commented 5 years ago

The command "gpios" returns all components but without those assigned in module config or template. To be able to edit templates externally, this needs extra work to compile a complete list.

Such list of all available GPIOs (including these assigned) is available in the comboboxes in template edit - could it be available via MQTT? Maybe just adding a parameter to existing command, or a whole new command? That would greatly help external management tools (like TDM wink wink nudge nudge)

arendst commented 5 years ago

Not all GPIO are available in all compilations. Depending on defines enabled many GPIO's are not present so your list will almost never be complete.

The ones assigned in module config can be shown with command gpio.

jziolkowski commented 5 years ago

Yes, I know. That's why I'm polling each device before configuring gpios. I don't want a list of all gpios available in whole Tasmota - but only in that certain device.

jziolkowski commented 5 years ago

The comboboxes in template edit shows exactly the data I need - independent of currently used/configured gpios.

arendst commented 5 years ago

The template combo box holds exactly the same information as command gpios with an additional User 255

jziolkowski commented 5 years ago

I beg to differ. The output below is from a 3-button device configured via template.

09:24:14 MQT: stat/ds102_chlopcy/RESULT = {"NAME":"DS-102 3 Gang","GPIO":[57,59,0,18,22,19,0,0,17,21,58,25,56],"FLAG":0,"BASE":18}

09:19:14 CMD: gpios
09:19:14 MQT: stat/ds102_chlopcy/RESULT = {"GPIOs1":["0 (None)","20 (Button4)","93 (Button4n)","125 (Button4i)","129 (Button4in)","9 (Switch1)","82 (Switch1n)","10 (Switch2)","83 (Switch2n)","11 (Switch3)","84 (Switch3n)","12 (Switch4)","85 (Switch4n)","13 (Switch5)","86 (Switch5n)","14 (Switch6)","87 (Switch6n)","15 (Switch7)","88 (Switch7n)","16 (Switch8)","89 (Switch8n)","23 (Relay3)","31 (Relay3i)","24 (Relay4)","32 (Relay4i)","26 (Relay6)","34 (Relay6i)"]}
09:19:14 MQT: stat/ds102_chlopcy/RESULT = {"GPIOs2":["27 (Relay7)","35 (Relay7i)","28 (Relay8)","36 (Relay8i)","37 (PWM1)","46 (PWM1i)","38 (PWM2)","47 (PWM2i)","39 (PWM3)","48 (PWM3i)","40 (PWM4)","49 (PWM4i)","41 (PWM5)","50 (PWM5i)","42 (Counter1)","94 (Counter1n)","43 (Counter2)","95 (Counter2n)","44 (Counter3)","96 (Counter3n)","45 (Counter4)","97 (Counter4n)","148 (Serial Tx)","149 (Serial Rx)","5 (I2C SCL)","6 (I2C SDA)","1 (DHT11)","2 (AM2301)","3 (SI7021)"]}
09:19:15 MQT: stat/ds102_chlopcy/RESULT = {"GPIOs3":["4 (DS18x20)","7 (WS2812)","8 (IRsend)","51 (IRrecv)","105 (RFSend)","106 (RFrecv)","73 (SR04 Tri)","74 (SR04 Ech)","102 (HX711 SCK)","103 (HX711 DAT)","130 (HLWBL SEL)","131 (HLWBL SELi)","132 (HLWBL CF1)","133 (HLW8012 CF)","134 (BL0937 CF)","156 (ADE7953 IRQ)","145 (CSE7766 Tx)","146 (CSE7766 Rx)","135 (MCP39F5 Tx)","136 (MCP39F5 Rx)","137 (MCP39F5 Rst)","62 (PZEM0XX Tx)","63 (PZEM004 Rx)","98 (PZEM016 Rx)"]}
09:19:15 MQT: stat/ds102_chlopcy/RESULT = {"GPIOs4":["99 (PZEM017 Rx)","71 (SerBr Tx)","72 (SerBr Rx)","60 (MHZ Tx)","61 (MHZ Rx)","64 (SAir Tx)","65 (SAir Rx)","101 (SDS0X1 Tx)","70 (SDS0X1 Rx)","69 (PMS5003)","104 (TX20)","107 (Tuya Tx)","108 (Tuya Rx)","143 (MY92x1 DI)","144 (MY92x1 DCKI)","140 (SM16716 CLK)","141 (SM16716 DAT)","142 (SM16716 PWR)","147 (ALux IrRcv)"]}

09:19:29 CMD: gpio
09:19:29 MQT: stat/ds102_chlopcy/RESULT = {"GPIO":"Not supported"}

However, at the same time, I can see all the GPIOs in the template editor: image

(ignore that I have Relay5 instead of Relay3, it's for testing purposes)

jziolkowski commented 5 years ago

Also, it would be so nice if the GPIOs JSON output would be a dict keyed with gpio id, instead of flat list, but one can only dream :)

arendst commented 5 years ago

Ha, got it.

Will see.

arendst commented 5 years ago

What format would you like the dict keyed to look like?

jziolkowski commented 5 years ago

Oh, you spoil me.

Maybe something like this:

{"GPIOs1": {"0": "None", "20": "Button4", "93": "Button4n", "125": "Button4i", "129": "Button4in", "9": "Switch1", "82": "Switch1n", "10": "Switch2", "83": "Switch2n", "11": "Switch3", "84": "Switch3n", "12": "Switch4", "85": "Switch4n", "13": "Switch5", "86": "Switch5n", "14": "Switch6", "87": "Switch6n", "15": "Switch7", "88": "Switch7n", "16": "Switch8", "89": "Switch8n", "23": "Relay3", "31": "Relay3i", "24": "Relay4", "32": "Relay4i", "26": "Relay6", "34": "Relay6i"} }

etc

IF the modules JSON output would follow suit it would be too good to be true ;)

arendst commented 5 years ago

For now you'll have to deal with the old output format ;-)

jziolkowski commented 5 years ago

Hehe noticed, I'm reading the commit. Thanks a lot anyways. New output is just cosmetics, because it's easy to parse as-is.

This commit was the main request and it finally allows templates to be edited using external tools. Thanks a lot!

arendst commented 5 years ago

I'll change the ouput too as I noticed it is more readable and also not longer than the original.

Hold on.

jziolkowski commented 5 years ago

Yes, removing the brackets saves quite a few bytes in the whole payload. Thanks again for this, makes it much easier for tool makers.