Hi,
while the shelly devices meanwhile do support MQTT I found it to be difficult to check which device is running which firmware version (and where an update is available). To be honest I don’t know if I don’t see the forest for the trees and if an easier solution is available, but for now this is how I addresses my problem.
I ran the tests with two different shelly devices.
- Shelly1 (named Shelly1_01)
- Shelly2 (named Shelly2_01).
things:
Bridge mqtt:broker:mosquitto "Mosquitto" [ host="localhost", port=1883, secure=false, username="openhabian", password="*****", clientID="openHAB" ] { Thing topic ShellyAnnounce "ShellyAnnounce" { Channels: Type string : announcestring "announcestring" [ stateTopic="shellies/announce" ] } Thing topic Shelly1-01 "Shelly1-01" { Channels: Type string : online "Online" [ stateTopic="shellies/shelly1-55521D/online" ] Type switch : power "Power" [ stateTopic="shellies/shelly1-55521D/relay/0", on="on", off="off", commandTopic="shellies/shelly1-55521D/relay/0/command", on="on", off="off"] } Thing topic Shelly2-01 "Shelly2-01" { Channels: Type string : online "Online" [ stateTopic="shellies/shellyswitch-5A4CE4/online" ] Type switch : power1 "Power1" [ stateTopic="shellies/shellyswitch-5A4CE4/relay/0", on="on", off="off", commandTopic="shellies/shellyswitch-5A4CE4/relay/0/command", on="on", off="off"] Type switch : power2 "Power2" [ stateTopic="shellies/shellyswitch-5A4CE4/relay/1", on="on", off="off", commandTopic="shellies/shellyswitch-5A4CE4/relay/1/command", on="on", off="off"] } }
items:
String ShellyAnnounce "Shelly Announce [%s]" { channel="mqtt:topic:mosquitto:ShellyAnnounce:announcestring" } Switch Shelly1_01_Switch "Shelly1_01 Power" [ "Switchable" ] { channel="mqtt:topic:mosquitto:Shelly1-01:power" } String Shelly1_01_Online "Shelly1_01 Online [%s]" { channel="mqtt:topic:mosquitto:Shelly1-01:online" } String Shelly1_01_IP "Shelly1_01 IP [%s]" String Shelly1_01_FWVer "Shelly1_01 FW Version [%s]" String Shelly1_01_NewFW "Shelly1_01 FW Update [%s]" Switch Shelly2_01_Switch1 "Shelly2_01 Power1" [ "Switchable" ] { channel="mqtt:topic:mosquitto:Shelly2-01:power1" } Switch Shelly2_01_Switch2 "Shelly2_01 Power2" [ "Switchable" ] { channel="mqtt:topic:mosquitto:Shelly2-01:power2" } String Shelly2_01_Online "Shelly2_01 Online [%s]" { channel="mqtt:topic:mosquitto:Shelly2-01:online" } String Shelly2_01_IP "Shelly2_01 IP [%s]" String Shelly2_01_FWVer "Shelly2_01 FW Version [%s]" String Shelly2_01_NewFW "Shelly2_01 FW Update [%s]"
rules (to enforce shellies publish their data every day at noon):
rule "ask for firmware version" when Channel 'astro:sun:local:noon#event' triggered START then val mqttActions = getActions("mqtt","mqtt:broker:mosquitto") //ask for shelly firmware data (sequentially every 5s) createTimer(now.plusSeconds(0), [ | mqttActions.publishMQTT("shellies/shellyswitch-5A4CE4/command","announce") ]) createTimer(now.plusSeconds(5), [ | mqttActions.publishMQTT("shellies/shelly1-55521D/command","announce") ]) end
rules (to extract data):
rule "get shelly announce data" when Item ShellyAnnounce received update then var String sID = transform("JSONPATH", "$.id", ShellyAnnounce.state.toString) var String sIP = transform("JSONPATH", "$.ip", ShellyAnnounce.state.toString) var String sFWVerFull = transform("JSONPATH", "$.fw_ver", ShellyAnnounce.state.toString) var String sFWVer = sFWVerFull.split("@").get(0).split("/").get(1) var String sNewFW = transform("JSONPATH", "$.new_fw", ShellyAnnounce.state.toString) var String myItem switch sID { case "shelly1-55521D": myItem = "Shelly1_01" case "shellyswitch-5A4CE4": myItem = "Shelly2_01" } postUpdate(myItem+"_FWVer",sFWVer) postUpdate(myItem+"_NewFW",sNewFW) postUpdate(myItem+"_IP",sIP) end
sitemap extract:
Frame label="Shelly FWs" { Text item=Shelly1_01_Online Text item=Shelly1_01_IP Text item=Shelly1_01_FWVer Text item=Shelly1_01_NewFW Text item=Shelly2_01_Online Text item=Shelly2_01_IP Text item=Shelly2_01_FWVer Text item=Shelly2_01_NewFW }
Result: