I’m using MQTT Hub on my Homey to control lights and other devices via an Android application i build using ‘Kodular’.
This is pretty much working allready. I can turn lights on and off with the app, but when the app starts up i want the app to check all the the device status so the device status in the app match the device status in real life from the beginning.
It must be possible because i used Home Assistant for a dashboard via MQTT and the status there was always up to date.
All device state messages are retained on the broker. So all messages should come in immediately when you subscribe to the device topics.
Thanx for your replay.
That’s what i thought. But no message comes in after i subscribe. Only after a status is altered a message comes in.
Could it be that I need to change settings in the MQTT hub, broker or client?
Does each device state appear as a unique topic?
I have one hub that sends each device update to the same topic, therefore overwriting the previous state for a device.
Also I’m not sure if the Qos level will affect it.
If you use an MQTT monitor, like MQTT Explorer, can you see the state of each device?
Each device has its own topic. Even multiple topics like: ‘/onoff’,’/dim’ and ‘/powerusage’
In MQTT Explorer everything is visible and clear. And only after altering one of the variables an update is send. Maybe there is a topic like /get or a payload like ? that responds with the current state without changing it.
Hmm, strange, so as Harrie says, as soon as you subscribe you should get any updates that have been missed.
I’m not sure if you would get any messages that you have already received before you disconnected if you connect using the same client ID.
Do you use an external broker or the Homey broker app?
I have tried disconnecting and reconnecting and unsubscribe and subscribing again. But still no messages.
I’m using this MQTT Broker by Menno van Grinsven in combination with MQTT Client and MQTT Hub
I don’t know if that is ‘the Homey broker app’.
@Dirk_D The Homey broker has known limitations in handling retained messages. I would recommend running an external broker (e.g. mosquitto).
An alternative approach can be to send a ‘birth message’. This will trigger a broadcast of the Hub. Not the ideal solution, but at least you’ll get the latest values.
Is it possible to install mosquito on Homey or should it be on a separate device?
Separate device, e.g. Synology NAS or raspberry pi.
I’ve put mosquito on a rpi and it works perfect.
So it’s the Homey Broker that doesn’t work.