Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maxela/64af0e0471aa59c1550b05d8c0d79802 to your computer and use it in GitHub Desktop.
Save maxela/64af0e0471aa59c1550b05d8c0d79802 to your computer and use it in GitHub Desktop.
Tasmota Script for WiFi-2Channel-Dimmer QS-WiFi-D02-2C or MS-105B-220
;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
#
@silverStSt
Copy link

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!

@silverStSt
Copy link

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

@silverStSt
Copy link

sorry for all the messages but it is already solved, following another tutorial I had erroneously modified an option. It works great. thanks.

@maxela
Copy link
Author

maxela commented Jan 23, 2021

@silverStSt great to read that you were able to solve the issue 😊

@JDyszczynski
Copy link

JDyszczynski commented Dec 15, 2021

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
#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment