MQTT problem

hi .
i have HA 0.75v with mosquitto broker on Ubuntu server 18.
i have a 10 sonoff device connect to my network . all work fine .
but when the mosquitto service restart , the turn off devices randomly . sometime he turn on some devices…
i can’t found the problem…
best regards…

The problem might be that when the mosquitto service restarts, all devices have to reconnect and therefore any topics with the retain flag set will be sent.

If you restart the sonoffs (without starting the broker), does each sonoff turn off/on consistently when there hasn’t been a command from HA?

If you connect another client to the broker and subscribe to all topics, what does it display? For instance

mosquitto_sub -t "#" -v

tele/Kitchen/LWT Offline-------------->" power off the devices , mosquitto service still running on network "
tele/ToharRoom/LWT Offline
tele/EnterLight/LWT Offline
tele/misdaron1/LWT Offline ---------> here i power up the devices
tele/misdaron1/LWT Online
tele/EnterLight/LWT Online
tele/Kitchen/LWT Online
tele/ToharRoom/LWT Online
cmnd/misdaron1/POWER (null)
cmnd/EnterLight/POWER (null)
stat/misdaron1/RESULT {“POWER”:“OFF”}
stat/misdaron1/POWER OFF
stat/EnterLight/RESULT {“POWER3”:“OFF”}
stat/EnterLight/POWER3 OFF
cmnd/Kitchen/POWER (null)
cmnd/ToharRoom/POWER (null)
tele/misdaron1/INFO1 {“Module”:“Sonoff T1 1CH”,“Version”:“6.1.1”,“FallbackTopic”:“misdaron_1”,“GroupTopic”:“mis_light”}
tele/EnterLight/INFO1 {“Module”:“Sonoff T1 3CH”,“Version”:“6.1.1”,“FallbackTopic”:“EnterDoor”,“GroupTopic”:“sonoffs”}
tele/EnterLight/INFO2 {“WebServerMode”:“Admin”,“Hostname”:“EnterDoor”,“IPAddress”:“192.168.0.71”}
tele/EnterLight/INFO3 {“RestartReason”:“Blocked Loop”}
stat/ToharRoom/RESULT {“POWER1”:“OFF”}

stat/Kitchen/RESULT {“POWER1”:“OFF”} ---->" before off all devices , this was on ON . why he decide to turn off him ???"

stat/ToharRoom/POWER1 OFF
stat/Kitchen/POWER1 OFF
stat/EnterLight/RESULT {“POWER1”:“ON”}
stat/EnterLight/POWER1 ON
tele/misdaron1/INFO2 {“WebServerMode”:“Admin”,“Hostname”:“Misdaron1”,“IPAddress”:“192.168.0.77”}
tele/misdaron1/INFO3 {“RestartReason”:“Power on”}
homeassistant/light/misdaron1_1/config (null)
tele/ToharRoom/INFO1 {“Module”:“Sonoff T1 2CH”,“Version”:“6.1.1”,“FallbackTopic”:“tohar_room”,“GroupTopic”:“sonoffs”}
homeassistant/switch/misdaron1_1/config {“name”:“Misdaron1”,“command_topic”:“cmnd/misdaron1/POWER”,“state_topic”:“stat/misdaron1/RESULT”,“value_template”:"{{value_json.POWER}}",“payload_off”:“OFF”,“payload_on”:“ON”,“availability_topic”:“tele/misdaron1/LWT”,“payload_available”:“Online”,“payload_not_available”:“Offline”}
tele/ToharRoom/INFO2 {“WebServerMode”:“Admin”,“Hostname”:“ToharRoom”,“IPAddress”:“192.168.0.73”}
tele/Kitchen/INFO1 {“Module”:“Sonoff T1 3CH”,“Version”:“6.1.1”,“FallbackTopic”:“KitchenLight”,“GroupTopic”:“sonoffs”}
tele/Kitchen/INFO2 {“WebServerMode”:“Admin”,“Hostname”:“Kitchen”,“IPAddress”:“192.168.0.70”}
tele/ToharRoom/INFO3 {“RestartReason”:“Power on”}
stat/ToharRoom/RESULT {“POWER2”:“OFF”}
tele/Kitchen/INFO3 {“RestartReason”:“Power on”}
stat/ToharRoom/POWER2 OFF
homeassistant/light/misdaron1_2/config (null)
stat/Kitchen/RESULT {“POWER2”:“ON”} — this was off !!!
homeassistant/switch/misdaron1_2/config (null)
stat/Kitchen/POWER2 ON
homeassistant/light/misdaron1_3/config (null)
stat/Kitchen/RESULT {“POWER3”:“ON”}
homeassistant/switch/misdaron1_3/config (null)
stat/Kitchen/POWER3 ON
homeassistant/light/misdaron1_4/config (null)
homeassistant/switch/misdaron1_4/config (null)
homeassistant/light/misdaron1_5/config (null)
homeassistant/switch/misdaron1_5/config (null)
homeassistant/light/misdaron1_6/config (null)
homeassistant/switch/misdaron1_6/config (null)
homeassistant/light/misdaron1_7/config (null)
homeassistant/switch/misdaron1_7/config (null)
homeassistant/light/misdaron1_8/config (null)
homeassistant/switch/misdaron1_8/config (null)
tele/MisdaronLights/LWT Online
cmnd/MisdaronLights/POWER (null)
stat/MisdaronLights/RESULT {“POWER1”:“OFF”}
stat/MisdaronLights/POWER1 OFF
tele/MisdaronLights/INFO1 {“Module”:“Sonoff T1 2CH”,“Version”:“6.1.1”,“FallbackTopic”:“misdaron_light”,“GroupTopic”:“mis_light”}
tele/MisdaronLights/INFO2 {“WebServerMode”:“Admin”,“Hostname”:“Misdaron”,“IPAddress”:“192.168.0.76”}
tele/MisdaronLights/INFO3 {“RestartReason”:“Blocked Loop”}
stat/EnterLight/RESULT {“POWER1”:“ON”}
stat/EnterLight/POWER1 ON
stat/EnterLight/RESULT {“POWER2”:“OFF”}
stat/EnterLight/POWER2 OFF
stat/ToharRoom/RESULT {“POWER1”:“OFF”}
stat/EnterLight/RESULT {“POWER3”:“OFF”}
stat/ToharRoom/POWER1 OFF
stat/EnterLight/POWER3 OFF
stat/ToharRoom/RESULT {“POWER2”:“OFF”}
stat/ToharRoom/POWER2 OFF
stat/Kitchen/RESULT {“POWER1”:“OFF”}
stat/Kitchen/POWER1 OFF
stat/Kitchen/RESULT {“POWER2”:“ON”}
stat/Kitchen/POWER2 ON
stat/Kitchen/RESULT {“POWER3”:“ON”}
stat/misdaron1/RESULT {“POWER”:“OFF”}
stat/misdaron1/POWER OFF
stat/Kitchen/POWER3 ON
stat/MisdaronLights/RESULT {“POWER1”:“OFF”}
stat/MisdaronLights/POWER1 OFF
stat/MisdaronLights/RESULT {“POWER2”:“OFF”}
stat/MisdaronLights/POWER2 OFF
tele/EnterLight/STATE {“Time”:“1970-01-01T00:00:13”,“Uptime”:“0T00:00:13”,“Vcc”:3.171,“POWER1”:“ON”,“POWER2”:“OFF”,“POWER3”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“Mejahez”,“RSSI”:72,“APMac”:“80:2A:A8:54:8A:49”}}
tele/ToharRoom/STATE {“Time”:“2018-08-12T09:05:38”,“Uptime”:“0T00:00:13”,“Vcc”:3.178,“POWER1”:“OFF”,“POWER2”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“Mejahez”,“RSSI”:100,“APMac”:“80:2A:A8:54:8A:49”}}
tele/Kitchen/STATE {“Time”:“2018-08-12T09:05:37”,“Uptime”:“0T00:00:13”,“Vcc”:3.116,“POWER1”:“OFF”,“POWER2”:“ON”,“POWER3”:“ON”,“Wifi”:{“AP”:1,“SSId”:“Mejahez”,“RSSI”:60,“APMac”:“80:2A:A8:54:8A:49”}}
tele/misdaron1/STATE {“Time”:“2018-08-12T07:05:37”,“Uptime”:“0T00:00:13”,“Vcc”:3.148,“POWER”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“Mejahez”,“RSSI”:100,“APMac”:“80:2A:A8:54:8A:49”}}
tele/MisdaronLights/STATE {“Time”:“2018-08-12T09:05:38”,“Uptime”:“0T00:00:13”,“Vcc”:3.104,“POWER1”:“OFF”,“POWER2”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“Mejahez”,“RSSI”:100,“APMac”:“80:2A:A8:54:8A:49”}}

i did what you said…
so strange…look the commet that i wrote between line from result.

I think the first message in this sequence cmnd/Kitchen/POWER (null) caused the status to change. The question is what caused this message to be sent. The fact that it has no payload may be a clue, but I don’t know enough about your system to help.

Do you have any automations that send MQTT messages?

hi…
yes. i have automation that check state of all switch.