Anyhow, the Smart Lock republishes everything to the MQTT server once it reconnects. This has to happen because it could have also been a server restart / crash and some servers do not retain all informations during a restart. Therefore the Smart Lock needs to republish everything in order to make sure that the server is up to date.
What you say seems fine to me, but there should not be a change of state, I do not see necessary to send an “off” and an “on”, only the current state. With the two messages you are causing home automation actions to be triggered when there really has been no change in state.
Have a look at the MQTT spec. The /connected topic carries a last will message which will be sent out by the MQTT broker automatically:
Indicates if the device is currently
connected to the MQTT server or not.
Uses “false” as the last will message,
which will be set by the mqtt server
automatically if the device disconnects.
Ok, I understand, but I have many devices connected via MQTT in my house, the only device that changes its status from off to on when it loses the signal is the Smart Lock.
One thing is the status of the connection and another is the status of the smart lock.