Tasmota (MQTT) switches repeatedly marked as "unavailable"

I have a bunch of Sonoff / Tasmota switches in my house, all controlled via Home Assistant. Periodically through the day, they’ll get marked as “unavailable” and back to “available” again in the same minute (according to my logbook). Nothing appreciable has happened in that minute. The WiFi has not been interrupted, the Sonoffs have not rebooted, the HA instance has not lost its network connection.

Every once in a while, one will go unavailable and stay that way in HA, even though the device itself is still very much available. I can hit its local webserver and control it just fine. I can even use the HA dev MQTT service to send a command to it, which it receives and obeys, but the switch says it’s unavailable. I’m starting to think it’s something to do with my configuration.

All my switches behave the same way. Here’s a sample config for my MQTT sonoff tasmota devices:

  • name: downstairs_floor_lamp
    platform: mqtt
    state_topic: ‘stat/DownstairsFloorLamp/POWER’
    command_topic: ‘cmnd/DownstairsFloorLamp/POWER’
    availability_topic: ‘tele/DownstairsFloorLamp/LWT’
    qos: 1
    payload_on: ‘ON’
    payload_off: ‘OFF’
    payload_available: ‘Online’
    payload_not_available: ‘Offline’
    retain: true

Any ideas?

1 Like

If you monitor mqtt using :

mosquitto_sub -h localhost -u username -P password -v -t '#'

do you see anything unusual happening?

I guess I should have mentioned that I’m using an HA instance on an Ubuntu machine, and I’m using the builtin MQTT server. My MQTT configuration section consists of:

mqtt:
  embedded:

Thanks.

I think @cariboo’s question is still valid, no matter which broker you are using.

I agree, but I don’t know how to run a similar command with the embedded mqtt broker.

Come to think of it, I have 2 tp-link switches that exhibit the same behavior. That makes me think this isn’t even an mqtt issue. In my logbook screenshot above, “Living room ceiling light” and “dining room ceiling light” are tp-link switches, the rest are sonoff-tasmota.

For the record, it doesn’t matter which broker you are using, you can still use the mosquitto_sub command. By definition, all mqtt brokers use the same protocol.

hi,
did you ever got this figured out? My sonoffs also stay gray and unavailable.
thanks!
regards

I believe now that my problem was actually spotty wi-fi. I was just never able to catch it happening. It seems as though my tasmota devices were disconnecting and connecting again very quickly, but that was enough for HA to show them as “unavailable” and not correct itself.

I haven’t seen the problem in several months (and several versions).

Yes, I have this issue, and suspect that this is my issue too. It seems to be especially bad for devices which “hop” an internet connection wirelessly across a couple of devices.

I have the same problem, and the worst part is that, if I have a device turn on, it disconnect at 12:00, Home Assistant turn off at 12:05 and the device connect again at 12:10, the device not turn off, change the switch to turn on… And that can be a problem, example, a water valve…

I have “retain true”, but not works.

what version of tasmota are you running
i upgraded to 6.1.1 and have a similar issue.
downgraded back to 5.14 and all is well

I have 5.14.

I don’t know why fail.

I have 8 Sonoff’s in my house at the moment, all were working perfectly fine until two days ago, and then for 8 hours they were in and out of availability, and then back to normal. I had a car in my house for that time, that had a lot of LED’s in it, and I can only presume the LED’s were causing some kind of interference with my wifi, as I am running Ubiquiti/Unifi kit through my house it is usual 100% stable.

So my point is, if you are having problems, check your wifi signal, is it strong enough ? Is there any interference ?as this can cause the Sonoff’s to go offline.

I just started with tasmota 6.1.1 everywhere, sometimes switches become unavailible, I renamed all to lowercase and it helped for all except one, now it seems ok after HASS restart. I’m using embeded server. But I guess I will see issues again after something disconnectes from network etc. All my switchers are R2 and most of them don’t get “Today” power consumtions, 2 do, config is same for all, I checked 10 times. It is very confussing for me. Especially the startup automation scripts don’t make any sense to me. Nor from tasmota wiki, nor from HASS MQTT guide. Is there guide from someone experienced with this stuff and really stable working setup?
All switches do have 100% wifi signal. (all switches connect trough same unifi AP)
“Today” working for only 2 out of 5 five switches, all with the same config, is super confusing for me.

What do the console messages read?

If you are getting failure to connect to the broker messages (which is my guess) then this strongly suggests wifi issues.

(If you are getting spurious on/off messages then radio interference is where I’d look.)

No messages about MQTT errors in console, home assistant reads all the sensors (even todayenergy) from the switch, signal strength 100%, marks switch as unavailable. last two messages in console

22:29:04 MQT: tele/sonoff1/STATE = {“Time”:“2018-08-05T22:29:04”,“Uptime”:“0T03:35:21”,“Vcc”:3.183,“POWER”:“ON”,“Wifi”:{“AP”:1,“SSId”:"",“RSSI”:100,“APMac”:""}}
22:29:04 MQT: tele/sonoff1/SENSOR = {“Time”:“2018-08-05T22:29:04”,“ENERGY”:{“Total”:164.926,“Yesterday”:22.326,“Today”:14.034,“Period”:77,“Power”:930,“Factor”:0.98,“Voltage”:234,“Current”:4.080}}

similar message is written to console very 5 minutes

A toy car, I presume? If you are playing with a remote-controlled toy car, the controller is transmitting on 2.4GHz 100% of the time generating a lot of background noise for any nearby WiFi device. Such as Sonoff switches. If you have wireless phones, make sure it’s running on 5GHz for the same reason.

If your interfering device is really close to the Sonoff, it’s signal could be so strong that the Sonoff can’t here anything over WiFi. That’s called RF-desense. Even poorly-built PC’s can radiate harmonics all the way into the 2.4 GHz range.

RSSI measurement doesn’t differentiate from friendly or interfering signals. It just means that the chip is “hearing” a strong on-frequency signal. You would be surprised how much 2.4GHz ‘stuff’ is in the air.

What does the console log read when Home Assistant marks the sensor as unavailable?

The messages you posted here are “tele” telemetry messages which Tasmota posts every five mintes by default, and signify nothing but correct operation.

Nice easy starting set is to disconnect from the mains and then plug it in to a PC and watch the serial output (not sure if you can get it to serial output on the webconfig page of those, if it can watch that, and ping it at the same time)

I changed the config to lower case from

payload_available: 'Online'
payload_not_available: 'Offline'

to

payload_available: 'online'
payload_not_available: 'offline'

and now it works for me

1 Like