Populate dropdown from MQTT

Hello all,

I'd like to populate the dashboard dropdown by using an "mqtt-in" element:
mqtt_dropdown

So the idea is to send mqtt messages from my ESP32 to fill up the dropdown with new elements.

Is something like that possible?

Thank you very much for your help
Matteo

Yes it is possible, but with out more info like the incoming message and the info you want in the dropdown it is hard to say how exactly.

What I'd like to achieve is to fill the dropdown with new entries from an external source through MQTT messages. The result would be like I'm editing it inside the node-red ui by adding manually new Options. Something like that (marked red):

The incoming MQTT-message is controlled by me, so I can create the QMTT message topic as needed.

Please start reading the help text for the drop down node. It is very well described how you shall populate the dropdowns

I have read the help text but I can't figure out how the MQTT-message string has to be formatted to add new entries to the dropdown element. One single example would be enough for me.

Here is an example of setting options via mqtt.
Click the injects and the options will change.
Hope it helps.

[{"id":"3def0d93.e3949a","type":"mqtt in","z":"c74669a0.6a34f8","name":"","topic":"mqtt/option/dorpdown","qos":"2","datatype":"json","broker":"d675b749.04b9c8","x":180,"y":2940,"wires":[["15356478.1211ac"]]},{"id":"15356478.1211ac","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"options","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":2920,"wires":[["e1165fd6.2733a8","118f1320.d242b5"]]},{"id":"e1165fd6.2733a8","type":"ui_dropdown","z":"c74669a0.6a34f8","name":"","label":"","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":17,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","x":530,"y":2960,"wires":[[]]},{"id":"118f1320.d242b5","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"options","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":2920,"wires":[]},{"id":"e729e11b.0f2818","type":"inject","z":"c74669a0.6a34f8","name":"option set 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"mqtt/option/dorpdown","payload":"[{\"Choice 1\":\"1\"},{\"Choice 2\":\"2\"},{\"Choice 3\":\"3\"}]","payloadType":"json","x":240,"y":3080,"wires":[["ee46676d.617f6"]]},{"id":"89a676e0.fc37c8","type":"inject","z":"c74669a0.6a34f8","name":"option set 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"mqtt/option/dorpdown","payload":"[{\"Choice 4\":\"4\"},{\"Choice 5\":\"5\"},{\"Choice 6\":\"6\"}]","payloadType":"json","x":240,"y":3120,"wires":[["ee46676d.617f6"]]},{"id":"ee46676d.617f6","type":"mqtt out","z":"c74669a0.6a34f8","name":"","topic":"","qos":"","retain":"","broker":"d675b749.04b9c8","x":370,"y":3080,"wires":[]},{"id":"d675b749.04b9c8","type":"mqtt-broker","name":"Localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","disabled":false,"hidden":false}]

the payload of the mqtt message should have the format

[{"Choice 1":"1"},{"Choice 2":"2"},{"Choice 3":"3"}]

Or others as descrided in the nodes help info.

Thank you so much! It worked!
Thank you also for the flow example, I wouldn't have been able to create the correct node-red flow.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.