Sonoff Tasmota Tips & Tricks

Sonoff Tasmota Tips & Tricks

This page is under development. Stay tuned for more Sonoff Tasmota Tips & Tricks.


Ghost / Random Switching on Sonoff Devices (MQTT Retained):

If you are experiencing Ghost Switching i.e. A device goes ON / OFF by itself, which is a terrible experience if happens during a mid night!!, then you at correct place to fix this terrible issue.

All of the communication between your Raspberry Pi Server and Sonoff devices running Tasmota firmware, is done through MQTT. If you have not configured your MQTT settings correctly then you might be facing terrible issues including random switching or ghost switching. If you have published a payload with retained flag over your MQTT network on a specific topic then each time your device will connect to your MQTT network, that retained message will be sent to the device who subscribed for that particular topic. So let’s correct it by closing all the back holes to Ghost’s entry 😉

a) Sonoff Tasmota Configuration:

Open up your  Sonoff Tasmota device IP address in your favourite browser and navigate to Console. Input the following commands in console followed by Enter Key.

SwitchRetain Off
ButtonRetain On
ButtonRetain Off

Now make sure that you have correct PowerOnState. By default PowerOnState is set to 3 which mean it turns to last know power state after boot. You can also change it by issuing the PowerOnState 3 command in Console. You can also use the command below to fire all above mentioned commands at once.

backlog SwitchRetain Off; ButtonRetain On; ButtonRetain Off; PowerOnState 3; PowerRetain On

b) Delete all previously retained MQTT messages:

After configuring the Sonoff Tasmota correctly as discussed above, delete all previously retained messages in to Mosquitto broker database to fix the problem completely. Open up the PuTTY, connect to your Raspberry Pi via SSH and fire the commands given below.

sudo systemctl stop mosquitto.service
sudo rm /var/lib/mosquitto/mosquitto.db
sudo systemctl start mosquitto.service

Above commands will stop the Mosquitto service, delete the Mosquitto database and start the Mosquitto service once again. Now do not use any Retain Flag with any of MQTT related stuff to avoid Ghost / Random switching.

Incorrect Switch State on Home Assistant / Domoticz:

Another common issue is wrong switch state on being reported on dashboard such as device is ON while it is being reported as OFF on your dashboard. It happens especially when your dashboard is restarted. Here is a quick fix to this problem. Change the PowerRetain to On by issuing the PowerRetain On command in Tasmota Console. Now your Dashboard will receive the last retained message of a switch state immediate after restart.

Re-pair IFAN-02 Remote:

  • Take off the battery lid situated on back side of the remote.
  • Remove the battery.
  • Open the remote case by screw driver from front.


  • Find a button on back side of remote PCB and push it once.
  • Led present on the front of remote will start blinking.
  • Power cycle or Switch off the IFAN-02, wait a few seconds and switch it back on.
  • Now remote will get paired with Sonoff IFAN-02.
  • Re-join the lids, insert battery and fix the battery cover in place.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x