From 26ac0cc46800e73e059edede6456efe71d45890c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 26 Aug 2025 16:23:03 +0200 Subject: [PATCH] Add tool to show global state info in GUI - Can be used to find hostname and IP address of newly added devices. --- tasmota/berry/examples/statedata.be | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tasmota/berry/examples/statedata.be diff --git a/tasmota/berry/examples/statedata.be b/tasmota/berry/examples/statedata.be new file mode 100644 index 000000000..8d95b13cc --- /dev/null +++ b/tasmota/berry/examples/statedata.be @@ -0,0 +1,62 @@ +# Show hostname and IP address from MQTT STATE messages in GUI + +import mqtt +import string + +class mqttdata_cls + var list_buffer # Buffer storing lines + var line_cnt # Number of lines + + def init() + self.list_buffer = [] # Init line buffer list + self.line_cnt = 10 # Number of lines to show + + if global.mqttdata_driver + global.mqttdata_driver.stop() # Let previous instance bail out cleanly + end + tasmota.add_driver(global.mqttdata_driver := self) + + # Assume default Fulltopic (%prefix%/%topic%/) and Prefix3 (tele) + mqtt.subscribe("tele/#", /topic, idx, data, databytes -> self.handle_state_data(topic, idx, data, databytes)) + end + + def handle_state_data(full_topic, idx, data, databytes) + import json + + if string.find(full_topic, "STATE") > 0 # tele/wemos7/STATE + var subtopic = string.split(full_topic, "/") # Assume default Fulltopic (%prefix%/%topic%/) + var topic = subtopic[1] # wemos7 + + var line + var state = json.load(data) + if state + var uptime = state['Uptime'] + if state.find('Hostname') + var hostname = state['Hostname'] + var ipaddress = state['IPAddress'] + line = format("