MQTT Turn some lights on when restart MQTT hub on homey


When I restart the MQTT Hub in homey, it will start a broadcast for the device.
But then it looks like home assistant somewhere powered on 3 off the lights… and every time the same lights…

Hope someone can help me with this.




The correct approach to implementing your MQTT integration from Homey is to make sure that the broker connection from Homey is posting retained topics to a broker that supports retained topics. The Homey inbuilt MQTT broker does not retain topics.

An often used workaround is that you use Last Will and Testament to trigger Homey into resending all the topics again (which assumes HA is online and listening)… I see you do this.

However this also triggers new payload received messages on every topic into HA and so it possibly updates it’s internal devices to match these ‘new’ states on MQTT. This can cause HA to change the state of real devices.

The real topic that is important here would be the command topic for each device (whatever that is, maybe .../device/set) and that could definitely cause state changes. When you restart MQTT what is present on this topic for a device that changes state in HA? These command topics should not be retained on the broker so this is a little bit contra indicatory - so they should be absent on the broker when it restarts.

Can I just check where the real physical device is being controlled? Is this a Homey device being exposed to HA via MQTT or an HA device being exposed to Homey?

Homey controlled the devices.
The broker is not on Homey but the home assistant…

When the lights are off in homey and home assistant… still happened?

That’s good,

Can you show me what is in the command topic ( .../set ) for a device that is changing state upon restart and when that value was last updated (compared to when it changed state)


This is a picture from now… but I tested it a bit now but now the lights still off after the hub restart…

Only thing is I have a flow to restart every night the MQTT Hub in Homey, so all the device are still up and running to HA, this because after a time some devices lost the connection? But now I have make that it restart every night I can see in the HA logbook the light where turned on only, and in Homey it says MQTT turn it on… at this time…

I will make tomorrow some more test to send you te good command topic.

The light is off… you see on the onoff = false, but the set = true? This is strange I guess?

No - both of those screenshots are OK. The set topic holds the last command that was sent to the device which may not be the current state. It could have been set some time agao and the device could have had its state updated directly within Homey since. The onoff is the current state as Homey sees it.

Can you restart the MQTT Explorer connection to your broker and see if the set topic is still there… it shouldn’t be.

Also when you re-run MQTT Hub on Homey the /set topic should not get re-populated. If it does the device state will get updated to that value.

The set is gone…

Also set is not availble…

The only thing what is changed today is I make a update to the new OS 7.1?

Everything you’ve posted is good. But you’re saying that when you do restart MQTT Hub on Homey that three lights that are currently off consistently turn on ? Nothing should change the state of the physical light via MQTT unless it uses the .../set topic and the controller that uses/updates that topic in your setup is HA.

OS7.1 shouldn’t make any difference.

Yes a few night and begin afternoon also but at the moment can not simulate it any more… so will check ik tomorrow morning… and let you know…

1 Like

It looks like it works now… don’t know why…

Maybe you know a other thing:
I have the following sensor what will not show inside HA, other sensor (same type are in HA)
Do you have a idea how to get it in HA?