Triggered by a post by @Spaceman_Spiff, I thought it was finally time to tackle this MQTT stuff. After some searching, I was able to get the “MQTT Explorer” working:
According to your screen shot, shellies/shellyflood/online is true not ONLINE. payloadAvailable needs to be true and payloadNotAvailable needs to be false.
Furthermore, the message published there needs to be retained. I can’t tell from the screenshot if it is or not. Usually it is. Otherwise, OH would have to be online and able to receive the true message when the Shelly happened to come online on. Otherwise, it gets no message at all and assumes the shelly is offline.
Aha. I actually was thinking in that direction, but since it’s the same device, I expected @Spaceman_Spiff’s configuration to work. I should have tested it, or course…
I didn’t know what that meant, but your explanation makes it clear. I assume it’s the checkbox on the Shelly GUI?
The device publishes to online when it’s online and ready to receive commands / settings. This is only a couple of seconds so your thing will be mostly offline and of not much help for you.
I have a rule that tracks the wakeup and publishes to another topic if the device reported online in the last 24 or 48 hours.
I edited the topic to match the original one but forgot that I must have changed the online message, too.
So for your case you can
either implement the same rule and use it in the thing config
use the expire binding e.g. on the battery level to track if the device is online and not use the online state in the thing config
Retain means that all messages are “cached” by the mqtt broker, so you get them directly after you connect to it.
For stateful topics (e.g. online/offline topic) this is sometimes nice to have, however the danger is always that you get old values which are no longer correct.
However in your case this will not change anything.
You can change the retain flag in the shelly GUI.
The device sleeps a lot because it’s a battery device.
Once a day it wakes up. Then it sends “true” on the online topic.
After a couple of seconds it sends “false” and goes back to sleep.
If you use the online topic for your thing status the thing will be “OFFLINE” all day and then change to “ONLINE” for only a couple of seconds.
That’s of no use for you because you probably want to see if the Shelly Flood is online which means it’s reporting values once a day.
My rule listens to the online topic and when the device reports “true” it publishes “ONLINE”.
It also starts a countdown so it will report “OFFLINE” after 48h of no “true”.
Since I use the topic of the rule for the thing status, I now see the thing as online even though it’s currently sleeping.
It’s not required to use the online/offline topic for the thing.
Then the thing will always be online.
The simple way to check if it still works would be to use expire with e.g. 48h on the battery level.
Expire is no add on but a core functionality in OH4.
It’s still there, check the docs for expire.
I think you can answer that yourself:
If you start openHAB what state will the device have - online “true” or “false” or “don’t know”?
I’m using HABApp and the rule does a little bit more, pushover notifications and logging.
So it might not be what you are looking for. If you are still interested I’m happy to share.
For a normal status topic with LWT configured, the status topic should never go stale. When the device comes online it publishes the online message to the status topic. When the device goes offline the broker publishes the offline message to the status topic.
But these battery powered Shelly devices don’t work like that that so @ErikDB another option is to just eliminate the availabilityTopic and payload properties entirely. Then the status of the MQTT Thing will follow the status of the MQTT broker. But of course you won’t know when/if the device ever does go offline in that case. But it’s a viable option, and for some bindings that’s typical behavior.