Sonoff Tasmota extension for covers

Here’s what happen when i push button sparring from a not fully closed position.

06:52:14 MQT: tele/camera/STATE = {“Time”:“2018-06-13T06:52:14”,“Uptime”:“0T11:46:15”,“Vcc”:3.420,“Cover1”:69,“Wifi”:{“AP”:1,“SSId”:“BECCO”,“RSSI”:84,“APMac”:“68:7F:74:1C:D9:8C”}}
06:52:14 MQT: tele/camera/SENSOR = {“Time”:“2018-06-13T06:52:14”,“Switch1”:“ON”,“Switch2”:“ON”}
06:52:18 Pulse: 100, To:13,From:4,By:1
06:52:28 Arrived:: 14
06:52:28 MQT: stat/camera/RESULT = {“Cover1”:“ON”}
06:52:29 Pulse: 60, To:13,From:18,By:-1
06:52:35 Arrived:: 12
06:52:35 MQT: stat/camera/RESULT = {“Cover1”:92}
06:53:00 RSL: Gruppo 0, Indice 1, Comando BACKLOG, Dati cover ON
06:53:00 RSLT: Payload -101, Payload16 0
06:53:00 MQT: stat/camera/RESULT = {“Backlog”:“Appended”}
06:53:01 RSL: Gruppo 0, Indice 1, Comando COVER, Dati ON
06:53:01 RSLT: Payload 1, Payload16 0
06:53:01 Pulse: 70, To:13,From:7,By:1
06:53:08 Arrived:: 14
06:53:08 MQT: stat/camera/RESULT = {“Cover1”:“ON”}
06:54:23 Pulse: 60, To:13,From:18,By:-1
06:54:24 Arrived:: 17
06:54:24 MQT: stat/camera/RESULT = {“Cover1”:“ON”}
06:54:25 Pulse: 60, To:13,From:18,By:-1
06:54:25 Arrived:: 18
06:54:25 MQT: stat/camera/RESULT = {“Cover1”:“ON”}
06:54:27 Pulse: 119, To:0,From:18,By:-1
06:54:28 Arrived:: 17
06:54:28 MQT: stat/camera/RESULT = {“Cover1”:“ON”}
06:54:29 Pulse: 60, To:13,From:18,By:-1
06:54:29 Arrived:: 18
06:54:29 MQT: stat/camera/RESULT = {“Cover1”:“ON”}

It always came back to closed

@kabongsteve I could not try yet…i lost my sonoff upgrading to minimal firmware via ota…today I hope to be able to recover it with a serial flash.

hi @kabongsteve
my sonoff is back online
so…I replaced the line of code you suggested, but when I send any cover command only the first time the relay is switched on and off, then the rolling shutter goes fully open or fully closed always

the console log is this

21:41:36 MQT: tele/tapparellaStudio/INFO3 = {“RestartReason”:“Power on”}
21:41:36 MQT: homeassistant/switch/tapparellaStudio_1/config = (retained)
21:41:36 MQT: homeassistant/switch/tapparellaStudio_2/config = (retained)
21:41:37 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:“OFF”}
21:41:44 MQT: tele/tapparellaStudio/STATE = {“Time”:“2018-06-13T21:41:44”,“Uptime”:“0T00:00:16”,“Vcc”:3.149,“Cover1”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“aaaaa”,“RSSI”:100,“APMac”:“C8:0E:14:1E:C4:9C”}}
21:41:44 MQT: tele/tapparellaStudio/SENSOR = {“Time”:“2018-06-13T21:41:44”,“Switch1”:“ON”,“Switch2”:“ON”}
21:41:50 CMD: cover 1
21:41:56 CMD: cover 0
21:41:56 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:26}
21:42:04 CMD: cover 0
21:42:12 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:“OFF”}
21:42:16 CMD: cover 1
21:42:41 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:“ON”}
21:45:30 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:“OFF”}
21:45:47 CMD: cover 1
21:45:47 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:65}
21:45:50 CMD: cover 0
21:46:06 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:“OFF”}
21:46:44 MQT: tele/tapparellaStudio/STATE = {“Time”:“2018-06-13T21:46:44”,“Uptime”:“0T00:05:16”,“Vcc”:3.152,“Cover1”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“aaaaa”,“RSSI”:100,“APMac”:“C8:0E:14:1E:C4:9C”}}
21:46:44 MQT: tele/tapparellaStudio/SENSOR = {“Time”:“2018-06-13T21:46:44”,“Switch1”:“ON”,“Switch2”:“ON”}
21:48:06 CMD: cover 1
21:48:12 CMD: cover 0
21:48:12 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:26}
21:48:17 CMD: cover 0
21:48:25 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:“OFF”}
21:48:31 CMD: cover 50
21:48:42 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:47}

@B1G You said you replaced “the line of code”. I mentioned you had to do it twice, the second time at line 1761.
But, apart from that I’ve re-checked the code and I think i found a new place for change
Line 1704 is where the relay is normally turned off, so this one needs to bounce the relay as well.
Hopefully the following will work for you
Replace
power &= (POWER_MASK ^ (3 << (cover * 2)));
SetDevicePower(power);
with
byte device = 2 * cover;
if (cover_direction[cover] > 0)
device += 1;
power_t mask = (1 << device);
power |= mask;
SetDevicePower(power);
delay(100);
SetDevicePower(power);

Hi @alesaund,
You should be able to do the following to verify what is going on.
From the console on the sonoff do a
SwitchTopic Switch

This should cause the “pressing” of either switch to send a MQTT message INSTEAD of operating the Cover.
This will tell us whether you get a message for the press, the release or both, and that that will help to debug what is going on.
You could also add debug code around line 2404, where the switch code calls the ExecuteCommandCover to make sure that is what is causing the cover to move.

@kabongsteve yes i did it twice as you mentioned, later i will test it with this new replace

thank you

by the way, I also need to use the wall buttons like @alesaund, i think i’ll have to replace something to do that too

with the last update, when send cover 0 the relay goes on and off, then after the pulsetime, in my case 22, the relay goes on and off again and the position starts to decrement to 0, and after other 22 sec the relay goes on and remains on

7:25:01 CMD: cover 0
17:25:16 CMD: cover
17:25:16 MQT: stat/sonoff/RESULT = {“Cover1”:“ON”}
17:25:21 CMD: cover
17:25:21 MQT: stat/sonoff/RESULT = {“Cover1”:“ON”}
17:25:25 MQT: stat/sonoff/RESULT = {“Cover1”:“ON”}
17:25:26 CMD: cover
17:25:26 MQT: stat/sonoff/RESULT = {“Cover1”:95}
17:25:30 CMD: cover
17:25:30 MQT: stat/sonoff/RESULT = {“Cover1”:77}
17:25:34 CMD: cover
17:25:34 MQT: stat/sonoff/RESULT = {“Cover1”:59}
17:25:46 CMD: cover
17:25:46 MQT: stat/sonoff/RESULT = {“Cover1”:4}
17:25:49 MQT: stat/sonoff/RESULT = {“Cover1”:“OFF”}
17:25:54 CMD: cover
17:25:54 MQT: stat/sonoff/RESULT = {“Cover1”:“OFF”}

@B1G So my question is how does the original switches work on the system. If they are momentary action, then I’d assume you press and it starts moving, and then automatically stops when finished.
If pressed a second time while moving then it stops, but perhaps the second press is NOT required when going to fully open, or fully closed.
If this is the case, then this would possibly explain the second press causing it to close again.
If this is the case you have a more complex scenario, where you only want the stopping press, when not going fully open or fully closed.
Have you turned on the Debug log level to see the output from the cover code?
You may need to add some debug code like the existing debug code below, at each point where the relay on/off is done to see which one is causing the always on at the end.

snprintf_P(log_data, sizeof(log_data), “Arrived:: %d”, cover_position[cover]);
AddLog(LOG_LEVEL_DEBUG);

@kabongsteve since i have a second temporized relay connected after the sonoff (i know that i don’t need it now with the sonoff, but it was installed before and i want to leave it, in case the sonoff doesn’t work) and the original switch has two position up and down all momentary . I only need to press one time up or down and the cover starts to move, till it’s fully open or closed, so the first on and off. If i want to stop the cover before is fully open and closed i need to press again the same up or down, so the second on off for the sonoff, only in this case.
Now i’m not at home, for the next week i can’t do other tests.

This is the button https://www.gewiss.com/content/dam/gwdam/product/GW/40/00/15/25/GW40001525/_jcr_content/renditions/original.svg

@kabongsteve
i made other test adding dubug code code as you said

18:07:13 CMD: cover
18:07:13 RSL: Group 0, Index 1, Command COVER, Data
18:07:13 RSLT: Payload -101, Payload16 0
18:07:13 MQT: stat/sonoff/RESULT = {“Cover1”:“OFF”}
18:07:26 CMD: cover 0
18:07:26 RSL: Group 0, Index 1, Command COVER, Data 0
18:07:26 RSLT: Payload 0, Payload16 0
18:07:26 Pulse: 20, To:0,From:0,By:-1
18:07:26 Arrived:: 0
18:07:28 Arrived:: -2
18:07:28 Arrived:: 0
18:07:28 MQT: stat/sonoff/RESULT = {“Cover1”:“OFF”}

18:12:39 CMD: cover
18:12:39 RSL: Group 0, Index 1, Command COVER, Data
18:12:39 RSLT: Payload -101, Payload16 0
18:12:39 MQT: stat/sonoff/RESULT = {“Cover1”:“OFF”}
18:12:48 CMD: cover 50
18:12:48 RSL: Group 0, Index 1, Command COVER, Data 50
18:12:48 RSLT: Payload 50, Payload16 50
18:12:48 Pulse: 110, To:11,From:0,By:1
18:12:48 Arrived:: 0
18:12:59 Arrived:: 0
18:12:59 MQT: stat/sonoff/RESULT = {“Cover1”:“OFF”}
18:13:22 Arrived:: 24
18:13:22 Arrived:: 22
18:13:22 MQT: stat/sonoff/RESULT = {“Cover1”:“ON”}
18:13:23 CFG: Saved to flash at F6, Count 38, Bytes 1648

21:20:04 CMD: cover
21:20:04 RSL: Group 0, Index 1, Command COVER, Data
21:20:04 RSLT: Payload -101, Payload16 0
21:20:04 MQT: stat/sonoff/RESULT = {“Cover1”:“OFF”}
21:20:11 MQT: tele/sonoff/STATE = {“Time”:“2018-06-24T21:20:11”,“Uptime”:“0T00:00:16”,“Vcc”:3.225,“Cover1”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“aaaaa”,“RSSI”:100,“APMac”:“C8:0E:14:1E:C4:9C”}}
21:20:11 MQT: tele/sonoff/SENSOR = {“Time”:“2018-06-24T21:20:11”,“Switch1”:“ON”,“Switch2”:“ON”}
21:20:11 CMD: cover 1
21:20:11 RSL: Group 0, Index 1, Command COVER, Data 1
21:20:11 RSLT: Payload 1, Payload16 1
21:20:11 Pulse: 124, To:22,From:0,By:1
21:20:11 Arrived:: 0
21:20:35 Arrived:: 24
21:20:35 Arrived:: 22
21:20:35 MQT: stat/sonoff/RESULT = {“Cover1”:“ON”}
21:20:35 CFG: Saved to flash at FB, Count 41, Bytes 1648

Hi @kabongsteve !
I purchased 4CH Pro R2’s. I flashed them with Tasmota, and intend to flash your version asap as they will serve for covers. Do I understand correctly that there is basically no reason to choose the 4CH Pro (R2) over the regular 4CH, or Sonoff dual, because the on-board functions are useless, but it will still work?
TIA

Hi @B1G and all,
I have updated a new version to github.
This version supports a setoption23 to turn on/off momentary button mode.
This means it will toggle the relays as if a momentary switches at start and end of travel.
Except when closing or opening, then only the first toggle. hardcoded to 250ms, which should be enough.
This should work for all those who are using the sonoff to pretend to be the standard up/down switches of a cover.

Enjoy
Steve

Hi @BTC,
I believe the advantage of the Pro/R2 is that the relays are separated and can switch any voltage, wheras the 4CH is like the 2CH and others and they simply switch mains voltage on/off.

But yes, with the Tasmota or my firmware the additional hardware features of the Pro is somewhat unnecessary

1 Like

Hi @kabongsteve,
It’s fantastic! Thanks for you work.
Now the cover moves as it should for my case, but …
I set pulsetime1 to 24 and pulsetime2 to 0, and for example cover 50 is more like 25-30% of the aperture and stops in a different position if it’s completely open or completely closed … should I better adjust pulsetime values?
I think I’m in a very particular condition because when the cover is completely open and I close it, it starts moving immediately and when it touch the ground it’s closed but not fully, vice versa when it’s completely closed and I open it, the cover starts moving immediately but for 2 seconds it does not rise from the floor.
I made a video to explain better

And if I send a cover command with the same value multiple times, the cover continues to move on the same direction instead of staying still

@B1G Nice video

I’d say it was more like 3 seconds. So the issue you have is you need +3 seconds, when starting from closed, but +0 seconds when moving from any other position.
At line 1740, there is
int16_t extra = Settings.pulse_timer[cover + (devices_present / 2)];

between it and like 1766 remove all lines that + or - extra;
then add
if (position ==0) pulse_timer[cover] += extra;

Also around like 1743, you could do a check and if difference between cover_position and position < 2 (ie very small movement) then simply return from the function and do nothing.

then set your pulsetime1 to 20 and pulsetime2 to 3, or there abouts

let me know how that goes.

@kabongsteve i made these changes to your suggestions

// Add startup time to travel distance
int16_t extra = Settings.pulse_timer[cover + (devices_present / 2)];

//pulse_timer[cover] = abs(cover_position[cover] - position) + extra;
pulse_timer[cover] = abs(cover_position[cover] - position);

if (cover_position[cover] == 0) pulse_timer[cover] += extra;

if (abs(cover_position[cover] - position) < 2) return;

if (cover_position[cover] < position) { // switch relays
device += 1;
other -= 1;
cover_direction[cover] = 1;
if (cover_position[cover] == 0) cover_position[cover] -= extra;
}
else {
cover_direction[cover] = -1;
//cover_position[cover] += extra;
}

and it’s working, but when closing from 100 to 50%, the cover is a little more opened than when I open it from 0 to 50. The closing speed is higher then the opening speed.

doing some test, to search the value that realy opens the cover at 50%… cover 50 then cover 60, and then cover 65 has fully open the cover

20:20:04 CMD: cover 50
20:20:04 RSL: Gruppo 0, Indice 1, Comando COVER, Dati 50
20:20:04 RSLT: Payload 50, Payload16 50
20:20:04 Pulse On
20:20:05 Move: 113, To:10,From:-3,By:1
20:20:18 Arrived:: 10
20:20:18 Pulse Off
20:20:18 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:50}
20:20:29 CMD: cover 60
20:20:29 RSL: Gruppo 0, Indice 1, Comando COVER, Dati 60
20:20:29 RSLT: Payload 60, Payload16 60
20:20:29 Pulse On
20:20:29 Move: 20, To:12,From:10,By:1
20:20:31 Arrived:: 12
20:20:31 Pulse Off
20:20:31 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:60}
20:20:37 CMD: cover 65
20:20:37 RSL: Gruppo 0, Indice 1, Comando COVER, Dati 65
20:20:37 RSLT: Payload 65, Payload16 65
20:20:37 Arrived:: 12
20:20:37 Pulse Off
20:20:37 MQT: stat/tapparellaStudio/RESULT = {“Cover1”:60}

Looking at your log output, it seems the cover 65, doesn’t pule ON, only pulse Off (which will actually be a pulse on and thus move it all the way open

The code below will have to be changed
if (abs(cover_position[cover] - position) < 2) return;

if (abs(cover_position[cover] - position) <; 2) {
pulse_timer[cover] = 0;
return;
}

ie when it doesn’t have to move, then we have to clear the pulse_timer;

Its going to be way too complex to deal with differing speeds. The system is really only guesstimating where the blind is, so accuracy doesn’t exist, just something to give some idea of the relative position.
If you really need it accurate, then you’ll have get the opening position timing right, then always fully close, then re-open to get it to the right spot.

it’s a great job!
really what needs sonoff for covers I have tested your vesrion and it’s fine.
I have programed switchmode1 2 and switchmode2 2 to keep old wall switch behavious only when I open or close until “ON” or “OFF” positions the sonoff comes back automaticly to the last position set, in the other hand all other positions are fine.

I think in my case should take out 10% extra time for close, because full open “ON” returns systematicly back to 90

Thanks a lot