Skip to content

Instantly share code, notes, and snippets.

@thxthx0
Last active November 26, 2021 17:21
Show Gist options
  • Save thxthx0/ce7f72ea75ab82be2704c9536ea77bf7 to your computer and use it in GitHub Desktop.
Save thxthx0/ce7f72ea75ab82be2704c9536ea77bf7 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.3
;QS-WiFi-D02-2C
;MS-105B
>D
sw1=0
sw2=0
x=0
cn1=0
cn2=0
tm1=0
tm2=0
h1=0
h2=0
t1=0
t2=0
sl1=0
sl2=0
di=""
pl=2
pu=10
dd1=0
dd2=0
mp=2.2
sp=2
ll=15
ul=95
dv1=70
dv2=70
p1=0
p2=0
>B
=>Counter1 0
=>Counter2 0
=>Baudrate 9600
=#sd1(dv1)
delay(1000)
=#sd1(0)
=#sd2(0)
>F
cn1=pc[1]
cn2=pc[2]
if chg[cn1]>0
then sw1=1
else sw1=0
endif
if chg[cn2]>0
then sw2=1
else sw2=0
endif
tm1+=1
tm2+=1
if sw1==0
and tm1>pl
and tm1<pu
then
t1^=1
if t1==1
then
=#sd1(dv1)
else
=#sd1(0)
endif
endif
if sw2==0
and tm2>pl
and tm2<pu
then
t2^=1
if t2==1
then
=#sd2(dv2)
else
=#sd2(0)
endif
endif
if sw1>0
then
if h1==0
then
dd1^=1
endif
if tm1>pu
then
h1=1
if t1>0
then
if dd1>0
then
dv1+=sp
if dv1>ul
then
dv1=ul
endif
=#sd1(dv1)
else
dv1-=sp
if dv1<ll
then
dv1=ll
endif
=#sd1(dv1)
endif
endif
endif
else
tm1=0
h1=0
endif
if sw2>0
then
if h2==0
then
dd2^=1
endif
if tm2>pu
then
h2=1
if t2>0
then
if dd2>0
then
dv2+=sp
if dv2>ul
then
dv2=ul
endif
=#sd2(dv2)
else
dv2-=sp
if dv2<ll
then
dv2=ll
endif
=#sd2(dv2)
endif
endif
endif
else
tm2=0
h2=0
endif
>E
sl1=Channel1
if chg[sl1]>0
then
if sl1>0
then
dv1=sl1
=#sd1(dv1)
else
t1=0
=#sd1(0)
endif
endif
sl2=Channel2
if chg[sl2]>0
then
if sl2>0
then
dv2=sl2
=#sd2(dv2)
else
t2=0
=#sd2(0)
endif
endif
p1=pwr[1]
if p1==1
then
t1=1
=#sd1(dv1)
else
t1=0
=#sd1(0)
endif
p2=pwr[2]
if p2==1
then
t2=1
=#sd2(dv2)
else
t2=0
=#sd2(0)
endif
#sd1(x)
di="FF5501"+hn(x*mp)+"0000000A"
=>SerialSend5 %di%
=>Channel1 %x%
#sd2(x)
di="FF550200"+hn(x*mp)+"00000A"
=>SerialSend5 %di%
=>Channel2 %x%
#
@casapleiadi
Copy link

casapleiadi commented May 7, 2020

Hello, I was able to install tasmota firmware and load the template but the device is not working. Looks like both lights are always on at 50% power. Unfortunately I am not capable of activate script, it is a must have to let the device work or it is just for the button functions?

I also noticed that after a few minutes the device loses its configuration and start over with the tasmota-xxxx thingy.

Any suggestions?

a place to download the tasmota bin with script activated for this dual dimmer would be awesome for noobs like me.

@maxela
Copy link

maxela commented May 8, 2020

@casapleiadi

Hello, I was able to install tasmota firmware and load the template but the device is not working. Looks like both lights are always on at 50% power. Unfortunately I am not capable of activate script, it is a must have to let the device work or it is just for the button functions?

It's required for both the button functions and mqtt.

I also noticed that after a few minutes the device loses its configuration and start over with the tasmota-xxxx thingy.

Do you use and activate this template and option?

Template:
{"NAME":"2Chan-Dimmer","GPIO":[255,148,255,149,38,43,0,0,255,42,37,255,255],"FLAG":0,"BASE":18}

Console:
SetOption68 1

The device should respond in the browser like in the post of @aceindy above https://gist.github.com/thxthx0/ce7f72ea75ab82be2704c9536ea77bf7#gistcomment-3212382

@aldii-hassio
Copy link

Only switch 2 works. Any help?

@aceindy
Copy link

aceindy commented May 21, 2020

@dondch ,

Looks like there is one more 'glitch', the status of channel 1 and 2 are not updated on HA when operated by the manual switch :-/
Will try to fix it (or maybe you already did ??)

Finally had the time to fix the 'glitch' that the status of channel 1 and 2 are not updated on HA when operated by the manual switch by using value_template See also HA documentation https://www.home-assistant.io/integrations/switch.mqtt/

Just replace

    state_topic: "dualdimmer/stat/POWER1"
by
    state_topic: "dualdimmer/stat/RESULT"
    value_template: '{{ value_json["POWER1"] }}'

And ofc the same for POWER2:

light:

- platform: mqtt
  name: "dualdimmer_SW1"
  state_topic: "dualdimmer/stat/RESULT"
  value_template: '{{ value_json["POWER1"] }}'
  command_topic: "dualdimmer/cmnd/POWER1"
  availability_topic: "dualdimmer/tele/LWT"
  brightness_state_topic: "dualdimmer/stat/RESULT"
  brightness_command_topic: "dualdimmer/cmnd/Channel1"
  brightness_scale: 100
  brightness_value_template: >
  {% if value_json.Channel1 is defined %}
  {{ value_json.Channel1 }}
  {% else %}
  {% if state_attr('light.dualdimmer_SW1','brightness') == none %}
  0
  {% else %}
  {{ state_attr('light.dualdimmer_SW1','brightness') / 255 * 100 }}
  {% endif %}
  {% endif %}
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: false
- platform: mqtt
  name: "dualdimmer_SW2"
  state_topic: "dualdimmer/stat/RESULT"
  value_template: '{{ value_json["POWER2"] }}'
  command_topic: "dualdimmer/cmnd/POWER2"
  availability_topic: "dualdimmer/tele/LWT"
  brightness_state_topic: "dualdimmer/stat/RESULT"
  brightness_command_topic: "dualdimmer/cmnd/Channel2"
  brightness_scale: 100
  brightness_value_template: >
  {% if value_json.Channel2 is defined %}
  {{ value_json.Channel2 }}
  {% else %}
  {% if state_attr('light.dualdimmer_SW2','brightness') == none %}
  0
  {% else %}
  {{ state_attr('light.dualdimmer_SW2','brightness') / 255 * 100 }}
  {% endif %}
  {% endif %}
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: false

@casapleiadi
Copy link

casapleiadi commented Jun 14, 2020

Great job, the devices (I have multiple) works fine on tasmota consolle. I am using node-red instead of HA, I can switch the lights on and off but can't control dimmers, can you please tell me the MQTT command (or the console command) to dim Channel1 ans channel2? thanks!

@aceindy
Copy link

aceindy commented Jun 14, 2020

Hmm..I also use node red (within HA), but not with MQTT.
(Or did I misunderstand, and you use MQTT only and no HA at all??)

In case you do use HA, I use a 'fixed' brightness here, I'm sure you'll find a way to adapt it.
image

https://pastebin.com/iRNVhmmU

I also tinkered a while ago with a softstarter

@yuraivan
Copy link

yuraivan commented Jul 7, 2020

Hello everyone!!!! I did everything according instruction.I have entered the script, the template and activated "Setoption68 1". In web interface I see all correct. Toggle 1 and 2 are working but my lamps not light(((((( What is the problem???

@yuraivan
Copy link

yuraivan commented Jul 8, 2020

Hello everyone!!!! I did everything according instruction.I have entered the script, the template and activated "Setoption68 1". In web interface I see all correct. Toggle 1 and 2 are working but my lamps not light(((((( What is the problem???

Sorry for this moment lamp lights everytime and dont turn off. In console I see turn on and off process

@SimasVejas
Copy link

This thread is probably dead but I will try.
I've successfully flashed LM1 chip with script enabled firmware. I've pasted the script and enabled Setoption 1. Everything looks ok in Tasmota. I can see two toggles for both channels, both sliders for dimming and two counters.
My problem - my lamps are always off despite of the status in tasmota. I've tried checking corresponding channels with multimeter and one of them reports ~10V when the lamp is on or off, and the other one is always 0. Using push button also doesn't work. If I push the button toggle status doesn't change and only the counter increases.
I've tried script in this thread and script available here - https://gist.github.com/maxela/64af0e0471aa59c1550b05d8c0d79802
Maybe I did something wrong? Any help would be appreciated...
Thank you!

@maxela
Copy link

maxela commented Sep 1, 2021

This thread is probably dead but I will try

There’s not much happening in this thread, but I get notified and usually I try to help.

Which device and which version of the tasmota firmware are you using?

@SimasVejas
Copy link

SimasVejas commented Sep 1, 2021

Hi, @maxela, thanks for a quick reply!

At first glance it looks like I'm using the same two channel dimmer that is displayed in this thread with LM1 chip but my version might be a bit different. I will attach a photo of the insides when I get back home from work.
I'm not 100% sure but I believe it was 9.5.

20210901_201115

@aceindy
Copy link

aceindy commented Sep 3, 2021

Just for info, i moved to esphome with this 2ch dimmer unit, it works a lot smoother.
https://community.home-assistant.io/t/qs-wifi-d01-triac-dimmer/149811/25?u=aceindy

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