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)
|
- [LED Bar Display with WS2812 LED Chain](#LED-Bar-Display-with-WS2812-LED-Chain)
|
||||||
- [Multiple IR Receiver Synchronization](#Multiple-IR-Receiver-Synchronization)
|
- [Multiple IR Receiver Synchronization](#Multiple-IR-Receiver-Synchronization)
|
||||||
- [Fast Polling](#Fast-Polling)
|
- [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)
|
[Back To Top](#top)
|
||||||
|
|
||||||
|
@ -808,77 +808,161 @@ 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)
|
[#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**
|
>**>D**
|
||||||
sw1=0
|
sw=0
|
||||||
sw2=0
|
tmp=0
|
||||||
cnt1=0
|
cnt=0
|
||||||
cnt2=0
|
tmr=0
|
||||||
timer1=0
|
hold=0
|
||||||
timer2=0
|
powert=0
|
||||||
toggle1=0
|
slider=0
|
||||||
toggle2=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**
|
>**>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**
|
>**>F**
|
||||||
; Counter1/2 and Relay1/2 configured in template
|
cnt=pc[1]
|
||||||
cnt1=pc[1]
|
if chg[cnt]>0
|
||||||
cnt2=pc[2]
|
; sw pressed
|
||||||
>
|
then sw=1
|
||||||
>if chg[cnt1]>0
|
else sw=0
|
||||||
then
|
; sw not pressed
|
||||||
; counter1 has changed, switch is on
|
|
||||||
sw1=1
|
|
||||||
else
|
|
||||||
; no change switch is off
|
|
||||||
sw1=0
|
|
||||||
endif
|
|
||||||
>
|
|
||||||
>if chg[cnt2]>0
|
|
||||||
then
|
|
||||||
; counter2 has changed, switch is on
|
|
||||||
sw2=1
|
|
||||||
else
|
|
||||||
; no change switch is off
|
|
||||||
sw2=0
|
|
||||||
endif
|
endif
|
||||||
>
|
>
|
||||||
>; 100ms timer
|
>; 100ms timer
|
||||||
timer1+=1
|
tmr+=1
|
||||||
timer2+=1
|
|
||||||
>
|
>
|
||||||
>if sw1==0
|
>
|
||||||
and timer1>2
|
>; short press
|
||||||
and timer1<30
|
if sw==0
|
||||||
|
and tmr>shortprl
|
||||||
|
and tmr<shortpru
|
||||||
then
|
then
|
||||||
;=>print short press1
|
powert^=1
|
||||||
toggle1^=1
|
>
|
||||||
=>Power1 %toggle1%
|
>; change light on/off
|
||||||
|
if powert==1
|
||||||
|
then
|
||||||
|
=#senddim(dimval)
|
||||||
|
else
|
||||||
|
=#senddim(0)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
>
|
>
|
||||||
>if sw1==0
|
>
|
||||||
|
>; long press
|
||||||
|
if sw>0
|
||||||
then
|
then
|
||||||
timer1=0
|
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
|
||||||
|
>
|
||||||
|
>; decrease dim level
|
||||||
|
dimval-=dimstp
|
||||||
|
if dimval<dimll
|
||||||
|
then
|
||||||
|
>
|
||||||
|
>; lower limit
|
||||||
|
dimval=dimll
|
||||||
|
endif
|
||||||
|
=#senddim(dimval)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
tmr=0
|
||||||
|
hold=0
|
||||||
|
endif
|
||||||
|
|
||||||
|
>**>E**
|
||||||
|
slider=Dimmer
|
||||||
|
>
|
||||||
|
>; slider change
|
||||||
|
if chg[slider]>0
|
||||||
|
then
|
||||||
|
>
|
||||||
|
>; dim according slider
|
||||||
|
if slider>0
|
||||||
|
then
|
||||||
|
dimval=slider
|
||||||
|
=#senddim(dimval)
|
||||||
|
else
|
||||||
|
powert=0
|
||||||
|
=#senddim(0)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
>
|
>
|
||||||
>if sw2==0
|
>if pwr[1]==1
|
||||||
and timer2>2
|
; on/off webui
|
||||||
and timer2<30
|
|
||||||
then
|
then
|
||||||
;=>print short press2
|
powert=1
|
||||||
toggle2^=1
|
=#senddim(dimval)
|
||||||
=>Power2 %toggle2%
|
else
|
||||||
endif
|
powert=0
|
||||||
>
|
=#senddim(0)
|
||||||
>if sw2==0
|
|
||||||
then
|
|
||||||
timer2=0
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
>; subroutine dim
|
||||||
|
#senddim(tmp)
|
||||||
|
dim="FF55"+hn(tmp*dimmlp)+"05DC0A"
|
||||||
|
=>SerialSend5 %dim%
|
||||||
|
=>Dimmer %tmp%
|
||||||
|
\#
|
||||||
|
|
||||||
[Back To Top](#top)
|
[Back To Top](#top)
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue