MQTT Sonoff 4ch pro 1st channel turns ON after Mosquitto/Sonoff power reset

Setup:

Home Assistant 0.76.2
Mosquitto broker 2.0 (mosquitto version 1.4.15)
Sonoff 4ch Pro with Tasmota 6.2.1

Config:

S6 Sonoff switch: pos. 1
K5 Sonoff switches: pos. 1 for every channel

mqtt:
  broker: 192.168.1.149
  port: 1883
  client_id: home-assistant
  keepalive: 60
  username: user
  password: pass
  protocol: 3.1
  birth_message:
    topic: "tele/home/LWT"
    payload: "Online"
    qos: 2
    retain: true
  will_message:
    topic: "tele/home/LWT"
    payload: "Offline"
    qos: 2
    retain: true

light:
  - alias: Living Room
    platform: mqtt
    name: "Living Room"
    state_topic: "stat/home/light/POWER1"
    command_topic: "cmnd/home/light/POWER1"
    availability_topic: "tele/home/LWT"
    qos: 2
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false 
    
  - alias: Living Room 2nd light
    platform: mqtt
    name: "Living Room 2nd light"
    state_topic: "stat/home/light/POWER2"
    command_topic: "cmnd/home/light/POWER2"
    availability_topic: "tele/home/LWT"
    qos: 2
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false
    
  - alias: Hallway light
    platform: mqtt
    name: "Hallway light"
    state_topic: "stat/home/light/POWER3"
    command_topic: "cmnd/home/light/POWER3"
    availability_topic: "tele/home/LWT"
    qos: 2
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false
    
  - alias: Bathroom light
    platform: mqtt
    name: "Bathroom light"
    state_topic: "stat/home/light/POWER4"
    command_topic: "cmnd/home/light/POWER4"
    availability_topic: "tele/home/LWT"
    qos: 2
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

Issue description:

Every time I restart Mosquitto broker in Hassio or reset Sonoff module power - 1st channel enables regardless module config.

I bought some Sonoff modules and test them before overhaul in the apartment.
According to my plan, the relay must save its position after a power loss but this channel does not work on this logic - no matter how I turned it off, with a physical button or via web/mqtt, it still turns on after every reboot.

Some times ago I tried to use retain in hassio config for these relays but then disable them. I read I should try to remove retain messages via -r -n for the topics but it doesn’t help to solve the issue.

Here is the log from Tasmota web interface after reboot:

00:00:00 Project sonoff Sonoff (Topic light, Fallback sonoff_4ch_pro_1, GroupTopic sonoffs) Version 6.2.1-2_3_0
00:00:00 WIF: Connecting to AP1 Panch_2.4 in mode 11N as light-8131...
00:00:04 WIF: Connected
00:00:04 DNS: Initialized
00:00:04 HTP: Web server active on light-8131.local with IP address 192.168.1.105
00:00:04 MQT: Attempting connection...
00:00:04 MQT: Connected
00:00:04 MQT: tele/home/light/LWT = Online (retained)
00:00:04 MQT: cmnd/home/light/POWER = 
00:00:04 MQT: stat/home/light/RESULT = {"POWER1":"ON"}
00:00:04 MQT: stat/home/light/POWER1 = ON
00:00:04 MQT: tele/home/light/INFO1 = {"Module":"Sonoff 4CH Pro","Version":"6.2.1","FallbackTopic":"sonoff_4ch_pro_1","GroupTopic":"sonoffs"}
00:00:04 MQT: tele/home/light/INFO2 = {"WebServerMode":"Admin","Hostname":"light-8131","IPAddress":"192.168.1.105"}
00:00:04 MQT: tele/home/light/INFO3 = {"RestartReason":"Power on"}
00:00:05 MQT: stat/home/light/RESULT = {"POWER1":"ON"}
00:00:05 MQT: stat/home/light/POWER1 = ON
00:00:05 MQT: stat/home/light/RESULT = {"POWER2":"OFF"}
00:00:05 MQT: stat/home/light/POWER2 = OFF
00:00:05 MQT: stat/home/light/RESULT = {"POWER3":"OFF"}
00:00:05 MQT: stat/home/light/POWER3 = OFF
00:00:05 MQT: stat/home/light/RESULT = {"POWER4":"OFF"}
00:00:05 MQT: stat/home/light/POWER4 = OFF
00:00:05 MQT: homeassistant/light/light_1/config =  (retained)
00:00:05 MQT: homeassistant/switch/light_1/config = {"name":"Sonoff","command_topic":"cmnd/home/light/POWER1","state_topic":"stat/home/light/RESULT","value_template":"{{value_json.POWER1}}","payload_off":"OFF","payload_on":"ON","availability_topic":"tele/home/light/LWT","payload_available":"Online","payload_not_available":"Offline"} (retained)
00:00:05 MQT: homeassistant/light/light_2/config =  (retained)
00:00:05 MQT: homeassistant/switch/light_2/config = {"name":"Sonoff2","command_topic":"cmnd/home/light/POWER2","state_topic":"stat/home/light/RESULT","value_template":"{{value_json.POWER2}}","payload_off":"OFF","payload_on":"ON","availability_topic":"tele/home/light/LWT","payload_available":"Online","payload_not_available":"Offline"} (retained)
00:00:05 MQT: homeassistant/light/light_3/config =  (retained)
00:00:05 MQT: homeassistant/switch/light_3/config = {"name":"Sonoff3","command_topic":"cmnd/home/light/POWER3","state_topic":"stat/home/light/RESULT","value_template":"{{value_json.POWER3}}","payload_off":"OFF","payload_on":"ON","availability_topic":"tele/home/light/LWT","payload_available":"Online","payload_not_available":"Offline"} (retained)
00:00:05 MQT: homeassistant/light/light_4/config =  (retained)
00:00:05 MQT: homeassistant/switch/light_4/config = {"name":"Sonoff4","command_topic":"cmnd/home/light/POWER4","state_topic":"stat/home/light/RESULT","value_template":"{{value_json.POWER4}}","payload_off":"OFF","payload_on":"ON","availability_topic":"tele/home/light/LWT","payload_available":"Online","payload_not_available":"Offline"} (retained)
00:00:05 MQT: homeassistant/light/light_5/config =  (retained)
00:00:05 MQT: homeassistant/switch/light_5/config =  (retained)
00:00:05 MQT: homeassistant/light/light_6/config =  (retained)
00:00:05 MQT: homeassistant/switch/light_6/config =  (retained)
00:00:05 MQT: homeassistant/light/light_7/config =  (retained)
00:00:05 MQT: homeassistant/switch/light_7/config =  (retained)
00:00:05 MQT: homeassistant/light/light_8/config =  (retained)
00:00:05 MQT: homeassistant/switch/light_8/config =  (retained)
23:15:38 MQT: tele/home/light/STATE = {"Time":"2018-09-11T23:15:38","Uptime":"0T00:00:13","Vcc":3.222,"POWER1":"ON","POWER2":"OFF","POWER3":"OFF","POWER4":"OFF","Wifi":{"AP":1,"SSId":"Panch_2.4","RSSI":68,"APMac":"F4:F2:6D:AE:E2:45"}}

If I connect to broker via mqttspy and subscript to “#” topic it always shows cmnd topic for this relay with “ON” value even if it’s OFF and does not show such topics for other relays:

Also I found some info about deleting mosquitto.db but here is no such file or directory if I connect to my RPi with hassio via ssh with root user (looks like I should have permission connect to docker app with this module).

Thank you for any help!

This shows that at some point in the past, this message has been sent with the retain flag set. This causes the broker to store the message in its database, and send the message whenever a new client subscribes to that topic.

To clear only that message from the database, you can send a message with that topic, the retain flag set and a null payload.

With mosquitto_pub, you can do

mosquitto_pub -t "your topic" -r -n -u user -P pass -h host

You can also do it from the dev tools mqtt page, and I am sure you can do it from mqtt.fx but you will need to figure out how.

If you can find the db file, obviously deleting that will work, but it will also delete any other retained messages.

3 Likes

Thank you so much!

I have tried 3 days ago and issue is not repeated until now.

1 Like