After new firmware upgrade, my Sonoff basic is switched on by itself automatically. Not sure why. The following is the config.
platform: mqtt
name: "Home Theater Switch"
state_topic: "stat/hometheater/POWER1"
command_topic: "cmnd/hometheater/POWER"
availability_topic: "tele/hometheater/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: true
Log from console:
03:22:21 DNS: Initialized
03:22:21 MQT: Attempting connection...
03:22:21 MQT: Connected
03:22:21 MQT: tele/hometheater/LWT = Online (retained)
03:22:21 MQT: cmnd/hometheater/POWER =
03:22:21 MQT: stat/hometheater/RESULT = {"POWER1":"ON"}
03:22:21 MQT: stat/hometheater/POWER1 = ON
Hi. Can you share the status 0 output and also the console output when this behaviour occurs?
03:25:46 MQT: stat/hometheater/STATUS = {"Status":{"Module":1,"FriendlyName":["Sonoff"],"Topic":"hometheater","ButtonTopic":"0","Power":1,"PowerOnState":3,"LedState":1,"SaveData":1,"SaveState":1,"ButtonRetain":0,"PowerRetain":0}}
03:25:46 MQT: stat/hometheater/STATUS1 = {"StatusPRM":{"Baudrate":115200,"GroupTopic":"sonoffs","OtaUrl":"http://domus1:80/api/arduino/sonoff.ino.bin","RestartReason":"Exception","Uptime":"2T16:24:25","StartupUTC":"2018-07-08T10:01:21","Sleep":0,"BootCount":90,"SaveCount":247,"SaveAddress":"FA000"}}
03:25:46 MQT: stat/hometheater/STATUS2 = {"StatusFWR":{"Version":"6.1.0","BuildDateTime":"2018-07-06T21:01:47","Boot":31,"Core":"2_3_0","SDK":"1.5.3(aec24ac9)"}}
03:25:46 MQT: stat/hometheater/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"SysLog":0,"LogHost":"domus1","LogPort":514,"SSId":["Anuradha Sriram",""],"TelePeriod":300,"SetOption":["54000009","55818000"]}}
03:25:46 MQT: stat/hometheater/STATUS4 = {"StatusMEM":{"ProgramSize":535,"Free":468,"Heap":17,"ProgramFlashSize":1024,"FlashSize":1024,"FlashMode":3,"Features":["00000809","0FDAE794","0C000000","23B6179E","00000000"]}}
03:25:46 MQT: stat/hometheater/STATUS5 = {"StatusNET":{"Hostname":"hometheater-7742","IPAddress":"192.168.1.124","Gateway":"192.168.1.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.1.108","Mac":"5C:CF:7F:A8:7E:3E","Webserver":2,"WifiConfig":2}}
03:25:46 MQT: stat/hometheater/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.1.114","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_A87E3E","MqttUser":"hass","MqttType":1,"MAX_PACKET_SIZE":1000,"KEEPALIVE":15}}
03:25:46 MQT: stat/hometheater/STATUS7 = {"StatusTIM":{"UTC":"Wed Jul 11 02:25:46 2018","Local":"Wed Jul 11 03:25:46 2018","StartDST":"Sun Mar 25 02:00:00 2018","EndDST":"Sun Oct 28 03:00:00 2018","Timezone":1,"Sunrise":"04:59","Sunset":"20:52"}}
03:25:46 MQT: stat/hometheater/STATUS10 = {"StatusSNS":{"Time":"2018-07-11T03:25:46"}}
03:25:46 MQT: stat/hometheater/STATUS11 = {"StatusSTS":{"Time":"2018-07-11T03:25:46","Uptime":"2T16:24:25","Vcc":3.199,"POWER1":"ON","Wifi":{"AP":1,"SSId":"Anuradha Sriram","RSSI":100,"APMac":"E8:DE:27:FB:F0:5A"}}}
Hi.
Thanks.
Your config seems ok.
How often is this turn on occurs?
For your console output it is received the command from a mqtt server.
Are you using Mosquitto or the embedded mqtt server of HA?
Please, Try retain false in you HA config
The switch on is random and am using HA. Before upgrade the retain flag was true and it never switched on automatically. After upgrade, I have changed to false, it got switched on automatically, so I thought because of retain flag and I have changed back to true.
Changed to false and will wait for a day.
Once you have set retain to true, you will have a retained message stored in your broker. Restarting the broker does not clear the retained message. Depending on the state stored in the retained message you might get undesired results of your device reconnects to the broker.
I had exactly the same problem with Sonoff Touch when using retain: true in HA. Setting retain to false fixed all issues for me.
Still the same issue, it keep on switching, on its own even after changed to false.
The 'Restart Reason' output from 'status 0' says Exception, is that something related with this?
You HAVE to DELETE any retained messages or they will still be retained (which is the design intent of a retained message 馃榾).
The exception is generally a problem, and that causes the device to restart. When the device restarts, it connects to the MQTT broker. It subscribes to the cmnd topic. If there is a retained message, it gets it. If the message says to Toggle, that is what the device will do, even if you have the device configured to remember the last state.
If you have configured the device to start at a particular state, say off, if it restarts with the load on, when it restarts, it will turn the load off.
There are a couple of ways to delete retained messages. Search the issues and you will find the commands to use. Do that first and then provide the log showing the issue if it occurs again.
I just deleted the mosquitto.db and restarted the mosquitto service fixed the issue.
Great!!!!!
If your issue is solved, please close it. Thanks. :+1:
Most helpful comment
I just deleted the mosquitto.db and restarted the mosquitto service fixed the issue.