Autodiscover and manage all your Tasmota devices
This flow makes an auto-discovery of all Tasmota devices on the LAN, fills a table and let you manage the devices (by opening the WebUI or deleting it from the broker).
Instructions:
- Import the flow
- Set your MQTT broker in all mqtt-in or -out nodes
- Set your proper "store" for context variables (or it will save to default store, not recommended)
- Deploy
- Restart your Tasmota devices in order to get their LWT messages.
Once deployed, the flow will discover all devices. Go to the dashboard and click the "Refresh" icon (lower right corner) and it will fill the table.
From that moment on, the flow will keep your data always available (click Refresh if you need).
This is mine:
[{"id":"71408f882f871d4b","type":"group","z":"783effc661796605","name":"Devices","style":{"label":true},"nodes":["23a8f5181b58ecbb","5703c9a20c63c5f7","6ddd2847e99f200f","9837812836e4e7e9","041a6e8ea2424672","91efca0dcecbe235","ba7ba1a1326e2029","e4f520ca34058176","c8b88a200f3c0bb1","4106dab6a81b171d","41ce4ee23ad8a5c1","3bc0f91cc7ec03dc","38d3d2aeef3ee18b","2b05beaa20d0861b","c31784ccdb601ce8","3bf5c2b11d0420ad","a0547bbf0553d0ca","a2286eec1dd8f7d5"],"x":84,"y":129,"w":952,"h":425},{"id":"23a8f5181b58ecbb","type":"function","z":"783effc661796605","g":"71408f882f871d4b","name":"set label","func":"msg.value = msg.payload\nmsg.payload = \"<div style='text-align: center;'>You are going to remove<br><br><b >\" + msg.value +\"</b><br><br>Are you sure?</div>\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":360,"wires":[["5703c9a20c63c5f7"]]},{"id":"5703c9a20c63c5f7","type":"ui_toast","z":"783effc661796605","g":"71408f882f871d4b","position":"dialog","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"className":"","topic":"","name":"sure?","x":900,"y":360,"wires":[["6ddd2847e99f200f"]]},{"id":"6ddd2847e99f200f","type":"function","z":"783effc661796605","g":"71408f882f871d4b","name":"Confirm","func":"//only accept OK msg's\nif (msg.payload == 'OK') {\n msg.payload = msg.value;\n node.send(msg);\n}\nreturn null;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":413,"wires":[["9837812836e4e7e9"]]},{"id":"9837812836e4e7e9","type":"function","z":"783effc661796605","g":"71408f882f871d4b","name":"topic","func":"msg.topic = \"tele/\"+msg.payload+\"/LWT\"\nmsg.payload=\"\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":900,"y":413,"wires":[["041a6e8ea2424672"]]},{"id":"041a6e8ea2424672","type":"trigger","z":"783effc661796605","g":"71408f882f871d4b","name":"","op1":"","op2":"","op1type":"str","op2type":"pay","duration":"500","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":710,"y":473,"wires":[["91efca0dcecbe235"],["ba7ba1a1326e2029"]]},{"id":"91efca0dcecbe235","type":"mqtt out","z":"783effc661796605","g":"71408f882f871d4b","name":"del retained LWT","topic":"","qos":"","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"409a3a8.1a185c4","x":920,"y":466,"wires":[]},{"id":"ba7ba1a1326e2029","type":"change","z":"783effc661796605","g":"71408f882f871d4b","name":"del global obj","rules":[{"t":"delete","p":"#:(lilioStore)::devices[msg.value]","pt":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":513,"wires":[[]]},{"id":"e4f520ca34058176","type":"mqtt in","z":"783effc661796605","g":"71408f882f871d4b","name":"","topic":"tele/+/LWT","qos":"2","datatype":"auto","broker":"409a3a8.1a185c4","nl":false,"rap":true,"rh":0,"inputs":0,"x":180,"y":170,"wires":[["c8b88a200f3c0bb1"]]},{"id":"c8b88a200f3c0bb1","type":"function","z":"783effc661796605","g":"71408f882f871d4b","name":"Get all devices","func":"// get the global 'devices' object or initialize it if it doesn't exist\nlet devices = global.get('devices','lilioStore') || {}\n\n// get the device name from msg.topic\nlet device_name = msg.topic.split(\"/\")[1];\n\n// get this devices object or initialize it\nlet this_device = devices[device_name] ||{'status': \"Offline\"}\n\n// check the device status and set it in the object\nthis_device.status = msg.payload\n\n// update the 'devices' variable\ndevices[device_name] = this_device\n// update the 'devices' global\nglobal.set('devices', devices,'lilioStore')\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":170,"wires":[[]]},{"id":"4106dab6a81b171d","type":"mqtt in","z":"783effc661796605","g":"71408f882f871d4b","name":"","topic":"stat/+/STATUS0","qos":"2","datatype":"auto","broker":"409a3a8.1a185c4","nl":false,"rap":true,"rh":0,"inputs":0,"x":210,"y":230,"wires":[["41ce4ee23ad8a5c1"]]},{"id":"41ce4ee23ad8a5c1","type":"json","z":"783effc661796605","g":"71408f882f871d4b","name":"","property":"payload","action":"","pretty":false,"x":370,"y":230,"wires":[["3bc0f91cc7ec03dc"]]},{"id":"3bc0f91cc7ec03dc","type":"function","z":"783effc661796605","g":"71408f882f871d4b","name":"Update global","func":"devices = global.get(\"devices\",\"lilioStore\")\nlet this_device = msg.topic.split(\"/\")[1];\n\n//nome dispositivo\ndevices[this_device].name = msg.payload.Status.DeviceName \n\n\n// telemetria (secondi)\ndevices[this_device].teleperiod = msg.payload.StatusLOG.TelePeriod/60\n\n//Firmware\ndevices[this_device].fw = msg.payload.StatusFWR.Version\n\n//Uptime\ndevices[this_device].uptime = msg.payload.StatusPRM.Uptime\n\n//IP Address\ndevices[this_device].ip = msg.payload.StatusNET.IPAddress\n\n// WiFi\ndevices[this_device].ssid = msg.payload.StatusSTS.Wifi.SSId\ndevices[this_device].signal = msg.payload.StatusSTS.Wifi.RSSI\n\n// update the 'devices' global\nglobal.set('devices', devices,'lilioStore')\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":230,"wires":[[]]},{"id":"38d3d2aeef3ee18b","type":"ui_switch","z":"783effc661796605","g":"71408f882f871d4b","name":"Refresh","label":"{{msg.label}}","tooltip":"","group":"b3f61586ad63cd44","order":8,"width":"0","height":"0","passthru":false,"decouple":"false","topic":"","topicType":"str","style":"","onvalue":"true","onvalueType":"bool","onicon":"fa-refresh ","oncolor":"yellow","offvalue":"true","offvalueType":"bool","officon":"fa-refresh","offcolor":"yellow","animate":true,"className":"","x":170,"y":290,"wires":[["2b05beaa20d0861b"]]},{"id":"2b05beaa20d0861b","type":"trigger","z":"783effc661796605","g":"71408f882f871d4b","name":"","op1":"true","op2":"true","op1type":"bool","op2type":"bool","duration":"1","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":310,"y":290,"wires":[["c31784ccdb601ce8"],["a0547bbf0553d0ca"]]},{"id":"c31784ccdb601ce8","type":"function","z":"783effc661796605","g":"71408f882f871d4b","name":"Send status0 rqst","func":"devices = global.get(\"devices\",\"lilioStore\")\n// Clear all\nfor (var x in devices) {\n devices[x].ip =\"\"\n devices[x].signal=\"\"\n devices[x].ssid=\"\"\n devices[x].fw=\"\"\n devices[x].teleperiod=\"\"\n devices[x].uptime=\"\"\n}\n// update the 'devices' global\nglobal.set('devices', devices,'lilioStore')\n\n// Build status0 mqtt message\n\nfor (var z in devices) {\n msg.topic = \"cmnd/\"+z+\"/status0\"\n msg.payload=\"\"\n node.send(msg);\n \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":283,"wires":[["3bf5c2b11d0420ad"]]},{"id":"3bf5c2b11d0420ad","type":"mqtt out","z":"783effc661796605","g":"71408f882f871d4b","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"409a3a8.1a185c4","x":660,"y":283,"wires":[]},{"id":"a0547bbf0553d0ca","type":"change","z":"783effc661796605","g":"71408f882f871d4b","name":"get global","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(lilioStore)::devices","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":360,"wires":[["a2286eec1dd8f7d5"]]},{"id":"a2286eec1dd8f7d5","type":"ui_template","z":"783effc661796605","g":"71408f882f871d4b","group":"b3f61586ad63cd44","name":"custom table","order":1,"width":0,"height":0,"format":"\n<style>\n#devices {\n font-family: Arial, Helvetica, sans-serif;\n border-collapse: collapse;\n width: 100%;\n\n}\n\n#devices td, #devices th {\n border: 1px solid #ddd;\n padding: 8px;\n}\n\n\n#devices tr:nth-child(even){ background-color: #555;}\n\n#devices tr:hover {color: black;background-color: #ddd;}\n\n#devices th {\n padding-top: 12px;\n padding-bottom: 12px;\n text-align: left;\n background-color: #04AA6D;\n color: white;\n}\n\n.green {color:LawnGreen;}\n.red {color:red;}\n</style>\n\n<div style=\"height: 500px; overflow: auto;\">\n<table id=\"devices\">\n <tr style=\"font-size:smaller\">\n <th>Device Name</th>\n <th>MQTT topic</th>\n <th>IP Address</th>\n <th>WiFi AP</th>\n <th>Strength</th>\n <th>Telemetry</th>\n <th>Firmware</th>\n <th>Uptime</th>\n <th>Status</th>\n <th>Web UI</th>\n <th><i class=\"fa fa-remove\"></i></th>\n </tr>\n <tr ng-repeat=\"(k,v) in msg.payload\" \n style=\"font-size:smaller; border:1px dotted\">\n <td><b>{{v.name}}</b></td>\n <td>{{k}}</td>\n <td>{{v.ip}}</td>\n <td>{{v.ssid}}</td>\n <td>{{v.signal}}%</td>\n <td>{{v.teleperiod}} min.</td>\n <td>{{v.fw}}</td>\n <td>{{v.uptime}}</td>\n <td ng-class=\"{green: v.status=='Online', red: v.status=='Offline'}\">{{v.status}}</td>\n <td style=\"text-align:center\"><a href=\"http://{{v.ip}}\" target=\"_blank\" style=\"color:yellow\"><i class=\"fa fa-external-link\" aria-hidden=\"true\"></i></a></td>\n <td><a href=\"#\" ng-click=\"send({payload:k})\" style=\"color:lightgrey\"><i class=\"fa fa-trash\" aria-hidden=\"true\"></i></a></td>\n </tr>\n</table>\n</div>\n","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"","x":610,"y":360,"wires":[["23a8f5181b58ecbb"]]},{"id":"409a3a8.1a185c4","type":"mqtt-broker","name":"LilioMQTT","broker":"10.0.0.26","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"b3f61586ad63cd44","type":"ui_group","name":"Dispositivi","tab":"8baef7542f2ef651","order":1,"disp":false,"width":"20","collapse":false,"className":""},{"id":"8baef7542f2ef651","type":"ui_tab","name":"Dispositivi","icon":"dashboard","disabled":false,"hidden":false}]