MQTT keeps becoming unavailable


#1

I have 5 Sonoff devices operating via MQTT with mosquitto installed on the same server as Home Assistant. The devices connect okay and dont report any issues looking at the console output of the Sonoffs, however every few minutes a random device will change the unavailable and sometimes the switches fail to work. All the topics and user details must be right because periodically the switches work. I tried using cloudmqtt to see if it was my mosquitto install but this behaved exactly the same.
These had been working perfectly for a while but I migrated my install to a new machine and since then this has been happening.
I can ping the devices consistently with a timely reply so I personally don’t think its a Wi-Fi issue.
Does anyone have any suggestions?
I’m using version 0.84.6 and HA is installed as a virtual enviroment in ubuntu.


#2

Any errors in the mosquitto log?


#3

Nope not that I can see. They seem to connect fine to the MQTT server but HA cant seem to handle the requests…


#4

I would have thought that the unavailable state in HA was reached after the broker had lost connection with the sonoff and sent a will message, but if that were the case there would be disconnect and reconnect entries for the sonoffs in the mosquitto log.

I can’t think of any other way that it can reach the unavailable state. Can you post the configuration for one of the sonoffs?


#5

This is the log from the one which seems to behave the worst and has the most log events but it seems to connect okay?

20:30:42 MQT: Attempting connection...
20:30:42 MQT: Connected
20:30:42 MQT: tele/sonoff-001-outlight/LWT = Online (retained)
20:30:42 MQT: cmnd/sonoff-001-outlight/POWER = 
20:30:42 MQT: stat/sonoff-001-outlight/RESULT = {"POWER":"OFF"}
20:30:42 MQT: stat/sonoff-001-outlight/POWER = OFF (retained)
20:35:24 MQT: tele/sonoff-001-outlight/STATE = {"Time":"2019-01-03T20:35:24","Uptime":"0T01:43:01","Vcc":3.147,"POWER":"OFF","Wifi":{"AP":1,"SSId":"Poulter","RSSI":60,"APMac":"44:D9:E7:03:C7:C0"}}

the code for one of the Sonoff is also below:

  - platform: mqtt
    name: "Outside Lights"
    state_topic: "stat/sonoff-001-outlight/POWER"
    command_topic: "cmnd/sonoff-001-outlight/POWER"
    availability_topic: "tele/sonoff-001-outlight/LWT"
    qos: 1
    payload_on: “ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: true

#6

I realise this is becomming more of a mqtt issue and less HA but i tried adding a completely new device on (shelly1) and that doesn’t have any issues with becoming unavailable and is working great from what I can see so now I’m unsure why these other devices are doing this?

Any help would be really appreciated now.


#7

There have been some other posts suggesting that later versions of Tasmota have this characteristic. From your topics, I think you might be using this firmware, so I suggest you try an earlier version.


#8

Which sonoff devices are you using?

I’ve noticed that the 1st generation devices (Basic and S20) give my wireless access points a hard time with large numbers of tx/rx retries. The POW 2s don’t do this.

Though having said that they dont disconnect from my mqtt server.


#9

they are the sonoff basics mostly, I did have a a touch light switch, but swapped this out for a shelly1. I can ping them continuously even when they have the unavailable status. The sonoffs are on 6.4.1, do you know roughly how early I would need to go by any chance?
I can see them dropping off and on using the sub command but I am unsure where to find why they drop?


#10

6.2.1 has been very stable for me on the Basics. I tried 6.3.0 when it came out ahd half of them stopped responding. I had to pysically connect to them to re-flash them.


#11

Wow. I just updated all my POW 2, Basic and S23 Sonoffs to tasmota 6.4.1.

All of them experienced intermittent connectivity issues.

Went back to 6.2.1 and all have a stable connection again.

I have opened an issue with tasmota: https://github.com/arendst/Sonoff-Tasmota/issues/4896

Please add your experience to the issue if relevant.


#12

And the issue has been closed without actually addressing the problem.

Surprise sur-fucking-surprise.

Just use 6.2.1. It works.