Home Assistant Community

My lights keep turning on/off by itself (Tasmota + MQTT)


This is driving me nuts. I got a Sonoff T1 switches flashed with Tasmota. On v5 everything worked liked a charm for months. Few weeks ago I’ve decided to update to the newest version of Tasmota (huge huge mistake!) and now my lights are turning on and off by itself randomly.

I’m managed to pinpoint the problem and it seems that they reconnect to the Wifi every now and then (not sure why as the wifi signal is at 90+%), and on each reconnect they either get turned on or turned off (but not always). Here is the number of disconnects per hour from the last two days:

I can’t figure out why the number is inconsistent and varies between hours/days. Also the kitchen light is in close proximity to the access point (in plain sight, around 5m away).

Here is the log from the recent disconnects (the light was turned off on both times):

20:07:03 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:07:03","Uptime":"1T01:25:30","Vcc":3.478,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"ON","POWER2":"ON","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":92}}
20:12:03 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:12:03","Uptime":"1T01:30:30","Vcc":3.497,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"ON","POWER2":"ON","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":92}}
20:16:03 DNS: Initialized
20:16:04 MQT: Attempting connection...
20:16:04 MQT: Connected
20:16:04 MQT: light_kitchen/tele/LWT = Online (retained)
20:16:04 MQT: light_kitchen/cmnd/POWER = 
20:16:04 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:16:04","Uptime":"1T01:34:31","Vcc":3.476,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"ON","POWER2":"OFF","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":96}}
20:16:04 MQT: light_kitchen/stat/RESULT = {"POWER2":"OFF"}
20:16:04 MQT: light_kitchen/stat/POWER2 = OFF (retained)
20:16:04 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:16:04","Uptime":"1T01:34:31","Vcc":3.477,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":20,"POWER1":"OFF","POWER2":"OFF","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":96}}
20:16:04 MQT: light_kitchen/stat/RESULT = {"POWER1":"OFF"}
20:16:04 MQT: light_kitchen/stat/POWER1 = OFF (retained)
20:17:03 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:17:03","Uptime":"1T01:35:30","Vcc":3.496,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"OFF","POWER2":"OFF","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":96}}
20:19:53 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:19:53","Uptime":"1T01:38:20","Vcc":3.496,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"OFF","POWER2":"ON","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":94}}
20:19:53 MQT: light_kitchen/stat/RESULT = {"POWER2":"ON"}
20:19:53 MQT: light_kitchen/stat/POWER2 = ON (retained)
20:22:03 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:22:03","Uptime":"1T01:40:30","Vcc":3.496,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"OFF","POWER2":"ON","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":98}}
20:24:36 DNS: Initialized
20:24:37 MQT: Attempting connection...
20:24:37 MQT: Connected
20:24:37 MQT: light_kitchen/tele/LWT = Online (retained)
20:24:37 MQT: light_kitchen/cmnd/POWER = 
20:24:37 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:24:37","Uptime":"1T01:43:04","Vcc":3.477,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":21,"POWER1":"OFF","POWER2":"OFF","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":96}}
20:24:37 MQT: light_kitchen/stat/RESULT = {"POWER2":"OFF"}
20:24:37 MQT: light_kitchen/stat/POWER2 = OFF (retained)
20:24:37 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:24:37","Uptime":"1T01:43:04","Vcc":3.478,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":21,"POWER1":"OFF","POWER2":"OFF","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":96}}
20:24:37 MQT: light_kitchen/stat/RESULT = {"POWER1":"OFF"}
20:24:37 MQT: light_kitchen/stat/POWER1 = OFF (retained)
20:24:51 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:24:51","Uptime":"1T01:43:18","Vcc":3.496,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"OFF","POWER2":"ON","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":96}}
20:24:51 MQT: light_kitchen/stat/RESULT = {"POWER2":"ON"}
20:24:51 MQT: light_kitchen/stat/POWER2 = ON (retained)
20:27:03 MQT: light_kitchen/tele/STATE = {"Time":"2019-02-11T20:27:03","Uptime":"1T01:45:30","Vcc":3.496,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"OFF","POWER2":"ON","Wifi":{"AP":2,"SSId":"Cezex","BSSId":"FC:EC:DA:14:99:32","Channel":11,"RSSI":96}}

I have power retain turned off in HA config, and turned on in Tasmota:

- platform: mqtt
  name: "Kitchen"
  state_topic: "light_kitchen/stat/POWER1"
  command_topic: "light_kitchen/cmnd/POWER1"
  availability_topic: "light_kitchen/tele/LWT"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: false

Does anyone have any idea what I can check/change to fix it? I’m on the version with 2.5.0 core but I don’t see any improvement. My wife slowly looses her patience… To be fair me too, I had to turn off the light three times during the night today.



Hi! i have the same problem, Did you already fix the problem?



Yes, I did! It tuned out that it was not a problem with Tasmota firmware (I think), but rather with MQTT broker that was causing the WiFi disconnects in the Sonoffs.

This is what I’ve done:

  1. Updated the Tasmota firmware using 2.5.0 core (but I’m not sure if this is required)
  2. I’ve set the retain flag to false for all switches in the MQTT config in HA (this is important!)
  3. I’ve set the retain flag to true for all switches through the Tasmota web interface (PowerRetain 1)
  4. I’ve removed all retain messages in the HA database (this is very important!)
  5. I’ve restarted both HA and all the switches

To remove the retain flag in point 4 you will need a separate MQTT client, I’ve used MQTT Explorer. See post for details:

Hope that helps.