mirror of https://github.com/arendst/Tasmota.git
Update frequency detection script
parent
d573736974
commit
578f7b6d1f
|
@ -6,7 +6,7 @@
|
|||
- [LED Bar Display with WS2812 LED Chain](#LED-Bar-Display-with-WS2812-LED-Chain)
|
||||
- [Multiple IR Receiver Synchronization](#Multiple-IR-Receiver-Synchronization)
|
||||
- [Fast Polling](#Fast-Polling)
|
||||
- [Switching By Recognizing Mains Power Frequency](#Switching-By-Recognizing-Mains-Power-Frequency)
|
||||
- [Switching and Dimming By Recognizing Mains Power Frequency](#Switching-and-Dimming-By-Recognizing-Mains-Power-Frequency)
|
||||
|
||||
[Back To Top](#top)
|
||||
|
||||
|
@ -808,76 +808,160 @@ endif
|
|||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### Switching By Recognizing Mains Power Frequency
|
||||
#### Switching and Dimming By Recognizing Mains Power Frequency
|
||||
Switching in Tasmota is usually done by High/Low (+3.3V/GND) changes on a GPIO. Here, however, this is achieved by a pulse frequency when connected to the GPIO, and these pulses are captured by `Counter1` in Tasmota.
|
||||
![pushbutton-input](https://user-images.githubusercontent.com/36734573/61955930-5d90e480-afbc-11e9-8d7e-00ac526874d3.png)
|
||||
|
||||
- When the **light is OFF** and there is a **short period** of pulses **->** then turn the light **ON** at the previous dimmer level.
|
||||
- When the **light is ON** and there is a **short period** of pulses **->** then turn the light **OFF**.
|
||||
- When there is a longer period of pulses (i.e., **HOLD**) **->** toggle dimming direction and then adjust the brightness level as long as the button is pressed or until the limits are reached.
|
||||
|
||||
[#6085 (comment)](../issues/6085#issuecomment-512353010)
|
||||
|
||||
In the Data Section >D at the beginning of the Script the following initialization variables may be changed:
|
||||
- dim multiplier - 0..2.55 set the dimming increment value
|
||||
- dim lower limit - range for the dimmer value for push-button operation (set according to your bulb); min 0
|
||||
- dim upper limit - range for the dimmer value for push-button operation (set according to your bulb); max 100
|
||||
- start dim level - initial dimmer level after power-up or restart; max 100
|
||||
|
||||
>**>D**
|
||||
sw1=0
|
||||
sw2=0
|
||||
cnt1=0
|
||||
cnt2=0
|
||||
timer1=0
|
||||
timer2=0
|
||||
toggle1=0
|
||||
toggle2=0
|
||||
|
||||
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
|
||||
dimstp=2 ;dim step/speed 1 to 5
|
||||
dimmlp=2.2 ;dim multiplier
|
||||
dimll=15 ;dim lower limit
|
||||
dimul=95 ;dim upper limit
|
||||
dimval=70 ;start dim level
|
||||
|
||||
>**>B**
|
||||
=>print "WiFi 2-Gang Switch Script"
|
||||
|
||||
=>print "WiFi-Dimmer-Script-v0.2"
|
||||
=>Counter1 0
|
||||
=>Baudrate 9600
|
||||
; boot sequence
|
||||
=#senddim(dimval)
|
||||
delay(1000)
|
||||
=#senddim(0)
|
||||
|
||||
>**>F**
|
||||
; Counter1/2 and Relay1/2 configured in template
|
||||
cnt1=pc[1]
|
||||
cnt2=pc[2]
|
||||
cnt=pc[1]
|
||||
if chg[cnt]>0
|
||||
; sw pressed
|
||||
then sw=1
|
||||
else sw=0
|
||||
; sw not pressed
|
||||
endif
|
||||
>
|
||||
>if chg[cnt1]>0
|
||||
>; 100ms timer
|
||||
tmr+=1
|
||||
>
|
||||
>
|
||||
>; short press
|
||||
if sw==0
|
||||
and tmr>shortprl
|
||||
and tmr<shortpru
|
||||
then
|
||||
; counter1 has changed, switch is on
|
||||
sw1=1
|
||||
powert^=1
|
||||
>
|
||||
>; change light on/off
|
||||
if powert==1
|
||||
then
|
||||
=#senddim(dimval)
|
||||
else
|
||||
; no change switch is off
|
||||
sw1=0
|
||||
endif
|
||||
=#senddim(0)
|
||||
endif
|
||||
endif
|
||||
>
|
||||
>if chg[cnt2]>0
|
||||
>
|
||||
>; long press
|
||||
if sw>0
|
||||
then
|
||||
; counter2 has changed, switch is on
|
||||
sw2=1
|
||||
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
|
||||
=#senddim(dimval)
|
||||
else
|
||||
; no change switch is off
|
||||
sw2=0
|
||||
endif
|
||||
>
|
||||
>; 100 ms timer
|
||||
timer1+=1
|
||||
timer2+=1
|
||||
>
|
||||
>if sw1==0
|
||||
and timer1>2
|
||||
and timer1<30
|
||||
>; decrease dim level
|
||||
dimval-=dimstp
|
||||
if dimval<dimll
|
||||
then
|
||||
;=>print short press1
|
||||
toggle1^=1
|
||||
=>Power1 %toggle1%
|
||||
endif
|
||||
>
|
||||
>if sw1==0
|
||||
then
|
||||
timer1=0
|
||||
endif
|
||||
>; lower limit
|
||||
dimval=dimll
|
||||
endif
|
||||
=#senddim(dimval)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
else
|
||||
tmr=0
|
||||
hold=0
|
||||
endif
|
||||
|
||||
>**>E**
|
||||
slider=Dimmer
|
||||
>
|
||||
>if sw2==0
|
||||
and timer2>2
|
||||
and timer2<30
|
||||
>; slider change
|
||||
if chg[slider]>0
|
||||
then
|
||||
;=>print short press2
|
||||
toggle2^=1
|
||||
=>Power2 %toggle2%
|
||||
endif
|
||||
>
|
||||
>if sw2==0
|
||||
>; dim according slider
|
||||
if slider>0
|
||||
then
|
||||
timer2=0
|
||||
endif
|
||||
dimval=slider
|
||||
=#senddim(dimval)
|
||||
else
|
||||
powert=0
|
||||
=#senddim(0)
|
||||
endif
|
||||
endif
|
||||
>
|
||||
>if pwr[1]==1
|
||||
; on/off webui
|
||||
then
|
||||
powert=1
|
||||
=#senddim(dimval)
|
||||
else
|
||||
powert=0
|
||||
=#senddim(0)
|
||||
endif
|
||||
|
||||
>; subroutine dim
|
||||
#senddim(tmp)
|
||||
dim="FF55"+hn(tmp*dimmlp)+"05DC0A"
|
||||
=>SerialSend5 %dim%
|
||||
=>Dimmer %tmp%
|
||||
\#
|
||||
|
||||
[Back To Top](#top)
|
||||
|
||||
|
|
Loading…
Reference in New Issue