-
-
Save thxthx0/c22555f6ec25c3367264729a0ff74dce to your computer and use it in GitHub Desktop.
>D | |
sw=0 | |
tmp=0 | |
cnt=0 | |
tmr=0 | |
hold=0 | |
pwrt=0 | |
slid=0 | |
dim="" | |
doff="FF550005DC0A" | |
splo=2 ;short press lo limit | |
spup=10 ;short press up limit | |
ddir=0 ;dim dir 0/1 | |
dmul=2.2 ;dim multipl 1..2.55 | |
dstp=2 ;dim step/speed 1..5 | |
dlo=15 ;dim lolimit min.0 | |
dup=95 ;dim uplimit max.100 | |
dval=50 ;start dim level 0..100 | |
>B | |
print > Wifi-1CH-Dimmer-Script v2.0a < | |
print >> QS-WiFi-D01 150W Dimmer << | |
;hide cnt webui | |
->WebSensor1 0 | |
;reset cnt@teleperiod | |
->SetOption79 1 | |
->Baudrate 9600 | |
;boot sequ | |
=#snddim(dval) | |
delay(1000) | |
->SerialSend5 %doff% | |
=>Power1 0 | |
>F | |
cnt=pc[1] | |
if chg[cnt]>0 | |
;sw press | |
then sw=1 | |
else sw=0 | |
;sw not pressed | |
endif | |
; 100ms timer | |
tmr+=1 | |
; short press | |
if sw==0 | |
and tmr>splo | |
and tmr<spup | |
then | |
pwrt^=1 | |
;change on/off | |
if pwrt>0 | |
then | |
=#snddim(dval) | |
=>Power1 1 | |
else | |
->SerialSend5 %doff% | |
=>Power1 0 | |
endif | |
endif | |
; long press | |
if sw>0 | |
then | |
if tmr>spup | |
then | |
hold=1 | |
;off then on | |
if pwrt==0 | |
then | |
pwrt=1 | |
endif | |
;dim if on&hold | |
if pwrt>0 | |
then | |
if ddir>0 | |
then | |
;incr dimlevel | |
dval+=dstp | |
if dval>dup | |
then | |
;upper limit | |
dval=dup | |
endif | |
else | |
;decr dimlevel | |
dval-=dstp | |
if dval<dlo | |
then | |
;lower limit | |
dval=dlo | |
endif | |
endif | |
endif | |
endif | |
else | |
tmr=0 | |
if hold>0 | |
then | |
hold=0 | |
;change dim dir | |
ddir^=1 | |
endif | |
endif | |
if chg[dval]>0 | |
then | |
=#snddim(dval) | |
=>Dimmer %dval% | |
endif | |
>E | |
; slider | |
slid=Dimmer | |
if chg[slid]>0 | |
then | |
; dim per slider | |
if slid>0 | |
then | |
dval=slid | |
else | |
pwrt=0 | |
endif | |
endif | |
>P | |
; on/off webui | |
if pwr[1]>0 | |
then | |
pwrt=1 | |
dim="FF55"+hn(dval*dmul)+"05DC0A" | |
->SerialSend5 %dim% | |
else | |
pwrt=0 | |
->SerialSend5 %doff% | |
endif | |
; subroutine | |
#snddim(tmp) | |
dim="FF55"+hn(tmp*dmul)+"05DC0A" | |
->SerialSend5 %dim% | |
# |
Somehow it worked on one of my dimmers but not the other one!
Same configuration, same everything!..
Hi, I have updated the Script to v2.0a with some changes and fixes to work with Tasmota v9.5.0 / 9.5.0.8 ...
(Ver.a: dimming stops when minimum or maximum brightness is reached)
and an alt. Script v2.0b
https://gist.github.com/thxthx0/12074f1f5249e14b2a0aada75f590c9b
(Ver.b: changes the dimming direction when min/max brightness is reached and doesn't stop dimming)
also working with the precompiled tasmota-scripting.bin / tasmota-scripting.bin.gz files:
https://github.com/tasmota/install/tree/main/firmware/unofficial
Template:
{"NAME":"QS-WiFi-D01 150W Dimmer","GPIO":[0,3200,0,3232,0,0,0,0,0,352,416,0,0,1],"FLAG":0,"BASE":18}
THANKS 👍 @ askold2, sqw534, gadget78, strike56 ...
I found today that the scripting builds I was using did not support MQTT autodiscovery - so I rebuilt one on gitpod, and got discovery working again.
The dimming on this version works as expected using the scripts above, as does the discovery over MQTT - however power toggles no longer work at all.
On attempting a toggle I now get:
23:54:29.999 SRC: WebGui from 192.168.1.154
23:54:30.002 var not found: Dimmer
23:54:30.012 MQT: tele/bedroom_light/STATE = {"Time":"2021-11-28T23:54:30","Uptime":"0T00:01:49","UptimeSec":109,"Heap":22,"SleepMode":"Dynamic","Sleep":10,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Dimmer":40,"Fade":"OFF","Speed":1,"LedTable":"ON","Wifi":{"AP":1,"SSId":"barkernet","BSSId":"78:65:59:7C:9E:47","Channel":6,"Mode":"11n","RSSI":98,"Signal":-51,"LinkCount":1,"Downtime":"0T00:00:03"}}
23:54:30.018 MQT: stat/bedroom_light/RESULT = {"POWER":"ON"}
23:54:30.021 MQT: stat/bedroom_light/POWER = ON
23:54:30.555 CFG: Saved to flash at FB, Count 1356, Bytes 4096
23:54:42.435 WIF: Sending Gratuitous ARP
23:54:44.759 WIF: Checking connection...
Any thoughts?
Any thoughts?
Hi,
this must be set in my_user_config.h / user_config_override.h:
#define USE_SCRIPT // Add support for script (+17k code)
#define SCRIPT_POWER_SECTION // enable >P section (execute on power changes)
or you may use:
https://github.com/tasmota/install/blob/main/firmware/unofficial/tasmota-scripting.bin
or
https://github.com/tasmota/install/blob/main/firmware/unofficial/tasmota-scripting.bin.gz
Ah - thanks very much, I missed that line. I will try it this evening.
When I initially tried the unofficial build, the dimmer worked, but then MQTT autodiscovery did not - I think it may be left commented out in the automatic builds - but I'll take a look
Thanks for the help
Thanks - getting there!
The precompiled binaries functioned, but did not have auto discovery MQTT enabled
My own build, with your extra #define line, got the power on/off section working fine along with auto discovery
At this point, the dimming works, but toggles on/off do not. I suspect there are some status messages that are not being sent/received as expected.
I think that is because I had not set:
#define TELE_ON_POWER true
from its default of false. Doing this has partially resolved the issue - there is now a STATE message on every power ON, but not one on POWER OFF. Still looking into why!
Domoticz requires a STATE message
maybe autodiscovery plugin issue (?) and maybe SetOption59 on helps,
I also use the dimmer with Domoticz and it works without autodiscovery,
(added the dimmer manually to Domoticz and inserted the Idx in Tasmota).
Hi there,
using QS-WiFi-D01-TRIAC since about 2 years with old tasmota an 0.3 script. Since about a year WebUI does reacts anymore, last week dimmer stops working completly (also LED goes defective). So i have reflashed tasmota to reanimate the dimmer, using the actual version. Usind the new v2.0a script, but the light changes with some delay on changes in the WebUI slider and when I dim below 9% the LED begans to flicker and the dimmer resets. So i set limit minimal dimming rangen by setting dlo to 10 and with it works well with the wall switch, but using the slider in the webUi dimvalues below 10 can still be set causing a reset of the dimmer.
So i have read the scripting manual und changed some parts in the script 2.0a:
Changed GPIO14 from pwr1 to relay1 (to get rid of the "old" slider)
replaced
'>E
; slider
;slid=Dimmer
;if chg[slid]>0
;then
; dim per slider
;if slid>0
;then
;dval=slid
;else
;pwrt=0
;endif
;endif
by
'>W
sl(%dlo% %dup% dval "%dlo%" "%dval%" "%dup%")
for new slider.
When Dimmer is off and a differend dval than before is choosen with the new slider, die dimmer goes directly on. To also get correct state of relay1 (must toogle to Power1 1) by adding the following to the script in ^F section in dval-if-loop:
if sw==0
then
=>Power1 1
endif
before:
if chg[dval]>0
then
=#snddim(dval)
=>Dimmer %dval%
endif
after change:
if chg[dval]>0
then
=#snddim(dval)
=>Dimmer %dval%
if sw==0
then
=>Power1 1
endif
endif
pros:
- The new slider now shows the minimum an maximum values and the actual dimvalue an the LED and reacts much faster in changes in WebUi and can only moved in the ranges set in >D section.
cons:
- none konwn yet
Best regards
@MFe-tasmota
Cool!
A possible downside is that by changing GPIO14 to Relay, the integration with Home assistant will not be automatic, as it will be considered as a simple switch, losing the dimmer functionality.
Hello,
After powerup or restart the light goes shortly ON and OFF and then to the last dim level despite having dval=0 ;start dim level 0..100
PowerOnState 0 in the console has no effect.
Do I need additional settings?
Device: QS-WiFi-D01-TRIAC 150W Dimmer Module
firmware: Tasmota 14.2.0.4 (27611a1-scripting) by Theo Arends
script: v2.0a
Best regards
Hello,
nice, somebody else uses my script.
My First Idea maybe it is an issue of the installed Tasmota Version. I am using a self compiled Version (2022.01.28(scripting)) and since then IT Works. May IT IS a Result due to some Changes/Updates in Scripting language ? May be IT helps somehow?
(Sorry für the Crude upper/lowercase, but the autocorrection of German language Smartphone is very anoying for english language).
Hello,
Thank you for your quick reply and nice script. I like the combination of switch and web interface operation.
After looking into the script it appears that it is not a firmware issue but just a functional requirement.
According to the script: After boot or restart the dimvalue gets a preset and after 1 second the dimmer turns OFF and after a while it goes always ON with the actual slider value.
I assume that the intention was to see if the dimmer is alive? It seems odd to me because the dimmer does not stay to the init varable value.
My requirement is that the dimmer restores the state it had before powerup or restart.
To accomplish both requirements I made some changes in the script. My lines are commented with “EML”
For those who are interested:
D
sw=0
tmp=0
cnt=0
tmr=0
hold=0
powert=0
powerb=0 ;EML boot power state
bootst=0 ;EML boot state
lastst=1 ;EML 1: restore last state, 0: start dim level>off>slider value
slider=0
dim=""
doff="FF550005DC0A"
shortprl=2 ;short press lo limit
shortpru=10 ;short press up limit
dimdir=0 ;dim dir 0/1
dimmlp=2.2 ;dim multipl 1..2.55
dimstp=2 ;dim step/speed 1..5
dimll=15 ;dim lolimit min.0
dimul=95 ;dim uplimit max.100
dimval=50 ;start dim level 0..100
B
print > Wifi-1CH-Dimmer-Script v2.0a <
print >> QS-WiFi-D01 150W Dimmer <<
;hide cnt webui
->WebSensor1 0
;reset cnt@teleperiod
->SetOption79 1
->Baudrate 9600
;boot sequ
;EML begin, if no restore of the last state
if lastst==1
then
powerb=pwr[1] ;EML boot powerstatus
bootst=1 ;EML bootstatus
->Dimmer ;EML Get Dimmer value
else
;EML following 5 lines are not needed if restore of the last state
=#senddim(dimval)
delay(1000)
->SerialSend5 %doff%
=>Power1 0
powerb=1
endif
;EML end
;EML begin
;=#senddim(dimval)
;delay(1000)
;->SerialSend5 %doff%
;=>Power1 0
;EML end
F
cnt=pc[1]
if chg[cnt]>0
;sw press
then sw=1
else sw=0
;sw not pressed
endif
; 100ms timer
tmr+=1
; short press
if sw==0
and tmr>shortprl
and tmr<shortpru
then
powert^=1
;change on/off
if powert>0
then
=#senddim(dimval)
=>Power1 1
else
->SerialSend5 %doff%
=>Power1 0
endif
endif
; long press
if sw>0
then
if tmr>shortpru
then
hold=1
;off then on
if powert==0
then
powert=1
endif
;dim if on&hold
if powert>0
then
if dimdir>0
then
;incr dimlevel
dimval+=dimstp
if dimval>dimul
then
;upper limit
dimval=dimul
endif
else
;decr dimlevel
dimval-=dimstp
if dimval<dimll
then
;lower limit
dimval=dimll
endif
endif
endif
endif
else
tmr=0
if hold>0
then
hold=0
;change dim dir
dimdir^=1
endif
endif
if chg[dimval]>0
then
=#senddim(dimval)
=>Dimmer %dimval%
endif
E
;EML begin
if bootst==0
and powerb==1
and lastst==1
or
lastst==0
then
;EML end
; sliderer
slider=Dimmer
if chg[slider]>0
then
; dim per sliderer
if slider>0
then
dimval=slider
else
powert=0
endif
endif
else ;EML
bootst=0 ;EML
endif ;EML
P
; on/off webui
if pwr[1]>0
then
powert=1
dim="FF55"+hn(dimval*dimmlp)+"05DC0A"
->SerialSend5 %dim%
else
powert=0
->SerialSend5 %doff%
endif
; subroutine
#senddim(tmp)
dim="FF55"+hn(tmp*dimmlp)+"05DC0A"
->SerialSend5 %dim%
That didn't fix it for me - though luckily 9.1 works fine :-)
`>D
sw=0
tmp=0
cnt=0
tmr=0
hold=0
powert=0
slider=0
dim=""
shortprl=2 ;short press lo limit
shortpru=10;short press up limit
dimdir=0 ;dim direction 0/1
dimmlp=2.2 ;dim multiplier 1..2.55
dimstp=2 ;dim step/speed 1..5
dimll=15 ;dim lower limit min. 0
dimul=95 ;dim upper limit max. 100
dimval=70 ;start dim level 0..100
; long press
if sw>0
then
if hold==0
then
; change dim direction
dimdir^=1
endif
if tmr>shortpru
then
hold=1
if powert>0
; dim when on & hold
then
if dimdir>0
then
; increase dim level
dimval+=dimstp
if dimval>dimul
then
; upper limit
dimval=dimul
endif
dim="FF55"+hn(dimvaldimmlp)+"05DC0A"
=>SerialSend5 %dim%
=>Dimmer %dimval%
else
; decrease dim level
dimval-=dimstp
if dimval<dimll
then
; lower limit
dimval=dimll
endif
dim="FF55"+hn(dimvaldimmlp)+"05DC0A"
=>SerialSend5 %dim%
=>Dimmer %dimval%
endif
endif
endif
else
tmr=0
hold=0
endif