MQTT switch periodically toggles when internet down

Hey Guys,
I have a mysteries issue. There is an MQTT switch, see the configuration below. It drives a wifi module to open a gate via Mosquitto broker. Both the MQTT broker and the Home Assistant running on a Synology NAS.

  • platform: mqtt
    name: “Kapunyitó”
    state_topic: “krk_home/server_unit/gate”
    command_topic: “krk_home/server_unit/gate/set”
    payload_on: “on”
    payload_off: “off”
    optimistic: false
    qos: 0
    retain: true

Everything works fine since a while, EXCEPT In case the internet is down, the MQTT switch changes state automatically, periodically in every 2-3min. Once the internet connection established again, it goes back to normal operation!!

I have several other switches implemented with the very same wifi module, those do not have this issue (MQTT config is the same)

I don’t have any sensor, switch or whatever that requires internet connection or tied in any form to internet connection status at all. So I’m clueless how I might can proceed further in debugging why this happens?

Do you have any idea?

Thanks!

What do the MQTT logs show?

turboc,
can you help me please how to turn that on (bit new to home assistant)? The log file doesn’t show anything meaningful for this regard.

Thx …krisztian

What are you using for your MQTT broker?

turboc,
I use Mosguitto, running on the same synology. If you were referring to capture the MQTT traffic between them, that is something I can do. I thought there are other log methodologies in HA to capture that.
Thx …krisztian

Nope, just looking to see what the traffic looks like between them. Also, by internet being down, you mean your ISP internet, not your in-house lan. Right…

Most likely an issue with the retain flag. Turn it off and I bet it goes away.

My garage would mysteriously go up and down in the middle of the night. Found out it was the retain flag on a few messages, the device reconnecting, and timing. Total PITA.

turboc,
understand, I will then capture the traffic. The main question to me really is who or what service initiate the transaction at all. That is correct, the wifi and the local LAN was running without issues, only the ISP was down.

forsquirel,
this is something I had concerns with as well. I will give it a try. Don’t recall if this need to be turned off at the broker side as well or it is only initiated by the client?

One other thing that I have to review as well. The wifi modules are Particle devices, so they connect to the cloud as well. I wrote the FW in a way they shouldn’t stop running in case of cloud connection error. I might have a bug on that side, however it should play only if it gets a trigger from the MQTT broker - which is a mystery which HA service initiate that in case the ISP is down…

I will play with the system next weekend and will report back if I figured out something.

Thanks for the help so far!

You should turn off from the client side, but you’ll need to make sure that all the retained messages are purged from the mqtt database.

forsquirel,
thanks for the hints, those solved my problem (especially reminding me on purging the actual retained messages).