MQTT Automatic reconnect, force publishing

Hi,

first of all I am new to MQTT.

I integrated the new MQTT API (v1.4) into the Smart Home Software IP-Symcon (IPS) with success.

So IPS acts as a MQTT Server and subscribes to all topics the Smart Lock (SL) is publishing.
On the first provisioning and connection to IPS the SL publishes all topics and IPS retains them.
This will be also done if the SL restarts (plug battery off, plugin in battery again).
From there on the SL only publishes changes to IPS. I think that is the idea of MQTT.
So far, so good.

Now it cloud happen that the IPS MQTT Server is down for any reason.
So the SL can’t publish his topics/changes.
Also in the app the connection is marked as disconnected.

So is there an automatic reconnect from the SL to IPS?

Can I force the SL to publish all topics again without restarting the SL?

Looking forward for any hint.

Regards
Uli

1 Like

The Smart Lock makes a reconnect trial once per hour or when its own WIFI connectivity drops. All topics will be republished upon reconnect. i.e. just wait and everything should come back.

1 Like

Hi Jürgen,

thank you for sharing this information:

I already could see the reconnect in my test environment.
Publishing all topics again I have to check.

Uli

Scenario:

WLAN is all the time active and available.

MQTT Server switched to offline.
Smart Lock recognizes that the MQTT Server connection is offline.
MQTT Server switched on after several minutes.
Smart Look did a reconnect and publishes topics.

So, I can see the reconnect.

These topics were published again:

Home Assistant Config:

homeassistant/lock/nuki_12ABCD34_lock/config
homeassistant/binary_sensor/nuki_12ABCD34_lock/config
homeassistant/sensor/nuki_12ABCD34_battery_percent/config
homeassistant/binary_sensor/nuki_12ABCD34_lock_battery_critical/config
homeassistant/binary_sensor/nuki_12ABCD34_battery_charging/config
homeassistant/binary_sensor/nuki_12ABCD34_door_sensor/config
homeassistant/binary_sensor/nuki_12ABCD34_door_sensor_battery_critical/config
homeassistant/binary_sensor/nuki_12ABCD34_keypad_battery_critical/config
homeassistant/button/nuki_12ABCD34_unlatch_button/config
homeassistant/button/nuki_12ABCD34_lockngo_button/config
homeassistant/button/nuki_12ABCD34_lock_n_go_unlatch/config

It’s okay but I don’t need them, because I am not using HA.

The device state topics:

nuki/12ABCD34/connected
nuki/12ABCD34/unlock
nuki/12ABCD34/doorsensorState
nuki/12ABCD34/timestamp

These are not all all topics…

What’s about:

mode
state
batteryCritical
batteryChargeState
etc...

At the moment I have a dump file from my MQTT Server. So I can provide it via PN if needed.

On a restart of the SL all topics are published.

Uli

1 Like

@Juergen

What else can I check?

Still not all topics are republished on a reconnect.

Uli

Hi to all.
3 days ago i bought my First smart lock, nuki 3.0 pro.
I have a Raspberry with home assistant and a broker mqtt (mosquitto).
All works fine but… If i reboot my Raspberry (for any reason, for example After an update), the nuki lose the mqtt connection and i have to reconfigure It from nuki app. Is there a way to get automatic reconnect? Maybe it happens automatically after a long time?
Thanks

Yes.
If I remember correctly, 1 hour max.

This is correct. But in my case not all topics are updated.

Uli

Thank you man, I tried: in effect after about 40/45 minutes mqtt gets reconnect. Ok I feared to have an issue

Are all topics updated?

It seems yes. Status of lock, battery % and binary sensore " battery in charge ".

Hi my Nuki is loosing connection after some time to mqtt server. Sometimes after whole home assistant stack restart, but in my opinion it happens just sporadically. any hints how to solve?

1 Like

If you also restart your mqtt server it can take up to 1h until the Smart Lock reconnects.

The WiFi reconnect scheme is connected to the connection to the Nuki servers. i.e. you might see connects & disconnects if your internet goes up&down. If you just wait it should reconnect.

@Juergen thanks for your reply.
Unfortunately it does not reconnect. It even lost connection yday without any restart on HA stack. Nuki reconnects only if I go into the App → Funktionen und Konfiguration → MQTT → Tap on already configured MQTT server (with green mark) → Sichern (Save) without any change.

After the tap Nuki reconnects immediatly and the status and controls are visible/usable in Home Assistant again.

4 Likes

The problem might not be the connection but that not all services are republished upon every reconnect, especially the retained HA config topics.

When the problem occurs again, please connect with a desktop MQTT client to your MQTT server and check which topics you see for your Nuki lock. Most likely they are not the same than the ones you see when you connect right now, when everything is ok.

thanks Jürgen, will observe and post a screenshot/data, once I notice lost of connection again.

Best regards,

Nikolai

same problem here after a lost connection to my Matt server because of a reboot. these are the republished topics in my case (way to less topics):

Bildschirmfoto 2023-07-17 um 07.31.48

another problem: the reconnect itself is way too long… what if my mitt server reboots when I am not at home, and I return lets say 30 minutes after a reboot. the Nuki Lock will reconnect in 60minutes (as far as I understand), so its not reconnected when coming home and I cannot open my door :frowning:
any ideas how to handle that?

1 Like

Hi @Juergen , unfortunately I have still issues with auto-reconnecting to MQTT server. Nuki lock does not reconnect even after few hours. The problem is that Nuki app or maybe the lock itself does not remember mqtt password (only the user does). So after trying to re-connect it uses blank password. My MQTT setup is without anonymous allowed and every service integrated to mosquitto server has own user and pw.

1 Like

If i got you correct the MQTT connect is done with a user but with a blank password. Is that correct?

If the Smart Lock is in such a state and you repower it, does it instantly connect with username & pw?

Good morning @Juergen
I tried to repower the unit and it seems working great in that case
MQTT server log:

Blockquote
2023-09-14 06:39:16: Client SL3P_3709CD64 already connected, closing old connection.
2023-09-14 06:39:16: New client connected from 192.168.4.94:52433 as SL3P_3709CD64 (p2, c1, k300, u’nuki’).
2023-09-14 06:39:56: Saving in-memory database to mosquitto.db.

But if we lost connection to MQTT server in another scenario (restarting MQTT docker or whole NAS server) the Nuki does not reconnect automatically.
My assumption is that the Nuki is set correctly when the power is lost and it does what it is supposed to do. But if only the connectivity between the lock and the MQTT server is lost, then Nuki does not try to connect with the mqtt username and mqtt password which was set.

1 Like