I have an automation that switches on the light when a motion sensor has been triggered, but that automation it not the trigger of the issue.
MQTT log:
2018-07-21 08:10:45 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zigbee2mqtt/0x00158d000230e696: b'{"battery":"100.00","voltage":3005}'
2018-07-21 08:14:29 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/sonoff-bn-z1-01/LWT: b'Offline'
2018-07-21 08:14:38 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/sonoff-bn-z1-01/LWT: b'Online'
2018-07-21 08:14:38 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/sonoff-bn-z1-01/POWER1: b'OFF'
2018-07-21 08:14:40 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/sonoff-bn-z1-01/POWER1: b'ON'
2018-07-21 08:47:43 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zigbee2mqtt/0x00158d0002334eec: b'{"battery":"100.00","voltage":3035,"water_leak":false}'
I have tried setting āPowerRetain 1ā in tasmota, but that does not seem to help.
Also in the MQTT configuration it tried setting retain: from ātrueā to āfalseā but that didnāt hep either.
The symptoms you have suggest that the command topic with a payload of ON has been sent with a retain flag true. This causes the broker to store the message in its database.
Whenever a client connects and subscribes to that topic, such as when the tasmota becomes available, the broker sends the retained message, so your lamp turns on.
This will stop sending the retained flag from HA, but does not clear the mosquitto database, so mosquitto will continue sending the retained message when a client connects.
To clear the message from the mosquitto database, you need to send a message with that topic and a null payload and the retain flag set.
2018-07-21 17:41:17 ERROR (MainThread) [homeassistant.core] Error doing job: Task was destroyed but it is pending!
2018-07-21 17:47:23 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/sonoff-bn-z1-01/LWT: b'Offline'
2018-07-21 17:47:25 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/sonoff-bn-z1-01/LWT: b'Online'
2018-07-21 17:47:26 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/sonoff-bn-z1-01/POWER1: b'ON'
2018-07-21 17:57:31 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zigbee2mqtt/0x00158d0001f43341: b'{"battery":"100.00","voltage":3042}'
I also noticed something suspicious in the mosquitto log:
1532083143: Saving in-memory database to /data/mosquitto.db.
1532084469: Client DVES_88FF11 has exceeded timeout, disconnecting.
1532084469: Socket error on client DVES_88FF11, disconnecting.
1532084475: New connection from 192.168.2.93 on port 1883.
1532084475: New client connected from 192.168.2.93 as DVES_88FF11 (c1, k15, u'hass').
The MQTT messages received seem to indicate that the sonoff is still receiving messages when it starts. First thing is to check that the retain message isnāt still in the database
mosquitto_sub -u hass -P ***** -t '#' -v
will immediately print a list topics that have the retained flag set. If your command topic is still there then something went wrong with the previous commands you entered.
If it is missing, then the message is coming from somewhere else, so leave the mosquitto_sub command running and turn off the sonoff. Wait till its unavailable on the HA screen and restart it. You should see the mqtt message being sent in the mosquitto_sub output.