arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.71k stars 4.72k forks source link

Sonoff Touch: Switch is off after reconnect wifi/mqtt #2424

Closed dh-harald closed 6 years ago

dh-harald commented 6 years ago

Make sure these boxes are checked before submitting your issue - Thank you!

I'm using Sonoff Touch switches with almost default configuration. I facing that issue, if my switch disconnects from wifi, it doesn't pick up the last powered state. It came up with powered off state... Here's a sample log:

Apr 11 21:10:01 wsw01-0262 ESP-MQT: home/sonoff/stat/wsw01/RESULT = {"POWER":"ON"}
Apr 11 21:10:01 wsw01-0262 ESP-MQT: home/sonoff/stat/wsw01/POWER = ON (retained)
Apr 11 21:10:02 wsw01-0262 ESP-CFG: Saved to flash at F6, Count 8762, Bytes 1648
Apr 11 21:12:30 wsw01-0262 ESP-MQT: home/sonoff/tele/wsw01/STATE = {"Time":"2018-04-11T20:12:30","Uptime":"0T11:20:14","Vcc":3.591,"POWER":"ON","Wifi":{"AP":1,"SSId":"xxx","RSSI":98,"A
PMac":"xxx"}}
Apr 11 21:22:33 wsw01-0262 ESP-RSL: home/sonoff/tele/wsw01/STATE = {"Time":"2018-04-11T20:22:33","Uptime":"0T11:25:14","Vcc":3.578,"POWER":"ON","Wifi":{"AP":1,"SSId":"xxx","RSSI":100,"
APMac":"xxx"}}
Apr 11 21:22:35 wsw01-0262 ESP-DNS: Initialized
Apr 11 21:22:35 wsw01-0262 ESP-MQT: Attempting connection...
Apr 11 21:22:35 wsw01-0262 ESP-MQT: Connected
Apr 11 21:22:35 wsw01-0262 ESP-MQT: home/sonoff/tele/wsw01/LWT = Online (retained)
Apr 11 21:22:35 wsw01-0262 ESP-MQT: home/sonoff/cmnd/wsw01/POWER = 
Apr 11 21:22:35 wsw01-0262 ESP-MQT: Subscribe to home/sonoff/cmnd/wsw01/#
Apr 11 21:22:35 wsw01-0262 ESP-MQT: Subscribe to home/sonoff/cmnd/sonoffs/#
Apr 11 21:22:35 wsw01-0262 ESP-MQT: Subscribe to cmnd/DVES_854106/#
Apr 11 21:22:35 wsw01-0262 ESP-RSL: Group 0, Index 1, Command POWER, Data OFF
Apr 11 21:22:35 wsw01-0262 ESP-MQT: home/sonoff/stat/wsw01/RESULT = {"POWER":"OFF"}
Apr 11 21:22:35 wsw01-0262 ESP-MQT: home/sonoff/stat/wsw01/POWER = OFF (retained)
Apr 11 21:22:36 wsw01-0262 ESP-CFG: Saved to flash at F5, Count 8763, Bytes 1648

And of course, poweronstate set to 3:

08:30:54 CMD: PowerOnState
08:30:54 MQT: home/sonoff/stat/wsw01/RESULT = {"PowerOnState":3}
08:32:09 CMD: PowerRetain
08:32:09 MQT: home/sonoff/stat/wsw01/RESULT = {"PowerRetain":"ON"}

Any ideas, what's wrong?

reloxx13 commented 6 years ago

disconnects from wifi

power on is not wifi connected.

poweron is triggered after power loss, thats why its called poweron and not wificonnected...

dh-harald commented 6 years ago

Oh, I see... is it any parameter, to get this functionality on wifi reconnect?

reloxx13 commented 6 years ago

nope, cuz normally their is no reconnect.

also the state does not get lost if the wifi disconnects.

relais on => wifi off => relais (stays) on

relais on => power loss => relais off => power on => relais on again

could be a mqtt server problem/misconfigured, but im out here.

dh-harald commented 6 years ago

Its quiet interesting, because I've got 2 S20 switches, and those are working correctly... I've restarted the mqtt server, results: Touch:

Apr 12 11:42:10 wsw02-3662 ESP-MQT: home/sonoff/tele/wsw02/STATE = {"Time":"2018-04-12T10:42:11","Uptime":"0T18:30:17","Vcc":3.483,"POWER":"ON","Wifi":{"AP":1,"SSId":"xxx","RSSI":100,"APMac":"xxx"}}
Apr 12 11:52:05 wsw02-3662 ESP-MQT: Attempting connection...
Apr 12 11:52:05 wsw02-3662 ESP-MQT: Connect failed to xxx:1883, rc -2. Retry in 10 sec
Apr 12 11:52:13 wsw02-3662 ESP-RSL: home/sonoff/tele/wsw02/STATE = {"Time":"2018-04-12T10:52:14","Uptime":"0T18:35:17","Vcc":3.473,"POWER":"ON","Wifi":{"AP":1,"SSId":"xxx","RSSI":100,"APMac":"xxx"}}
Apr 12 11:52:27 wsw02-3662 ESP-MQT: Attempting connection...
Apr 12 11:52:27 wsw02-3662 ESP-MQT: Connected
Apr 12 11:52:27 wsw02-3662 ESP-MQT: home/sonoff/tele/wsw02/LWT = Online (retained)
Apr 12 11:52:27 wsw02-3662 ESP-MQT: home/sonoff/cmnd/wsw02/POWER = 
Apr 12 11:52:27 wsw02-3662 ESP-MQT: Subscribe to home/sonoff/cmnd/wsw02/#
Apr 12 11:52:27 wsw02-3662 ESP-MQT: Subscribe to home/sonoff/cmnd/sonoffs/#
Apr 12 11:52:27 wsw02-3662 ESP-MQT: Subscribe to cmnd/DVES_84CE4E/#
Apr 12 11:52:27 wsw02-3662 ESP-RSL: Group 0, Index 1, Command POWER, Data OFF
Apr 12 11:52:27 wsw02-3662 ESP-MQT: home/sonoff/stat/wsw02/RESULT = {"POWER":"OFF"}
Apr 12 11:52:27 wsw02-3662 ESP-MQT: home/sonoff/stat/wsw02/POWER = OFF (retained)
Apr 12 11:52:28 wsw02-3662 ESP-CFG: Saved to flash at FA, Count 9511, Bytes 1648

meanwhile S20:

Apr 12 11:43:23 acsw01-3515 ESP-MQT: home/sonoff/tele/acsw01/STATE = {"Time":"2018-04-12T11:43:19","Uptime":"1T07:20:12","Vcc":3.528,"POWER":"ON","Wifi":{"AP":1,"SSId":"xxx","RSSI":100,"APMac":"xxx"}}
Apr 12 11:52:05 acsw01-3515 ESP-MQT: Attempting connection...
Apr 12 11:52:05 acsw01-3515 ESP-MQT: Connect failed to xxx:1883, rc -2. Retry in 10 sec
Apr 12 11:53:00 acsw01-3515 ESP-MQT: Attempting connection...
Apr 12 11:53:00 acsw01-3515 ESP-MQT: Connected
Apr 12 11:53:00 acsw01-3515 ESP-MQT: home/sonoff/tele/acsw01/LWT = Online (retained)
Apr 12 11:53:00 acsw01-3515 ESP-MQT: home/sonoff/cmnd/acsw01/POWER = 
Apr 12 11:53:00 acsw01-3515 ESP-MQT: Subscribe to home/sonoff/cmnd/acsw01/#
Apr 12 11:53:00 acsw01-3515 ESP-MQT: Subscribe to home/sonoff/cmnd/sonoffs/#
Apr 12 11:53:00 acsw01-3515 ESP-MQT: Subscribe to cmnd/DVES_acsw01/#
Apr 12 11:53:00 acsw01-3515 ESP-RSL: Group 0, Index 1, Command POWER, Data ON
Apr 12 11:53:00 acsw01-3515 ESP-MQT: home/sonoff/stat/acsw01/RESULT = {"POWER":"ON"}
Apr 12 11:53:00 acsw01-3515 ESP-MQT: home/sonoff/stat/acsw01/POWER = ON (retained)
reloxx13 commented 6 years ago

their is a command with powerretain or sth, look retain up in the wiki. but how i said, im out now, iave no mqtt server i dont know more :p

reloxx13 commented 6 years ago

2411

dh-harald commented 6 years ago

OC:

08:32:09 CMD: PowerRetain
08:32:09 MQT: home/sonoff/stat/wsw01/RESULT = {"PowerRetain":"ON"}
dh-harald commented 6 years ago

I've realized, that the Sonoff Touch always writes the configuration into the Flash (Saved to flash at FA, Count 9511, Bytes 1648), meanwhile S20 don't

reloxx13 commented 6 years ago

check SaveData command for this

dh-harald commented 6 years ago

Same settings:

11:19:32 CMD: SaveData
11:19:32 MQT: home/sonoff/stat/wsw01/RESULT = {"SaveData":"ON"}

12:19:37 CMD: SaveData
12:19:37 MQT: home/sonoff/stat/acsw01/RESULT = {"SaveData":"ON"}

acsw == S20 / wsw == Sonoff Touch

arendst commented 6 years ago

On the Touch you have log messages set to 3 while on the S20 it is set to 2 and hence no info about flash updates.

dh-harald commented 6 years ago

@arendst: do you have any idea about the "real" issue?

arendst commented 6 years ago

Well looking at your initial issue it clearly states that it receives a Power off after power on most likely caused by power retain set.

As documented in answers given since then I do not go into discussing setting power retain on.

dh-harald commented 6 years ago

@arendst: yes, I'm setting PowerRetain on, hence I'm using homeassistant... All my experiences are weird, because with same config, S20 are working fine (they're keep turning on after reconnect), while Touches aren't

It looks, when I connects to the broker, it automatically sends an power off command:

2018-04-12 14:26:12.601 home/sonoff/stat/wsw01/POWER ON
---- [ mqtt restart here ] ----
2018-04-12 14:26:30.530 home/sonoff/tele/wsw01/LWT Online
2018-04-12 14:26:30.558 home/sonoff/cmnd/wsw01/POWER OFF
2018-04-12 14:26:30.583 home/sonoff/stat/wsw01/POWER ON
2018-04-12 14:26:50.897 home/sonoff/tele/wsw01/LWT Online
2018-04-12 14:26:50.942 home/sonoff/cmnd/wsw01/POWER (null)
2018-04-12 14:26:51.119 home/sonoff/stat/wsw01/RESULT {"POWER":"OFF"}
2018-04-12 14:26:51.163 home/sonoff/stat/wsw01/POWER OFF
Jason2866 commented 6 years ago

No offend, why do so many people use HomeAssistant? I read so many problems with and about it. In my humble opinion for easy fast setup Domoticz is nice. For nearly everything OpenHab can be used. I took a short look at HA and found no reason for me to use. Setting up isnt realy simple and the things i wanted to do arent easy maybe impossible... I tried OpenHab and i am happy with that choice.

kajmaj commented 6 years ago

Jason, I am HA user. Be more specific-I use HASS.IO version. Why? (My point of view)

dh-harald commented 6 years ago

@arendst: I've investigated the issue, and I think, I've found the root cause. When you're using the switch with HA, it makes the command topic retained... So If I powered off a switch, the /cmnd/ topic got the last value retained into the mqtt (in this case powered off).... After reconnect, the switch subscribes to the /cmnd/ topic as well, and just because the topic has retained value, it thinks: got the power off command...

So, idea: could you add a config value and functionality to the command retain as well? So if you push the physical button/through webpage, the command into the topic should be retained as well (not just the power topic)... Edit: I can use not retained command topic in HA, problem solved

carloda commented 5 years ago

Hi, I have the same problem with sonoff touch, someone managed to solve?

ascillato commented 5 years ago

Solution: don't use retain messages for a normal setup. Retain is meant for advance Management like for example retained variables for the mode of a thermostat. See the video from thehookup. Link in Tutorials in the wiki

carloda commented 5 years ago

@ascillato thanks I solved =)