stefanbode / Sonoff-Tasmota

Provide ESP8266 based itead Sonoff with Web, MQTT and OTA firmware using Arduino IDE, enhanced with I2C options
GNU General Public License v3.0
128 stars 41 forks source link

Question to Safe-Mode (Sonoff 4CH Pro R2) #193

Closed ranseyer closed 4 years ago

ranseyer commented 4 years ago

My Goal is to use the SonOf as an Replacemant for my existig Wintergarden-Control

I want the following procedure:

Press one of the 4 buttons on the SonOff (I'll put it on the right switch later) A) downwards: awning or roller blind (~Shutter) moves down B) Press opposite direction: Shutter stops C) Press up: shutter moves up

I've read several times: https://github.com/stefanbode/Sonoff-Tasmota/wiki/Shutter-blinds-working-with-two-relays

Since my current setup is based on the "Short Circuit safe wire configuration" I would have liked to do it that way again.

SETOPTION14 is apparently not available. That didn't really help me either: https://github.com/stefanbode/Sonoff-Tasmota/issues/69

So I defined two shutters and played around with options 80 and 81. I admit that I didn't really discover how to activate the "Short Circuit safe wire configuration". I guess I didn't understand the text correctly.

Thanks in advance for hints.

Translated with www.DeepL.com/Translator

12:13:50 MQT: stat/sonoff/STATUS = {"Status":{"Module":23,"FriendlyName":["Sonoff","Sonoff2","Sonoff3","Sonoff4"],"Topic":"sonoff","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[1,1,1,1,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":1}} 12:13:50 MQT: stat/sonoff/STATUS1 = {"StatusPRM":{"Baudrate":115200,"GroupTopic":"sonoffs","OtaUrl":"http://thehackbox.org/tasmota/release/sonoff.bin","RestartReason":"Software/System restart","Uptime":"0T01:00:29","StartupUTC":"2019-09-24T10:13:21","Sleep":50,"CfgHolder":4617,"BootCount":9,"SaveCount":137,"SaveAddress":"FB000"}} 12:13:50 MQT: stat/sonoff/STATUS2 = {"StatusFWR":{"Version":"6.6.0.10 stb-1.11(sonoff)","BuildDateTime":"2019.09.24 11:06:31","Boot":31,"Core":"STAGE","SDK":"2.2.2-dev(38a443e)"}} 12:13:50 MQT: stat/sonoff/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["neuby2",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["0000C029","280500000100060000005A64000000000000","40000000"]}} 12:13:50 MQT: stat/sonoff/STATUS4 = {"StatusMEM":{"ProgramSize":566,"Free":436,"Heap":22,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"144051","FlashMode":3,"Features":["00000407","8FDAE397","043683A0","22B617CD","01001BC0","00000001"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24","Sensors":"1,2,3,4,5,6,7,8,9,10,14,15,17,18,20,22,26,34"}} 12:13:50 MQT: stat/sonoff/STATUS5 = {"StatusNET":{"Hostname":"sonoff-3924","IPAddress":"192.168.1.43","Gateway":"192.168.1.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.1.1","Mac":"2C:F4:32:AA:6F:54","Webserver":2,"WifiConfig":4}} 12:13:50 MQT: stat/sonoff/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.1.7","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_AA6F54","MqttUser":"DVES_USER","MqttCount":2,"MAX_PACKET_SIZE":1000,"KEEPALIVE":30}} 12:13:50 MQT: stat/sonoff/STATUS7 = {"StatusTIM":{"UTC":"Tue Sep 24 11:13:50 2019","Local":"Tue Sep 24 12:13:50 2019","StartDST":"Sun Mar 31 02:00:00 2019","EndDST":"Sun Oct 27 03:00:00 2019","Timezone":"+01:00","Sunrise":"06:39","Sunset":"18:45"}} 12:13:50 MQT: stat/sonoff/STATUS10 = {"StatusSNS":{"Time":"2019-09-24T12:13:50","Epoch":1569323630,"SHUTTER-1":{"position":0, "direction":0},"SHUTTER-2":{"position":9, "direction":0}}} 12:13:50 MQT: stat/sonoff/STATUS11 = {"StatusSTS":{"Time":"2019-09-24T12:13:50","Epoch":1569323630,"Uptime":"0T01:00:29","UptimeSec":3629,"Heap":22,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":24,"MqttCount":2,"POWER1":"OFF","POWER2":"OFF","POWER3":"OFF","POWER4":"OFF","Wifi":{"AP":1,"SSId":"xxx","BSSId":"xx:4E:6D:4B:3E:xx","Channel":6,"RSSI":42,"LinkCount":2,"Downtime":"0T00:00:13","DeepSleep":0,"Heap":23152}}}

stefanbode commented 4 years ago

Which configuration you need depends on how your switches operate. down/off, up/off is the normal configuration. on/off , up/down is the failsafe configuration. The first switch control f there power and the second one set the direction. SETOPTION14 is obsolte. see wiki for INTERLOCK. Setoption 81 is obsolete. See wiki for INTERLOCK

stefanbode commented 4 years ago

the on/off up/down is ACTIVATED if INTERLOCK OFF. If INTERLOCK ON and INTERLOCK 1,2 then the shutter is in normal mode (up/off down/off). If INTERLOCK ON and INTERLOCK 1,2 and PULESETIME1 2 and PULSETIME2 2 then shutter is in pulsemode.

ranseyer commented 4 years ago

I have one Wire for "up" and one for "down". When it is powered it moves the shutter in the correct direction. Because at least one of the motors its not allowed to activate both directions or switch in 0 seconds the direction because this would short the condensor until it is discharged.

So i entered:

13:15:49 CMD: interlock off
13:15:49 MQT: stat/sonoff/RESULT = {"Interlock":"OFF","Groups":"1,2"}
13:17:14 CMD: pulsetime
13:17:14 MQT: stat/sonoff/RESULT = {"PulseTime1":"0 (Active 0)"}
13:17:24 CMD: pulsetime2
13:17:24 MQT: stat/sonoff/RESULT = {"PulseTime2":"0 (Active 0)"}

And did no reboot/ did reboot: it has not changed.

Sorry for asking a bit stupid, but i think im really on the wrong way.

PS: I have read this much times: https://github.com/stefanbode/Sonoff-Tasmota/wiki/Shutter-blinds-working-with-two-relays but for me it isnt clear whar this means exactly:

Short Circuit Safe (relay1 OFF/ON, relay2 UP/DOWN) no additional options, no PULSETIME

ranseyer commented 4 years ago

Ich habe normals in Ruhe von vorne angefangen.

-Relais 2+4 sind dauerhaft "On" -Wenn ich den ersten Shutter auf "Open" setze geht Relais 2 auf "Off" und Relais 1 geht eine Weile auf "On". -Wenn ich den ersten Shutter auf Close setzte geht auch Relais1 kurz auf "Off", dann werden beide Relais eingeschaltet

=> Das wäre im Prinzip alles OK, nur brauchen die beiden ständig aktiven Relais immer Strom.

Zweites Problem: Ich habe nichts geändert nur erneut getestet und kann mir somit schlecht erklären warum es nun funktioniert.

Falls das Verhalten so gewünscht ist, wäre das Thema also behoben. (Nur schade um den Stromverbrauch, ich würde Relais 2+4 gerne invertieren. Habe dazu mehrmals in der originalen Tasmota Doku gelesen und befürchte ich muss statt meinem Gerät Generic auswählen und alle IO/s oder sogar alle Einstellungen neu konfigurieren.

Der Stand: SwitchMode1 und SwitchMode3 ist auf "1" INTERLOCK0, INTERLOCK1, INTERLOCK2 sind alle off. Aber: "Groups":"1,2" Shutter-Relais: A) {"shutterrelay1":1} B) {"shutterrelay2":3} Shutterivert habe ich nicht: A) {"shutterinvert1":0} B) {"shutterinvert2":0}

Translation: I usually started all over again in peace.

-Relays 2+4 are permanently "On". -When I set the first shutter to "Open" relay 2 goes to "Off" and relay 1 goes to "On" for a while. -If I set the first shutter to Close also relay 1 goes briefly to "Off", then both relays are switched on.

=> That would be OK in principle, but the two permanently active relays always need current.

Second problem: I didn't change anything but tested it again and can't explain why it works now.

If the behavior is so desired, the topic would be solved. (Too bad about the power consumption, I would like to invert relay 2+4. I have read several times in the original Tasmota documentation and fear I have to choose Generic instead of my device and reconfigure all IO/s or even all settings.

The status: SwitchMode1 and SwitchMode3 is set to "1". INTERLOCK0, INTERLOCK1, INTERLOCK2 are all off. But: "Groups": "1,2" Shutter relay: A) {"shutterrelay1":1} B) {"shutterrelay2":3} I don't have Shutterivert: A) {"shutterinvert1":0} B) {"shutterinvert2"":0}

ranseyer commented 4 years ago

Nachtrag: Eigenartig finde ich folgendes: Ich habe das Template angepasst und Relais 2+4 invertiert. Nach einem Neustart oder Strom abschalten ist trotzdem wieder Relais 2+4 immer aktiv wenn gerade nichts anderes passiert wie vorher.

Translation: Addendum: I find the following strange: I adapted the template and inverted relay 2+4. After a restart or switching off the power, relay 2+4 is still active if nothing else happens.

stefanbode commented 4 years ago

The problem is that you did not have the right configuration for the interlock. Therefore the relays work in the SAFE CONFIGURATION MODE.

In the init phase you must have SHUTTERMODE 0. I assume you have shuttermode 1. You can type shutterrelay1 1 to get the same message again:

00:00:00 Shutter accuracy digits: 1
00:00:00 Shutter 0 (Relay:1): Init. Pos: 20000 [100 %], Open Vel.: 100 Close Vel.: 100 , Max Way: 20000, Opentime 10.0 [s], Closetime 10.0 [s], CoedffCalc
: c0: 0, c1 200, c2: 200, c3: 0, c4: 0, binmask 3, is inverted 1, shuttermode 0

To get to this configuration please execute these two lines INTERLOCK 1 INTERLOCK 1,2

stefanbode commented 4 years ago

The default for ALL configuration is that al relays are in OFF position. Anything else is strange. I must admitt, that in the FAILSAFE CONFIGURATION the second relay that control up/down remain in its state after relay 1 is switched OFF. Anyhow it should be easily possible to create a RULE that switchs OFF relay 2 if shutter has moved. Therefore at the end BOTH relays must be in OFF state.

ranseyer commented 4 years ago

Hi, is it a good idea to wait for the integration in TASMOTA himselve ?

My original controller ist manually uasable. I have two of the SonOff 4 Pro. So i could do: -wait a little bit -use one for the beginning without safe-configuration -i can test heavy with the second Sonoff...

PS: I did some more Tests without succes. If it helps i can reset the settings an start completly fresh an document it...

stefanbode commented 4 years ago

You can continue to solve your issues. There will be no difference between the two versions

flashtel commented 4 years ago

Hi ranseyer,

I would use Stefans code until we complete testing.

https://github.com/arendst/Sonoff-Tasmota/issues/6535#issuecomment-537051245

flashtel commented 4 years ago

It should be good to go now, I haven't tested the stat messages.

ranseyer commented 4 years ago

Thank you both. i have compiled the actual software an flashed it with "wipe all data". But when i set some options the device reboots an open an wlan with the strange name "ESP-XYZ12" (not Sonoff-XYZ12). (And i have no more access to the device until i reflash it)

Because im new in the Tasmota business, and i played a lot without really success, i think its better i wait until after merging. :-(

meingraham commented 4 years ago

ESP-XYZ12 means the firmware did not flash properly. Use esptool.py to perform the erase_flash.

ranseyer commented 4 years ago

Hi,

=> So i read the wiki again and i think the result should be the same if i flash it over the GUI for the ESP-Tool. But my Odroid tells me another story.

(my ESP-Tool knows no flashmode, maybe i habe to compile it by myselve...) `root@odroid:~# esptool --port /dev/ttyUSB0 --chip auto erase_flash esptool.py v2.1 Connecting... Detecting chip type... ESP8266 Chip is ESP8266 Enabling default SPI flash mode... Erasing flash (this may take a while)...

A fatal error occurred: ESP8266 ROM does not support function erase_flash. `

It Is an ESP8285 Chip in the SonOff 4Ch Pro...

ranseyer commented 4 years ago

Next try. Installed http://thehackbox.org/tasmota/sonoff.bin from today.

`Command: esptool.py --port COM18 --baud 57600 --after no_reset write_flash --flash_mode dout 0x00000 C:\Users\Martin\Downloads\sonoff.bin --erase-all

esptool.py v2.6 Serial port COM18 Connecting.... Detecting chip type... ESP8266 Chip is ESP8285 Features: WiFi, Embedded Flash MAC: 2c:f4:32:a9:55:bd Uploading stub... Running stub... Stub running... Configuring flash size... Auto-detected Flash size: 1MB Erasing flash (this may take a while)... Chip erase completed successfully in 0.6s Compressed 542688 bytes to 374552... Wrote 542688 bytes (374552 compressed) at 0x00000000 in 65.8 seconds (effective 66.0 kbit/s)... Hash of data verified.`

My Mistake: Commit 22dbe59 has no shutter support. I thougt this was merged.

14:24:55 CMD: SHUTTERRELAY1 1 14:24:55 RSL: stat/sonoff/RESULT = {"Command":"Unknown"}

So again i compiled Stefans Firmware by myself (i don't know an actual source for an binary) If i want to kill the Tasmota installation: I enter this:

Backlog SETOPTION80 1; SetOption63 1;SaveData 1; Delay 20;Restart 1

=> The ESP Reboots and looses WiFi Connection, and i see again the WiFi Network "ESP-XYZ12" instead of SonOff

So i flashed it again and did at the console an "Reset 2"

erase flash, reset device settings to firmware defaults and restart

After this Command i got again the the WiFi Network "ESP-XYZ12":

Backlog SETOPTION80 1; SetOption63 1;SaveData 1; Delay 20;Restart 1

I see two possibilities: My Backlog Command i no good Idea, or i compiled an instable Firmware...

stefanbode commented 4 years ago

A “Reset 2” should also perform a complete erase of wrong data on the chip

ranseyer commented 4 years ago

Thanks for the confimation. I will give an update when im back in my country... (Expected problem: How to build the rule for powering off the second relais if this still required).

stefanbode commented 4 years ago

The powe off of the second relay is now implemented as standard. Check newest build in the tasmota main project.