Shelly MQTT randomly showing offline

Hi there,

I have >10 Shelly 1PM Relays around the house. Sometimes a random 1PM goes unavailable in the HA UI, in the “shellies-gen2/shellyplus1pm-e465b8933630/online” topic in the MQTT broker I can see that it transitioned into false.
I can also see that it is still reporting in via MQTT on a frequent base:



The overall tree for this specific shelly during the time of an issue looks like this:

If I restart the Shelly via it’s web UI, it instantly reports back in. I’ve had this issue for a year now but never really debugged it but it’s getting annoying.
I am using the Shellies Discovery Script for Gen 2 devices.

Anyone got an idea what the issue might be or where to start searching? I do believe it is on homeassistant side as I can see the shelly still posting to the broker when the issue occurs.

I’m far from an expert in MQTT, but I seriously doubt it’s a homeassistant issue because of this:

HA is simply reporting the correct state, you your issue is either the device itself going offline, or else some issue with the discovery script.

Are you sure you set up the script correctly, including setting up the RPC status notifications over MQTT settings on the Shellies & the associated rpc automation at the bottom of the docs?

Yeah, the script is set up and configured correctly.
I’ve been using it for 3-4 years already, it is just random devices randomly going offline in Homeassistant. The devices are definitely online when the issue occurs, I still see them publishing data to the MQTT broker and I can also see them doing it in their individual log on the webinterface.

Shouldn’t the discovery script be no longer needed for existing devices even? I get that it is still probing them and having them report in, but they should technically still work in HA, even if the discovery stopped.

Just figured out, if I re-run the announcement script another two (!) times when the problem happened, it “fixes” the non reporting devices. Is there some cleanup interval configurable in HA where it would mark non-frequent discovered devices as inactive?