Report Shelly Status over MQTT periodically every minute incl. IP Address

When using the original Shelly firmware for Shelly Gen2 and Gen3 devices you may want to add a Shelly script which reports the complete Shelly status including current IP address once per minute over MQTT. The script that does this is the following:

let ipAddress = null;

function handleGetStatusResponse(result) {
  ipAddress = result;
}

function publishIpAddress() {
  let status = {
    operational: true
  };
  Shelly.call("Shelly.GetStatus", null, handleGetStatusResponse);
  if (ipAddress !== null) {
    MQTT.publish("bridge/fabde/wifi/m27ttxofficelightswitch/deviceinfo", JSON.stringify(ipAddress), 0, false);
  }
  else 
  {
    MQTT.publish("bridge/fabde/wifi/m27ttxofficelightswitch/heartbeat", JSON.stringify(status), 0, false);
  }
}

let notifyTimer = Timer.set(
   60000,
   true,
   function() {
     publishIpAddress();
   }
 )
1 Like

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