How to display update for Shelly Devices

Hello,
i want to announce / display at OH2 if a Firmware update for the Shelly devices is aviable. All Shellys that connected to the broker report by the MQTT publish shellies/command/ announce a json formatted answer like this:
shellies/<shellymodel>-<deviceid>/announce

{
“id” : “shellyswitch25-xxxx”,
“model” : “SHSW-25”,
“mac” : “xxxxxxxx”,
“ip” : “192.1xx.xxx.xxx”,
“new_fw” : true,
“fw_ver” : “20200827-065456/v1.8.3@4a8bc427”
}"

{
“id” : “shellyplug-s-xxxx”,
“model” : “SHPLG-S”,
“mac” : “xxxx”,
“ip” : “192.1xx.xxx.xxx”,
“new_fw” : false,
“fw_ver” : “20201124-092310/v1.9.0@57ac4ad8”
}`

The problem is that all of the devices respond almost simultaneously.
Is it possible to summarize the JSON answers in groups sorted by the model and to generate an output for the individual model groups?

Maybe someone has an idea

Thanks
André

You have tagged this post with mqtt - is that what you’re using to communicate with these Shelly devices, and not the binding?

If you’re using MQTT, why not add a new Channel to each device Thing, and those Channels subscribe to the respective announce topic?

For example, you presumably already have a device Thing for your shellyswitch25-xxxx - install the JSONPATH Transformation Service if you don’t have it already, and add the following Channel:

Type switch:new_fw "New firmware available" [
    stateTopic="shellies/SHSW-25-shellyswitch25-xxxx/announce",
    transformationPattern ="JSONPATH:$.new_fw",
    on="true",
    off="false"
]

Obviously, adjust the topic to suite - I only copied and pasted the id and model from your JSON extracts.

For the next device, the Channel could be:

Type switch:new_fw "New firmware available" [
    stateTopic="shellies/SHPLG-S-shellyplug-s-xxxx/announce",
    transformationPattern ="JSONPATH:$.new_fw",
    on="true",
    off="false"
]

Or have I misunderstood the problem?

Hi,
All my Shellies are connected via MQTT.
Yes that’s the way how i´m evaluating it at the moment. I toke one Device and look at the FW JSON-pattern.

But if the Shelly i´m evaluating is not online, like a unplugged plug-s there is no respond.

Or must i display each channel of a shelly thing to check if there is an FW update aviable?

I thought it might be possible to make a kind of group channel for each model. That display that a update for the SHPLG-S or SHSW-25 model is aviable…

It does not matter if you use the binding or MQTT, if the device is not online (connected to the network), there can’t be any indication of an available firmware update. These checks run inside the shelly devices…

Ah, I think I see what you mean now, and I think I also understand this from your first post:

So, for a device model, such as the SHSW-25:

  • You have more than 1 of these devices
  • You want to display a single Item which tells you whether firmware is available for that particular model

Is that correct?

If so, you will still need a Channel for each device Thing, but you can use a Group Item to collect them all together. For example, let’s say you have the Items:

Switch sSHSW-25-001_new_fw "SHSW-25 Device 1" (gSHSW-25_new_fw) {channel="mqtt:.... "}
Switch sSHSW-25-002_new_fw "SHSW-25 Device 2" (gSHSW-25_new_fw) {channel="mqtt:.... "}
Switch sSHSW-25-003_new_fw "SHSW-25 Device 3" (gSHSW-25_new_fw) {channel="mqtt:.... "}

So we have three SHSW-25 devices, with the Channels I created previously, and they’re all part of the Group Item gSHSW-25_new_fw. Now, we can define the Group Item:

Group:Switch:OR(ON,OFF) gSHSW-25_new_fw

What this means is that the group gSHSW-25_new_fw will be ON if any of its members is ON. In other words, if any of the Shelly devices has a “new_fw” : true response, the Group will switch ON. More Group magic in the docs.

Does that get you closer?

Yes i think it looks nice and i will give your idea a try.

thanks

OoopsI made a mistake in the explanation. :woozy_face:

I made a Thing:

Thing topic ShellyUpdate {
Type string : fw_update “FW Update” [ stateTopic =“shellies/announce”, transformationPattern=“JSONPATH:$.new_fw”]
}

And a Item:

//Shelly update info
String shelly_fw_update “FW update vorhanden: [%s]” { channel=“mqtt:topic:hubschraube:ShellyUpdate:fw_update” }`

I Publish via MQTT FX:

shellies/command
payload: announce

all the shellies respond :

Can I evaluate this number of JSON responds too?

Not sure I understand what’s going on here: is every device publishing a message to exactly the same topic, at the same time? What is that topic? shellies/announce/#?

I think they do.
/# is a wildcard in MQTT FX to get all responds under this topic.

i hope i´m right

So what topic is each individual device actually pushing a message to? Is there an extra level under shellies/announce/?

No there is no level under this topic.
I think this is to check which shelly devices is online at the network. Like a call in the room and everybody who hear it answer who he is.

OK, so if that’s the case, then you can do the following.

Adjust the Channel from my first example to the following. You will need one of these Channels in each of your device Things. Also install the REGEX Transformation Service.

Type switch:new_fw "New firmware available" [
    stateTopic="shellies/announce",
    transformationPattern ="REGEX:(.*shellyswitch25-xxxx.*)∩JSONPATH:$.new_fw",
    on="true",
    off="false"
]

The shellyswitch25-xxxx is the id of your device, so you need to change this to the correct one for each device Thing.

What this does is use REGEX to scan the entire JSON string for the string shellyswitch25-xxxx. If that string is found (as part of the id key/value pair), the transformation moves on to the JSONPATH, and will extract the new_fw value. If the string is not found then the message is ignored by this Channel.

Once that’s done, you can continue with the Group Item idea!

Now i’m curious… it is possible too and make a list of the id of the devices that respond on this topic?

shellies/announce/

Maybe, but you’d have to use rules which:

  • Trigger everytime something is published to shellies/announce/
  • Process the incoming JSON to extract the id
  • Save those id's somewhere
  • ?

That’s quite a bit more involved than the original query though!

Ok Thanks this is enough input at this evening and i will try somethings by my self.

thanks
andré