-
-
Save maxela/64af0e0471aa59c1550b05d8c0d79802 to your computer and use it in GitHub Desktop.
;WiFi-2CH-Dimmer v1.10 | |
;QS-WiFi-D02-2C | |
;MS-105B | |
>D | |
b1=0 | |
b2=0 | |
n1=0 | |
n2=0 | |
t1=0 | |
t2=0 | |
h1=0 | |
h2=0 | |
pl=3 | |
pu=10 | |
dd1=0 | |
dd2=0 | |
mp=2.2 | |
sp=8 | |
sm=4 | |
ll=8 | |
ul=100 | |
dv1=0 | |
dv2=0 | |
d1=70 | |
d2=70 | |
f1=0 | |
f2=0 | |
p1=0 | |
p2=0 | |
s1=0 | |
s2=0 | |
di="" | |
c=0 | |
tv=0 | |
i=0 | |
dt=0 | |
>B | |
=>Counter1 0 | |
=>Counter2 0 | |
=>Baudrate 9600 | |
=#sd1 | |
=#sd2 | |
>F | |
n1=pc[1] | |
n2=pc[2] | |
b1=0 | |
if chg[n1]>0 { | |
b1=1 | |
} | |
b2=0 | |
if chg[n2]>0 { | |
b2=1 | |
} | |
t1+=1 | |
t2+=1 | |
if b1==0 | |
and t1>pl | |
and t1<pu { | |
f1^=1 | |
dd1=0 | |
} | |
if b2==0 | |
and t2>pl | |
and t2<pu { | |
f2^=1 | |
dd2=0 | |
} | |
if b1>0 { | |
if t1>pu | |
and h1==0 { | |
h1=1 | |
dd1^=1 | |
} | |
if h1>0 { | |
if dd1>0 { | |
d1+=sm*f1 | |
if d1>ul { | |
d1=ul | |
} | |
} else { | |
d1-=sm*f1 | |
if d1<ll { | |
d1=ll | |
} | |
} | |
} | |
} else { | |
t1=0 | |
h1=0 | |
} | |
if b2>0 { | |
if t2>pu | |
and h2==0 { | |
h2=1 | |
dd2^=1 | |
} | |
if h2>0 { | |
if dd2>0 { | |
d2+=sm*f2 | |
if d2>ul { | |
d2=ul | |
} | |
} else { | |
d2-=sm*f2 | |
if d2<ll { | |
d2=ll | |
} | |
} | |
} | |
} else { | |
t2=0 | |
h2=0 | |
} | |
if f1>0 { | |
if dv1!=d1 { | |
=#ud1(d1) | |
} | |
} else { | |
if dv1>0 { | |
=#ud1(0) | |
} | |
} | |
if f2>0 { | |
if dv2!=d2 { | |
=#ud2(d2) | |
} | |
} else { | |
if dv2>0 { | |
=#ud2(0) | |
} | |
} | |
>E | |
f1=pwr[1] | |
f2=pwr[2] | |
s1=Channel1 | |
if f1>0 | |
and s1>0 { | |
if s1>=ll { | |
if s1>ul { | |
s1=ul | |
} | |
d1=s1 | |
} else { | |
f1=0 | |
s1=0 | |
} | |
} | |
s2=Channel2 | |
if f2>0 | |
and s2>0 { | |
if s2>=ll { | |
if s2>ul { | |
s2=ul | |
} | |
d2=s2 | |
} else { | |
f2=0 | |
s2=0 | |
} | |
} | |
#sd1 | |
di="FF5501"+hn(dv1*mp)+"0000000A" | |
=>SerialSend5 %di% | |
#ch1 | |
=>Channel1 %dv1% | |
#sd2 | |
di="FF550200"+hn(dv2*mp)+"00000A" | |
=>SerialSend5 %di% | |
#ch2 | |
=>Channel2 %dv2% | |
#ud1(tv) | |
if dv1<tv { | |
dt=tv-dv1 | |
i=sp | |
} else { | |
dt=dv1-tv | |
i=-sp | |
} | |
if dt>sp { | |
for c sp dt sp | |
dv1+=i | |
=#sd1 | |
next | |
} | |
dv1=tv | |
=#sd1 | |
=#ch1 | |
#ud2(tv) | |
if dv2<tv { | |
dt=tv-dv2 | |
i=sp | |
} else { | |
dt=dv2-tv | |
i=-sp | |
} | |
if dt>sp { | |
for c sp dt sp | |
dv2+=i | |
=#sd2 | |
next | |
} | |
dv2=tv | |
=#sd2 | |
=#ch2 | |
# |
@beolink btw in case you are using physical wall push buttons to switch on/off the lights, you can make them more or less sensitive by using higher or lower values for pl
. In version 1.10 in line 14 pl is set to 3:
pl=3
In my opinion this leads to a sightly too long push duration that is required to toggle the lights. Actually I had to use this value because sometimes both lights switched on/off when I wanted to switch on/off only one of them. Maybe a capacitor would also help to prevent the signal to affect both lines. But I chose to solve it this way.
If you have the same feeling when pushing the push buttons you can try with
pl=2
If then both lights toggle, go back to 3.
@maxela Thanks! Everything worked perfect until I added the second channel. Now both channels seem to be unstable. The same happens wether I use physical buttons or the sliders in the tasmota web gui. Would it be possible to get a copy of your 8.x scripting binary so I can test with that?
Thanks in advance!
@beolink I will check but probably I had compiled it by myself.
What means „unstable“? With physical switches it could be happening that the signal affects both channels. But that can not happen when you switch by using mqtt commands or the Tasmota interface.
Which device are you using?
@maxela Unstable: When I move one slider it immediately affects the correct channel but within a second or two the other channel lights up and starts dimming up until it reaches maximum. The slider I´m referring to is either in the tasmota webinterface or in the HomeAssistant. Same effect. The script I´m using is 1.10 and Tasmota 9.1
Device I´m using: MS-105B
@beolink Okay I'm using the same device.
I usually don't use sliders. But I just tested them from the Tasmota web ui and they work fine. One important detail in this context is how often commands are actually sent to the device while sliding. When I use the Tasmota web ui sliders the lights start to act when I release the slider because there is only one command sent when I release it. When I use the sliders of my home automation ui (openHAB in my case) this is a bit different. But anyway it still works quite good. I don't experience the effects you describe.
I put my 8.1.0.5 version with scripting activated on my Google drive. This is probably the firmware I use on my MS-105B. You can try if things work better with this firmware. However there's no guarantee. Maybe the reason is something else.
tasmota-DE-8.1-scripting.bin
Hi. First of all, thank you very much for your work, the script works very well and is more stable than previous versions. I have tried it with version 8.5.1 and it becomes unstable, but with the firmware version you shared it works quite well. I just have a problem with the physical switch. It changes the intensity well and turns off the light, but I can't turn it on from the physical switch. I have tried to analyze the script but the truth is that I am new and I get lost, what could I try? Thanks a lot!
Hello again, I have continued doing tests and I see that the light bulb is turned on with the switch but the power status of the device does not change, so I do not know its status. to turn off the bulb if it changes the state from power to off
sorry for all the messages but it is already solved, following another tutorial I had erroneously modified an option. It works great. thanks.
@silverStSt great to read that you were able to solve the issue 😊
Hello
Fixed BUGS:
- Buttons Toggle1 and Toggle2 didn't worked (added two variables of last pwr[1] and pwr[2] state and compare them to current values in function ">P"
- Max hex value for brightnes never been after calulating as a maximum 255dec = Hex FF (parameter mp changed to 2.55)
- When current channel will be change to ON, script automaticaly will return back last state of brightnes for this channel.
Corrected Script:
>D
b1=0
b2=0
n1=0
n2=0
t1=0
t2=0
h1=0
h2=0
pl=3
pu=10
dd1=0
dd2=0
mp=2.55
sp=8
sm=4
ll=8
ul=100
dv1=0
dv2=0
d1=70
d2=70
f1=0
f2=0
p1=0
p2=0
s1=0
s2=0
di=""
c=0
tv=0
i=0
dt=0
f1l=0
f2l=0
>B
=>Counter1 0
=>Counter2 0
=>Baudrate 9600
=#sd1
=#sd2
>F
n1=pc[1]
n2=pc[2]
b1=0
if chg[n1]>0 {
b1=1
}
b2=0
if chg[n2]>0 {
b2=1
}
t1+=1
t2+=1
if b1==0
and t1>pl
and t1<pu {
f1^=1
dd1=0
}
if b2==0
and t2>pl
and t2<pu {
f2^=1
dd2=0
}
if b1>0 {
if t1>pu
and h1==0 {
h1=1
dd1^=1
}
if h1>0 {
if dd1>0 {
d1+=sm*f1
if d1>ul {
d1=ul
}
} else {
d1-=sm*f1
if d1<ll {
d1=ll
}
}
}
} else {
t1=0
h1=0
}
if b2>0 {
if t2>pu
and h2==0 {
h2=1
dd2^=1
}
if h2>0 {
if dd2>0 {
d2+=sm*f2
if d2>ul {
d2=ul
}
} else {
d2-=sm*f2
if d2<ll {
d2=ll
}
}
}
} else {
t2=0
h2=0
}
if f1>0 {
if dv1!=d1 {
=#ud1(d1)
}
} else {
if dv1>0 {
=#ud1(0)
}
}
if f2>0 {
if dv2!=d2 {
=#ud2(d2)
}
} else {
if dv2>0 {
=#ud2(0)
}
}
>E
f1=pwr[1]
f2=pwr[2]
s1=Channel1
if f1>0
and s1>0 {
if s1>=ll {
if s1>ul {
s1=ul
}
d1=s1
} else {
f1=0
s1=0
}
}
s2=Channel2
if f2>0
and s2>0 {
if s2>=ll {
if s2>ul {
s2=ul
}
d2=s2
} else {
f2=0
s2=0
}
}
#sd1
di="FF5501"+hn(dv1*mp)+"0000000A"
=>SerialSend5 %di%
#ch1
=>Channel1 %dv1%
#sd2
di="FF550200"+hn(dv2*mp)+"00000A"
=>SerialSend5 %di%
#ch2
=>Channel2 %dv2%
#ud1(tv)
if dv1<tv {
dt=tv-dv1
i=sp
} else {
dt=dv1-tv
i=-sp
}
if dt>sp {
for c sp dt sp
dv1+=i
=#sd1
next
}
dv1=tv
=#sd1
=#ch1
#ud2(tv)
if dv2<tv {
dt=tv-dv2
i=sp
} else {
dt=dv2-tv
i=-sp
}
if dt>sp {
for c sp dt sp
dv2+=i
=#sd2
next
}
dv2=tv
=#sd2
=#ch2
>P
f1=pwr[1]
f2=pwr[2]
if upd(f1)>0
then
=>channel1 on
else
if f1<>f1l
then
=>channel1 off
endif
endif
if upd(f2)>0
then
=>channel2 on
else
if f2<>f2l
then
=>channel2 off
endif
endif
#
@beolink great! I’m glad to read that :)