Nasty issue with Sonoff BN-SZ turns on by itself

Hi,

I have a nasty issue with a Sonoff BN-SZ ceilight light running tasmota that keeps turning itself on after becoming unavailable.

2018-07-21%2011_02_26-Window

The sonff is running tasmota 6.10 now, but with previous versions I had the same issue.

The light is configured as:

- platform: mqtt
  name: "Lamp logeerkamer"
  state_topic: "stat/sonoff-bn-z1-01/POWER1"
  command_topic: "cmnd/sonoff-bn-z1-01/POWER1"
  availability_topic: "tele/sonoff-bn-z1-01/LWT"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: false
  brightness_command_topic: "cmnd/sonoff-bn-z1-01/DIMMER"
  brightness_scale: 100
  brightness_state_topic: ā€œstat/sonoff-bn-z1-01/DIMMERā€

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.

Any suggestions?

Michel

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.

You can do this with mosquitto_pub using

$ mosquitto_pub -t 'cmnd/sonoff-bn-z1-01/POWER1' -nr

You may also need parameters for the host, password and user, depending on your setup.

Thanks. Iā€™ll try

When I enter:

 mosquitto_pub -h 127.0.0.1 -u hass -P ***** -t 'cmnd/sonoff-bn-z1-01/POWER1' -nr

I get: Error: Unknown option ā€˜-nrā€™.

Sorry, they are two options, I assumed you could combine them. Try

 mosquitto_pub -h 127.0.0.1 -u hass -P ***** -t 'cmnd/sonoff-bn-z1-01/POWER1' -n -r

Yes, that worked :slight_smile:

I will keep an eye on the logs and give some feedback here.

Thanks!

1 Like

Iā€™m afraid the problem still persists.

2018-07-21%2018_04_50-Home%20Assistant

logs:

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}'

Anything else I could try to debug or solve this?

Kind regards,

Michel

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.

If not, the sonoff is doing this itself.

Hi,

Iā€™m doing my very best to follow you :wink:

$ mosquitto_sub -u hass -P ********-t '#' -v
zigbee2mqtt/bridge/state online
tele/hass1/LWT Online
tele/sonoff-bn-z1-01/LWT Online
tele/sonoff_01/LWT Online
tele/sonoff-TV-boven/LWT Online
tele/sonoff-s20-pomp/LWT Online
state/doorbell/sound on
cmnd/sonoff-s20-pomp/POWER1 OFF
cmnd/sonoff-TV-boven/POWER OFF
cmnd/sonoff-bn-z1-01/DIMMER 9
cmnd/doorbell/sound on
cmnd/sonoff_01/POWER OFF
stat/sonoff-bn-z1-01/POWER1 OFF

Is this the one that shouldnā€™t be there?

cmnd/sonoff-bn-z1-01/DIMMER 9

I think so, if that causes the sonoff to turn on. You could test that by sending the message with mosquitto_pub

Sending:

mosquitto_pub -h 127.0.0.1 -u hass -P ******** -t cmnd/sonoff-bn-z1-01/DIMMER -m '9'

Results in:

cmnd/sonoff-bn-z1-01/DIMMER 9
stat/sonoff-bn-z1-01/RESULT {"POWER1":"ON","Dimmer":9}

Is this a command that is retained and should that be removed from the database now like:

mosquitto_pub -h 127.0.0.1 -u hass -P ******** -t ā€˜cmnd/sonoff-bn-z1-01/POWER1ā€™ -n -r

Yes, just like previously.