From e112902fd136642e23df604c526b7ac0fac3222a Mon Sep 17 00:00:00 2001 From: Michael Ingraham <34340210+meingraham@users.noreply.github.com> Date: Sun, 28 Jul 2019 14:41:18 -0400 Subject: [PATCH] Formatting. Needs to be rethought to remove need for
in code blocks --- Script-Cookbook.md | 842 ++++++++++----------------------------------- 1 file changed, 175 insertions(+), 667 deletions(-) diff --git a/Script-Cookbook.md b/Script-Cookbook.md index ff9fa5fa..7f75155b 100644 --- a/Script-Cookbook.md +++ b/Script-Cookbook.md @@ -8,7 +8,6 @@ - [Fast Polling](#Fast-Polling) - [Switching By Recognizing Mains Power Frequency](#Switching-By-Recognizing-Mains-Power-Frequency) - [Back To Top](#top) ------------------------------------------------------------------------------ @@ -16,509 +15,164 @@ #### Scripting Language Example Actually this code is too large. This is meant to show some of the possibilities -**\>D** -; define all vars here -p:mintmp=10 (p:means permanent) -p:maxtmp=30 -t:timer1=30 (t:means countdown timer) -t:mt=0 -i:count=0 (i:means auto counter) -hello="hello world" -string="xxx" -url="[192.168.178.86]" -hum=0 -temp=0 -timer=0 -dimmer=0 -sw=0 -rssi=0 -param=0 +**>D** -col="" -ocol="" -chan1=0 -chan2=0 -chan3=0 +; define all vars here
p:mintmp=10 (p:means permanent)
p:maxtmp=30
t:timer1=30 (t:means countdown timer)
t:mt=0
i:count=0 (i:means auto counter)
hello="hello world"
string="xxx"
url="[192.168.178.86]"
hum=0
temp=0
timer=0
dimmer=0
sw=0
rssi=0
param=0 -ahum=0 -atemp=0 -tcnt=0 -hour=0 -state=1 -m:med5=0 -M:movav=0 -; define array with 10 entries -m:array=0 10 +col=""
ocol=""
chan1=0
chan2=0
chan3=0 -**\>B** +ahum=0
atemp=0
tcnt=0
hour=0
state=1
m:med5=0
M:movav=0
; define array with 10 entries
m:array=0 10 -string=hello+"how are you?" -=\>print BOOT executed -=\>print %hello% -=\>mp3track 1 +**>B** -; list gpio pin definitions -for cnt 0 16 1 -tmp=pd[cnt] -=>print %cnt% = %tmp% -next +string=hello+"how are you?"
=\>print BOOT executed
=\>print %hello%
=\>mp3track 1 -; get gpio pin for relais 1 -tmp=pn[21] -=>print relais 1 is on pin %tmp% +; list gpio pin definitions
for cnt 0 16 1
tmp=pd[cnt]
=>print %cnt% = %tmp%
next -; pulse relais over raw gpio -spin(tmp 1) -delay(100) -spin(tmp 0) +; get gpio pin for relais 1
tmp=pn[21]
=>print relais 1 is on pin %tmp% -; raw pin level -=>print level of gpio1 %pin[1]% +; pulse relais over raw gpio
spin(tmp 1)
delay(100)
spin(tmp 0) -; pulse over tasmota cmd -=>power 1 -delay(100) -=>power 0 +; raw pin level
=>print level of gpio1 %pin[1]% -**\>T** -hum=BME280#Humidity -temp=BME280#Temperature -rssi=Wifi#RSSI -string=SleepMode +; pulse over tasmota cmd
=>power 1
delay(100)
=>power 0 -; add to median filter -median=temp -; add to moving average filter -movav=hum +**>T** -; show filtered results -=>print %median% %movav% +hum=BME280#Humidity
temp=BME280#Temperature
rssi=Wifi#RSSI
string=SleepMode -if chg[rssi]>0 -then =>print rssi changed to %rssi% -endif +; add to median filter
median=temp
; add to moving average filter
movav=hum -if temp\>30 -and hum\>70 -then =\>print damn hot! -endif +; show filtered results
=>print %median% %movav% -**\>S** +if chg[rssi]>0
then =>print rssi changed to %rssi%
endif -; every second but not completely reliable time here -; use upsecs and uptime or best t: for reliable timers +if temp\>30
and hum\>70
then =\>print damn hot!
endif -; arrays -array[1]=4 -array[2]=5 -tmp=array[1]+array[2] +**>S** -; call subrountines with parameters -=#sub1("hallo") -=#sub2(999) +; every second but not completely reliable time here
; use upsecs and uptime or best t: for reliable timers -; stop timer after expired -if timer1==0 -then timer1=-1 -=>print timer1 expired -endif +; arrays
array[1]=4
array[2]=5
tmp=array[1]+array[2] -; auto counter with restart -if count>=10 -then =>print 10 seconds over -count=0 -endif +; call subrountines with parameters
=#sub1("hallo")
=#sub2(999) -if upsecs%5==0 -then =\>print %upsecs% (every 5 seconds) -endif +; stop timer after expired
if timer1==0
then timer1=-1
=>print timer1 expired
endif -; not recommended for reliable timers -timer+=1 -if timer\>=5 -then =\>print 5 seconds over (may be) -timer=0 -endif +; auto counter with restart
if count>=10
then =>print 10 seconds over
count=0
endif -dimmer+=1 -if dimmer\>100 -then dimmer=0 -endif +if upsecs%5==0
then =\>print %upsecs% (every 5 seconds)
endif -=\>dimmer %dimmer% -=\>WebSend %url% dimmer %dimmer% +; not recommended for reliable timers
timer+=1
if timer\>=5
then =\>print 5 seconds over (may be)
timer=0
endif -; show on display -dp0 -=\>displaytext [c1l1f1s2p20] dimmer=%dimmer% +dimmer+=1
if dimmer\>100
then dimmer=0
endif + +=\>dimmer %dimmer%
=\>WebSend %url% dimmer %dimmer% + +; show on display
dp0
=\>displaytext [c1l1f1s2p20] dimmer=%dimmer% =\>print %upsecs% %uptime% %time% %sunrise% %sunset% %tstamp% -if time\>sunset -and time< sunrise -then -; night time -if pwr[1]==0 -then =\>power1 1 -endif -else -; day time -if pwr[1]\>0 -then =\>power1 0 -endif -endif +if time\>sunset
and time< sunrise
then
; night time
if pwr[1]==0
then =\>power1 1
endif
else
; day time
if pwr[1]\>0
then =\>power1 0
endif
endif -; clr display on boot -if boot\>0 -then =\>displaytext [z] -endif +; clr display on boot
if boot\>0
then =\>displaytext [z]
endif -; frost warning -if temp<0 -and mt<=0 -then =#sendmail("frost alert") -; alarm only every 5 minutes -mt=300 -=>mp3track 2 -endif +; frost warning
if temp<0
and mt<=0
then =#sendmail("frost alert")
; alarm only every 5 minutes
mt=300
=>mp3track 2
endif -; var has been updated -if upd[hello]>0 -then =>print %hello% -endif +; var has been updated
if upd[hello]>0
then =>print %hello%
endif -; send to Thingspeak every 60 seconds -; average data in between -if upsecs%60==0 -then -ahum/=tcnt -atemp/=tcnt -=>Websend [184.106.153.149:80]/update?key=PYUZMVWCICBW492&field1=%atemp%&field2=%ahum% -tcnt=0 -atemp=0 -ahum=0 -else -ahum+=hum -atemp+=temp -tcnt+=1 -endif +; send to Thingspeak every 60 seconds
; average data in between
if upsecs%60==0
then
ahum/=tcnt
atemp/=tcnt
=>Websend [184.106.153.149:80]/update?key=PYUZMVWCICBW492&field1=%atemp%&field2=%ahum%
tcnt=0
atemp=0
ahum=0
else
ahum+=hum
atemp+=temp
tcnt+=1
endif -hour=int(time/60) -if chg[hour]>0 -then -; exactly every hour -=>print full hour reached -endif +hour=int(time/60)
if chg[hour]>0
then
; exactly every hour
=>print full hour reached
endif -if time>5 { -=>print more then 5 minutes after midnight -} else { -=>print less then 5 minutes after midnight -} +if time>5 {
=>print more then 5 minutes after midnight
} else {
=>print less then 5 minutes after midnight
} -; publish abs hum every teleperiod time -if mqtts>0 -and upsecs%tper==0 -then -; calc abs humidity -tmp=pow(2.718281828 (17.67\*temp)/(temp+243.5)) -tmp=(6.112\*tmp\*hum\*18.01534)/((273.15+temp)\*8.31447215) -; publish median filtered value -=>Publish tele/%topic%/SENSOR {"Script":{"abshum":%med(0 tmp)%}} -endif +; publish abs hum every teleperiod time
if mqtts>0
and upsecs%tper==0
then
; calc abs humidity
tmp=pow(2.718281828 (17.67\*temp)/(temp+243.5))
tmp=(6.112\*tmp\*hum\*18.01534)/((273.15+temp)\*8.31447215)
; publish median filtered value
=>Publish tele/%topic%/SENSOR {"Script":{"abshum":%med(0 tmp)%}}
endif -;switch case state machine -switch state -case 1 -=>print state=%state% , start -state+=1 -case 2 -=>print state=%state% -state+=1 -case 3 -=>print state=%state% , reset -state=1 -ends +;switch case state machine
switch state
case 1
=>print state=%state% , start
state+=1
case 2
=>print state=%state%
state+=1
case 3
=>print state=%state% , reset
state=1
ends -; subroutines -\#sub1(string) -=>print sub1: %string% -\#sub2(param) -=>print sub2: %param% +; subroutines
\#sub1(string)
=>print sub1: %string%
\#sub2(param)
=>print sub2: %param% -\#sendmail(string) -=>sendmail [smtp.gmail.com:465:user:passwd:::alarm] %string% +\#sendmail(string)
=>sendmail [smtp.gmail.com:465:user:passwd:::alarm] %string% + +**>E** -**\>E** =\>print event executed! -; get HSBColor 1. component -tmp=st(HSBColor , 1) +; get HSBColor 1. component
tmp=st(HSBColor , 1) -; check if switch changed state -sw=sw[1] -if chg[sw]>0 -then =\>power1 %sw% -endif +; check if switch changed state
sw=sw[1]
if chg[sw]>0
then =\>power1 %sw%
endif hello="event occured" -; check for Color change (Color is a string) -col=Color -; color change needs 2 string vars -if col!=ocol -then ocol=col -=>print color changed %col% -endif +; check for Color change (Color is a string)
col=Color
; color change needs 2 string vars
if col!=ocol
then ocol=col
=>print color changed %col%
endif -; or check change of color channels -chan1=Channel[1] -chan2=Channel[2] -chan3=Channel[3] +; or check change of color channels
chan1=Channel[1]
chan2=Channel[2]
chan3=Channel[3] -if chg[chan1]>0 -or chg[chan2]>0 -or chg[chan3]>0 -then => color has changed -endif +if chg[chan1]>0
or chg[chan2]>0
or chg[chan3]>0
then => color has changed
endif -; compose color string for red -col=hn(255)+hn(0)+hn(0) -=>color %col% +; compose color string for red
col=hn(255)+hn(0)+hn(0)
=>color %col% + +**>R** -**\>R** =\>print restarting now - [Back To Top](#top) ------------------------------------------------------------------------------ #### Log Sensor -; define all vars here -; reserve large strings -**\>D** 48 -hum=0 -temp=0 -fr=0 -res=0 -; moving average for 60 seconds -M:mhum=0 60 -M:mtemp=0 60 -str="" +; define all vars here
; reserve large strings +**>D 48** -**\>B** -; set sensor file download link -fl1("slog.txt") -; delete file in case we want to start fresh -;fd("slog.txt") +hum=0
temp=0
fr=0
res=0
; moving average for 60 seconds
M:mhum=0 60
M:mtemp=0 60
str="" + +**>B** + +; set sensor file download link
fl1("slog.txt")
; delete file in case we want to start fresh
;fd("slog.txt") -; list all files in root directory -fr=fo("/" 0) -for cnt 1 20 1 -res=fr(str fr) -if res>0 -then -=>print %cnt% : %str% -else -break -endif -next -fc(fr) +; list all files in root directory
fr=fo("/" 0)
for cnt 1 20 1
res=fr(str fr)
if res>0
then
=>print %cnt% : %str%
else
break
endif
next
fc(fr) -**\>T** -; get sensor values -temp=BME280#Temperature -hum=BME280#Humidity +**>T** -**\>S** -; average sensor values every second -mhum=hum -mtemp=temp +; get sensor values
temp=BME280#Temperature
hum=BME280#Humidity -; write average to sensor log every minute -if upsecs%60==0 -then -; open file for write -fr=fo("slog.txt" 1) -; compose string for tab delimited file entry -str=s(upsecs)+"\t"+s(mhum)+"\t"+s(mtemp)+"\n" -; write string to log file -res=fw(str fr) -; close file -fc(fr) -endif +**>S** -**\>R** +; average sensor values every second
mhum=hum
mtemp=temp +; write average to sensor log every minute
if upsecs%60==0
then
; open file for write
fr=fo("slog.txt" 1)
; compose string for tab delimited file entry
str=s(upsecs)+"\t"+s(mhum)+"\t"+s(mtemp)+"\n"
; write string to log file
res=fw(str fr)
; close file
fc(fr)
endif + +**>R** [Back To Top](#top) ------------------------------------------------------------------------------ #### ePaper 29 Display with SGP30 and BME280 - -Some vars are set from iobroker -DisplayText substituted to save script space - -**\>D** -hum=0 -temp=0 -press=0 -ahum=0 -tvoc=0 -eco2=0 -zwz=0 -wr1=0 -wr2=0 -wr3=0 -otmp=0 -pwl=0 -tmp=0 -DT="DisplayText" -; preset units in case they are not available -punit="hPa" -tunit="C" - -**\>B** -;reset auto draw -=>%DT% [zD0] -;clr display and draw a frame -=>%DT% [x0y20h296x0y40h296] - -**\>T** -; get tele vars -temp=BME280#Temperature -hum=BME280#Humidity -press=BME280#Pressure -tvoc=SGP30#TVOC -eco2=SGP30#eCO2 -ahum=SGP30#aHumidity -tunit=TempUnit -punit=PressureUnit - -**\>S** -// update display every teleperiod time -if upsecs%tper==0 -then -dp2 -=>%DT% [f1p7x0y5]%temp% %tunit% -=>%DT% [p5x70y5]%hum% %%[x250y5t] -=>%DT% [p11x140y5]%press% %punit% -=>%DT% [p10x30y25]TVOC: %tvoc% ppb -=>%DT% [p10x160y25]eCO2: %eco2% ppm -=>%DT% [p10c26l5]ahum: %ahum% g^m3 - -dp0 -=>%DT% [p25c1l5]WR 1 (Dach) : %wr1% W -=>%DT% [p25c1l6]WR 2 (Garage): %-wr3% W -=>%DT% [p25c1l7]WR 3 (Garten): %-wr2% W -=>%DT% [p25c1l8]Aussentemperatur: %otmp% C -=>%DT% [x170y95r120:30f2p6x185y100] %pwl% %% -; now update screen -=>%DT% [d] -endif - - -**\>E** - -**\>R** - - -[Back To Top](#top) - ------------------------------------------------------------------------------- - -#### ILI 9488 Color LCD Display with BMP280 and VL5310X -shows various energy graphs -display switches on and off with proximity sensor - -some vars are set from iobroker +Some vars are set from iobroker
DisplayText substituted to save script space **>D** -temp=0 -press=0 -zwz=0 -wr1=0 -wr2=0 -wr3=0 -otmp=0 -pwl=0 -tmp=0 -dist=0 -DT="DisplayText" -punit="hPa" -tunit="C" -hour=0 + +hum=0
temp=0
press=0
ahum=0
tvoc=0
eco2=0
zwz=0
wr1=0
wr2=0
wr3=0
otmp=0
pwl=0
tmp=0
DT="DisplayText"
; preset units in case they are not available
punit="hPa"
tunit="C" **>B** -=>%DT% [z] -// define 2 graphs, 2. has 3 tracks -=>%DT% [zCi1G2656:5:20:400:80:1440:-5000:5000:3Ci7f3x410y20]+5000 W[x410y95]-5000 W [Ci7f1x70y3] Zweirichtungsz~80hler - 24 Stunden -=>%DT% [Ci1G2657:5:120:400:80:1440:0:5000:3Ci7f3x410y120]+5000 W[x410y195]0 W [Ci7f1x70y103] Wechselrichter 1-3 - 24 Stunden -=>%DT% [Ci1G2658:5:120:400:80:1440:0:5000:16][Ci1G2659:5:120:400:80:1440:0:5000:5] -=>%DT% [f1s1b0:260:260:100​:50:2:11:4:2:Rel 1:b1:370:260:100​:50:2:11:4:2:Dsp off:] -=>mp3volume 100 -=>mp3track 4 +;reset auto draw
=>%DT% [zD0]
;clr display and draw a frame
=>%DT% [x0y20h296x0y40h296] **>T** -; get some tele vars -temp=BMP280#Temperature -press=BMP280#Pressure -tunit=TempUnit -punit=PressureUnit -dist=VL53L0X#Distance - -; check proximity sensor to switch display on/off -; to prevent burn in -if dist>300 -then -if pwr[2]>0 -then -=>power2 0 -endif -else -if pwr[2]==0 -then -=>power2 1 -endif -endif +; get tele vars
temp=BME280#Temperature
hum=BME280#Humidity
press=BME280#Pressure
tvoc=SGP30#TVOC
eco2=SGP30#eCO2
ahum=SGP30#aHumidity
tunit=TempUnit
punit=PressureUnit **>S** -; update graph every teleperiod -if upsecs%tper==0 -then -dp2 -=>%DT% [f1Ci3x40y260w30Ci1] -=>%DT% [Ci7x120y220t] -=>%DT% [Ci7x180y220T] -=>%DT% [Ci7p8x120y240]%temp% %tunit% -=>%DT% [Ci7x120y260]%press% %punit% -=>%DT% [Ci7x120y280]%dist% mm -dp0 -=>%DT% [g0:%zwz%g1:%wr1%g2:%-wr2%g3:%-wr3%] -if zwz>0 -then -=>%DT% [p-8x410y55Ci2Bi0]%zwz% W -else -=>%DT% [p-8x410y55Ci3Bi0]%zwz% W -endif -=>%DT% [p-8x410y140Ci3Bi0]%wr1% W -=>%DT% [p-8x410y155Ci16Bi0]%-wr2% W -=>%DT% [p-8x410y170Ci5Bi0]%-wr3% W -endif -; chime every full hour -hour=int(time/60) -if chg[hour]>0 -then =>mp3track 4 -endif +// update display every teleperiod time
if upsecs%tper==0
then
dp2
=>%DT% [f1p7x0y5]%temp% %tunit%
=>%DT% [p5x70y5]%hum% %%[x250y5t]
=>%DT% [p11x140y5]%press% %punit%
=>%DT% [p10x30y25]TVOC: %tvoc% ppb
=>%DT% [p10x160y25]eCO2: %eco2% ppm
=>%DT% [p10c26l5]ahum: %ahum% g^m3 + +dp0
=>%DT% [p25c1l5]WR 1 (Dach) : %wr1% W
=>%DT% [p25c1l6]WR 2 (Garage): %-wr3% W
=>%DT% [p25c1l7]WR 3 (Garten): %-wr2% W
=>%DT% [p25c1l8]Aussentemperatur: %otmp% C
=>%DT% [x170y95r120:30f2p6x185y100] %pwl% %%
; now update screen
=>%DT% [d]
endif **>E** @@ -527,237 +181,133 @@ endif [Back To Top](#top) ------------------------------------------------------------------------------ -#### LED Bar Display with WS2812 LED Chain -Used as display for solar house power input/output (+-5000 Watts) -**\>D** -m:array=0 60 ;defines array for 60 led pixels -cnt=0 -val=0 -ind=0 -; rgb values for grid -colr1=0x050000 -colr2=0x050100 -colg1=0x000300 -colg2=0x020300 -ledbar=0 -blue=64 -pixels=60 -steps=10 -div=0 -tog=0 -max=5000 -min=-5000 -pos=0 +#### ILI 9488 Color LCD Display with BMP280 and VL5310X +Shows various energy graphs
display switches on and off with proximity sensor -**\>B** -div=pixels/steps -=#prep -ws2812(array) +some vars are set from iobroker -; ledbar is set from broker -**\>S** -if ledbarD** -if ledbar>max -then ledbar=max -endif +temp=0
press=0
zwz=0
wr1=0
wr2=0
wr3=0
otmp=0
pwl=0
tmp=0
dist=0
DT="DisplayText"
punit="hPa"
tunit="C"
hour=0 -pos=(ledbar/max)*(pixels/2) -if ledbar>0 -then -pos+=(pixels/2) -if pos>pixels-1 -then pos=pixels -endif -else -pos+=(pixels/2)+1 -if pos>pixels-1 -then pos=1 -endif -endif +**>B** -if pos<1 -or pos>pixels -then pos=1 -endif +=>%DT% [z] -=#prep +// define 2 graphs, 2. has 3 tracks
=>%DT% [zCi1G2656:5:20:400:80:1440:-5000:5000:3Ci7f3x410y20]+5000 W[x410y95]-5000 W [Ci7f1x70y3] Zweirichtungsz~80hler - 24 Stunden
=>%DT% [Ci1G2657:5:120:400:80:1440:0:5000:3Ci7f3x410y120]+5000 W[x410y195]0 W [Ci7f1x70y103] Wechselrichter 1-3 - 24 Stunden
=>%DT% [Ci1G2658:5:120:400:80:1440:0:5000:16][Ci1G2659:5:120:400:80:1440:0:5000:5]
=>%DT% [f1s1b0:260:260:100​:50:2:11:4:2:Rel 1:b1:370:260:100​:50:2:11:4:2:Dsp off:]
=>mp3volume 100
=>mp3track 4 -if ledbar==0 -then -array[pos]=blue -array[pos-1]=blue -else -array[pos]=blue -endif +**>T** -; only used if power is off -; so lets may be used normally if on -if pwr[1]==0 -then -ws2812(array) -endif +; get some tele vars
temp=BMP280#Temperature
press=BMP280#Pressure
tunit=TempUnit
punit=PressureUnit
dist=VL53L0X#Distance -; subroutine for grid -#prep -for cnt 1 pixels 1 -ind+=1 -if ind>div -then ind=1 -tog^=1 -endif +; check proximity sensor to switch display on/off
; to prevent burn in
if dist>300
then
if pwr[2]>0
then
=>power2 0
endif
else
if pwr[2]==0
then
=>power2 1
endif
endif -if cnt<=pixels/2 -then -if tog>0 -then val=colr1 -else val=colr2 -endif -else -if tog>0 -then val=colg1 -else val=colg2 -endif -endif -array[cnt]=val -next -**\>R** +**>S** + +; update graph every teleperiod
if upsecs%tper==0
then
dp2
=>%DT% [f1Ci3x40y260w30Ci1]
=>%DT% [Ci7x120y220t]
=>%DT% [Ci7x180y220T]
=>%DT% [Ci7p8x120y240]%temp% %tunit%
=>%DT% [Ci7x120y260]%press% %punit%
=>%DT% [Ci7x120y280]%dist% mm
dp0
=>%DT% [g0:%zwz%g1:%wr1%g2:%-wr2%g3:%-wr3%]
if zwz>0
then
=>%DT% [p-8x410y55Ci2Bi0]%zwz% W
else
=>%DT% [p-8x410y55Ci3Bi0]%zwz% W
endif
=>%DT% [p-8x410y140Ci3Bi0]%wr1% W
=>%DT% [p-8x410y155Ci16Bi0]%-wr2% W
=>%DT% [p-8x410y170Ci5Bi0]%-wr3% W
endif + +; chime every full hour
hour=int(time/60)
if chg[hour]>0
then =>mp3track 4
endif + +**>E** + +**>R** [Back To Top](#top) ------------------------------------------------------------------------------ + +#### LED Bar Display with WS2812 LED Chain +Used as display for solar house power input/output (+-5000 Watts) + +**>D** + +m:array=0 60 ;defines array for 60 led pixels
cnt=0
val=0
ind=0
; rgb values for grid
colr1=0x050000
colr2=0x050100
colg1=0x000300
colg2=0x020300
ledbar=0
blue=64
pixels=60
steps=10
div=0
tog=0
max=5000
min=-5000
pos=0 + +**>B** + +div=pixels/steps
=#prep
ws2812(array) + +; ledbar is set from broker
**>S** + +if ledbarthen ledbar=min
endif + +if ledbar>max
then ledbar=max
endif + +pos=(ledbar/max)*(pixels/2)
if ledbar>0
then
pos+=(pixels/2)
if pos>pixels-1
then pos=pixels
endif
else
pos+=(pixels/2)+1
if pos>pixels-1
then pos=1
endif
endif + +if pos<1
or pos>pixels
then pos=1
endif + +=#prep + +if ledbar==0
then
array[pos]=blue
array[pos-1]=blue
else
array[pos]=blue
endif + +; only used if power is off
; so lets may be used normally if on
if pwr[1]==0
then
ws2812(array)
endif + +; subroutine for grid
#prep
for cnt 1 pixels 1
ind+=1
if ind>div
then ind=1
tog^=1
endif + +if cnt<=pixels/2
then
if tog>0
then val=colr1
else val=colr2
endif
else
if tog>0
then val=colg1
else val=colg2
endif
endif
array[cnt]=val
next + +**>R** + +[Back To Top](#top) + +------------------------------------------------------------------------------ + #### Multiple IR Receiver Synchronization -since i own a magic home with ir receiver i made a script to show how it works -i have 2 magic home devices that should be synchronized so i send the commands also to a second magic home via websend +Since I own a magic home with IR receiver I made a script to show how it works
I have 2 magic home devices that should be synchronized so I send the commands also to a second magic home via websend ; define (expand string section to 25 chars) -**\>D 25** -istr="" -ws="websend [192.168.178.84]" -; event section -**\>E** -; get ir data -istr=IrReceived#Data +**>D 25** -; on -if istr=="0x00F7C03F" -then -=>wakeup -=>%ws% wakeup -endif +istr=""
ws="websend [192.168.178.84]" -; off -if istr=="0x00F740BF" -then -=>power1 0 -=>%ws% power1 0 -endif +; event section
**>E** -;white -if istr=="0x00F7E01F" -then -=>color 000000ff -=>%ws% color 000000ff -endif +; get ir data
istr=IrReceived#Data -;red -if istr=="0x00F720DF" -then -=>color ff000000 -=>%ws% color ff000000 -endif +; on
if istr=="0x00F7C03F"
then
=>wakeup
=>%ws% wakeup
endif -;green -if istr=="0x00F7A05F" -then -=>color 00ff0000 -=>%ws% color 00ff0000 -endif +; off
if istr=="0x00F740BF"
then
=>power1 0
=>%ws% power1 0
endif -;blue -if istr=="0x00F7609F" -then -=>color 0000ff00 -=>%ws% color 0000ff00 -endif +;white
if istr=="0x00F7E01F"
then
=>color 000000ff
=>%ws% color 000000ff
endif -; dimmer up -if istr=="0x00F700FF" -then -=>dimmer + -=>%ws% dimmer + -endif +;red
if istr=="0x00F720DF"
then
=>color ff000000
=>%ws% color ff000000
endif -;dimmer down -if istr=="0x00F7807F" -then -=>dimmer - -=>%ws% dimmer - -endif +;green
if istr=="0x00F7A05F"
then
=>color 00ff0000
=>%ws% color 00ff0000
endif + +;blue
if istr=="0x00F7609F"
then
=>color 0000ff00
=>%ws% color 0000ff00
endif + +; dimmer up
if istr=="0x00F700FF"
then
=>dimmer +
=>%ws% dimmer +
endif + +;dimmer down
if istr=="0x00F7807F"
then
=>dimmer -
=>%ws% dimmer -
endif istr="" - [Back To Top](#top) ------------------------------------------------------------------------------ #### Fast Polling ; expand strings to hold websend -**\>D 25** -sw=0 -ws="websend [192.168.178.86]" -timer=0 -hold=0 -toggle=0 -**\>B** -; gpio 5 button input -spinm(5,0) +**>D 25** -; fast section 100ms -**\>F** -sw=pin[5] -; 100 ms timer -timer+=1 +sw=0
ws="websend [192.168.178.86]"
timer=0
hold=0
toggle=0 -; 3 seconds long press -; below 0,5 short press -if sw==0 -and timer>5 -and timer<30 -then -; short press -;=>print short press -toggle^=1 -=>%ws% power1 %toggle% -endif +**>B** -if sw>0 -then -;pressed -if timer>30 -then -; hold -hold=1 -;=>print hold=%timer% -if toggle>0 -then -=>%ws% dimmer + -else -=>%ws% dimmer - -endif -endif -else -timer=0 -hold=0 -endif +; gpio 5 button input
spinm(5,0) +; fast section 100ms
**>F** + +sw=pin[5]
; 100 ms timer
timer+=1 + +; 3 seconds long press
; below 0,5 short press
if sw==0
and timer>5
and timer<30
then
; short press
;=>print short press
toggle^=1
=>%ws% power1 %toggle%
endif + +if sw>0
then
;pressed
if timer>30
then
; hold
hold=1
;=>print hold=%timer%
if toggle>0
then
=>%ws% dimmer +
else
=>%ws% dimmer -
endif
endif
else
timer=0
hold=0
endif [Back To Top](#top) @@ -766,74 +316,32 @@ endif #### Switching By Recognizing Mains Power Frequency [#6085 (comment)](../issues/6085#issuecomment-512353010) -**\>D** -sw1=0 -sw2=0 -cnt1=0 -cnt2=0 -timer1=0 -timer2=0 -toggle1=0 -toggle2=0 +**>D** + +sw1=0
sw2=0
cnt1=0
cnt2=0
timer1=0
timer2=0
toggle1=0
toggle2=0 + +**>B** -**\>B** =>print "WiFi 2-Gang Switch Script" -**\>F** -; Counter1/2 and Relay1/2 configured in template -cnt1=pc[1] -cnt2=pc[2] +**>F** -if chg[cnt1]>0 -then -; counter1 has changed, switch is on -sw1=1 -else -; no change switch is off -sw1=0 -endif +; Counter1/2 and Relay1/2 configured in template
cnt1=pc[1]
cnt2=pc[2] -if chg[cnt2]>0 -then -; counter2 has changed, switch is on -sw2=1 -else -; no change switch is off -sw2=0 -endif +if chg[cnt1]>0
then
; counter1 has changed, switch is on
sw1=1
else
; no change switch is off
sw1=0
endif -; 100 ms timer -timer1+=1 -timer2+=1 +if chg[cnt2]>0
then
; counter2 has changed, switch is on
sw2=1
else
; no change switch is off
sw2=0
endif -if sw1==0 -and timer1>2 -and timer1<30 -then -;=>print short press1 -toggle1^=1 -=>Power1 %toggle1% -endif +; 100 ms timer
timer1+=1
timer2+=1 -if sw1==0 -then -timer1=0 -endif +if sw1==0
and timer1>2
and timer1<30
then
;=>print short press1
toggle1^=1
=>Power1 %toggle1%
endif -if sw2==0 -and timer2>2 -and timer2<30 -then -;=>print short press2 -toggle2^=1 -=>Power2 %toggle2% -endif +if sw1==0
then
timer1=0
endif -if sw2==0 -then -timer2=0 -endif +if sw2==0
and timer2>2
and timer2<30
then
;=>print short press2
toggle2^=1
=>Power2 %toggle2%
endif + +if sw2==0
then
timer2=0
endif [Back To Top](#top) ------------------------------------------------------------------------------- \ No newline at end of file +------------------------------------------------------------------------------