<BR> issue resolved

Michael Ingraham 2019-07-28 15:02:51 -04:00
parent e66fd03178
commit 0417e43c14
1 changed files with 648 additions and 164 deletions

@ -16,107 +16,276 @@
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=&quot;hello world&quot;
string=&quot;xxx&quot;
url=&quot;[192.168.178.86]&quot;
hum=0
temp=0
timer=0
dimmer=0
sw=0
rssi=0
param=0
; define all vars here<BR>p:mintmp=10 (p:means permanent)<BR>p:maxtmp=30<BR>t:timer1=30 (t:means countdown timer)<BR>t:mt=0<BR>i:count=0 (i:means auto counter)<BR>hello=&quot;hello world&quot;<BR>string=&quot;xxx&quot;<BR>url=&quot;[192.168.178.86]&quot;<BR>hum=0<BR>temp=0<BR>timer=0<BR>dimmer=0<BR>sw=0<BR>rssi=0<BR>param=0
col=&quot;&quot;
ocol=&quot;&quot;
chan1=0
chan2=0
chan3=0
col=&quot;&quot;<BR>ocol=&quot;&quot;<BR>chan1=0<BR>chan2=0<BR>chan3=0
ahum=0<BR>atemp=0<BR>tcnt=0<BR>hour=0<BR>state=1<BR>m:med5=0<BR>M:movav=0<BR>; define array with 10 entries<BR>m:array=0 10
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
**>B**
string=hello+"how are you?"
=\>print BOOT executed
=\>print %hello%
=\>mp3track 1
string=hello+"how are you?"<BR>=\>print BOOT executed<BR>=\>print %hello%<BR>=\>mp3track 1
; list gpio pin definitions
for cnt 0 16 1
tmp=pd[cnt]
=>print %cnt% = %tmp%
next
; list gpio pin definitions<BR>for cnt 0 16 1<BR>tmp=pd[cnt]<BR>=>print %cnt% = %tmp%<BR>next
; get gpio pin for relais 1
tmp=pn[21]
=>print relais 1 is on pin %tmp%
; get gpio pin for relais 1<BR>tmp=pn[21]<BR>=>print relais 1 is on pin %tmp%
; pulse relais over raw gpio
spin(tmp 1)
delay(100)
spin(tmp 0)
; pulse relais over raw gpio<BR>spin(tmp 1)<BR>delay(100)<BR>spin(tmp 0)
; raw pin level
=>print level of gpio1 %pin[1]%
; raw pin level<BR>=>print level of gpio1 %pin[1]%
; pulse over tasmota cmd<BR>=>power 1<BR>delay(100)<BR>=>power 0
; pulse over tasmota cmd
=>power 1
delay(100)
=>power 0
**>T**
hum=BME280#Humidity
temp=BME280#Temperature
rssi=Wifi#RSSI
string=SleepMode
hum=BME280#Humidity<BR>temp=BME280#Temperature<BR>rssi=Wifi#RSSI<BR>string=SleepMode
; add to median filter
median=temp
; add to moving average filter
movav=hum
; add to median filter<BR>median=temp<BR>; add to moving average filter<BR>movav=hum
; show filtered results
=>print %median% %movav%
; show filtered results<BR>=>print %median% %movav%
if chg[rssi]>0
then =>print rssi changed to %rssi%
endif
if chg[rssi]>0<BR>then =>print rssi changed to %rssi%<BR>endif
if temp\>30<BR>and hum\>70<BR>then =\>print damn hot!<BR>endif
if temp\>30
and hum\>70
then =\>print damn hot!
endif
**>S**
; every second but not completely reliable time here
; use upsecs and uptime or best t: for reliable timers
; every second but not completely reliable time here<BR>; use upsecs and uptime or best t: for reliable timers
; arrays
array[1]=4
array[2]=5
tmp=array[1]+array[2]
; arrays<BR>array[1]=4<BR>array[2]=5<BR>tmp=array[1]+array[2]
; call subrountines with parameters
=#sub1("hallo")
=#sub2(999)
; call subrountines with parameters <BR>=#sub1("hallo")<BR>=#sub2(999)
; stop timer after expired
if timer1==0
then timer1=-1
=>print timer1 expired
endif
; stop timer after expired<BR>if timer1==0<BR>then timer1=-1<BR>=>print timer1 expired<BR>endif
; auto counter with restart
if count>=10
then =>print 10 seconds over
count=0
endif
; auto counter with restart<BR>if count>=10<BR>then =>print 10 seconds over<BR>count=0<BR>endif
if upsecs%5==0
then =\>print %upsecs% (every 5 seconds)
endif
if upsecs%5==0<BR>then =\>print %upsecs% (every 5 seconds)<BR>endif
; not recommended for reliable timers
timer+=1
if timer\>=5
then =\>print 5 seconds over (may be)
timer=0
endif
; not recommended for reliable timers<BR>timer+=1<BR>if timer\>=5<BR>then =\>print 5 seconds over (may be)<BR>timer=0<BR>endif
dimmer+=1
if dimmer\>100
then dimmer=0
endif
dimmer+=1<BR>if dimmer\>100<BR>then dimmer=0<BR>endif
=\>dimmer %dimmer%
=\>WebSend %url% dimmer %dimmer%
=\>dimmer %dimmer%<BR>=\>WebSend %url% dimmer %dimmer%
; show on display<BR>dp0<BR>=\>displaytext [c1l1f1s2p20] dimmer=%dimmer%
; show on display
dp0
=\>displaytext [c1l1f1s2p20] dimmer=%dimmer%
=\>print %upsecs% %uptime% %time% %sunrise% %sunset% %tstamp%
if time\>sunset<BR>and time< sunrise<BR>then<BR>; night time<BR>if pwr[1]==0<BR>then =\>power1 1<BR>endif<BR>else<BR>; day time<BR>if pwr[1]\>0<BR>then =\>power1 0<BR>endif<BR>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<BR>if boot\>0<BR>then =\>displaytext [z]<BR>endif
; clr display on boot
if boot\>0
then =\>displaytext [z]
endif
; frost warning<BR>if temp<0<BR>and mt<=0<BR>then =#sendmail("frost alert")<BR>; alarm only every 5 minutes<BR>mt=300<BR>=>mp3track 2<BR>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<BR>if upd[hello]>0<BR>then =>print %hello%<BR>endif
; var has been updated
if upd[hello]>0
then =>print %hello%
endif
; send to Thingspeak every 60 seconds<BR>; average data in between<BR>if upsecs%60==0 <BR>then<BR>ahum/=tcnt<BR>atemp/=tcnt<BR>=>Websend [184.106.153.149:80]/update?key=PYUZMVWCICBW492&field1=%atemp%&field2=%ahum%<BR>tcnt=0<BR>atemp=0<BR>ahum=0 <BR>else<BR>ahum+=hum<BR>atemp+=temp<BR>tcnt+=1<BR>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)<BR>if chg[hour]>0<BR>then<BR>; exactly every hour<BR>=>print full hour reached<BR>endif
hour=int(time/60)
if chg[hour]>0
then
; exactly every hour
=>print full hour reached
endif
if time>5 {<BR>=>print more then 5 minutes after midnight <BR>} else {<BR>=>print less then 5 minutes after midnight<BR>}
if time>5 {
=>print more then 5 minutes after midnight
} else {
=>print less then 5 minutes after midnight
}
; publish abs hum every teleperiod time<BR>if mqtts>0<BR>and upsecs%tper==0<BR>then<BR>; calc abs humidity<BR>tmp=pow(2.718281828 (17.67\*temp)/(temp+243.5))<BR>tmp=(6.112\*tmp\*hum\*18.01534)/((273.15+temp)\*8.31447215)<BR>; publish median filtered value<BR>=>Publish tele/%topic%/SENSOR {"Script":{"abshum":%med(0 tmp)%}}<BR>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 <BR>switch state<BR>case 1<BR>=>print state=%state% , start<BR>state+=1<BR>case 2<BR>=>print state=%state%<BR>state+=1<BR>case 3<BR>=>print state=%state% , reset<BR>state=1<BR>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<BR>\#sub1(string)<BR>=>print sub1: %string%<BR>\#sub2(param)<BR>=>print sub2: %param%
; subroutines
\#sub1(string)
=>print sub1: %string%
\#sub2(param)
=>print sub2: %param%
\#sendmail(string)<BR>=>sendmail [smtp.gmail.com:465:user:passwd:<sender@gmail.de>:<rec@gmail.de>:alarm] %string%
\#sendmail(string)
=>sendmail [smtp.gmail.com:465:user:passwd:<sender@gmail.de>:<rec@gmail.de>:alarm] %string%
**>E**
=\>print event executed!
; get HSBColor 1. component<BR>tmp=st(HSBColor , 1)
; get HSBColor 1. component
tmp=st(HSBColor , 1)
; check if switch changed state<BR>sw=sw[1]<BR>if chg[sw]>0<BR>then =\>power1 %sw%<BR>endif
; check if switch changed state
sw=sw[1]
if chg[sw]>0
then =\>power1 %sw%
endif
hello=&quot;event occured&quot;
; check for Color change (Color is a string)<BR>col=Color<BR>; color change needs 2 string vars<BR>if col!=ocol<BR>then ocol=col<BR>=>print color changed %col%<BR>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<BR>chan1=Channel[1]<BR>chan2=Channel[2]<BR>chan3=Channel[3]
; or check change of color channels
chan1=Channel[1]
chan2=Channel[2]
chan3=Channel[3]
if chg[chan1]>0<BR>or chg[chan2]>0<BR>or chg[chan3]>0<BR>then => color has changed<BR>endif
if chg[chan1]>0
or chg[chan2]>0
or chg[chan3]>0
then => color has changed
endif
; compose color string for red<BR>col=hn(255)+hn(0)+hn(0)<BR>=>color %col%
; compose color string for red
col=hn(255)+hn(0)+hn(0)
=>color %col%
**>R**
=\>print restarting now
[Back To Top](#top)
@ -124,96 +293,224 @@ if chg[chan1]>0<BR>or chg[chan2]>0<BR>or chg[chan3]>0<BR>then => color has chang
------------------------------------------------------------------------------
#### Log Sensor
; define all vars here<BR>; reserve large strings
; define all vars here
; reserve large strings
**>D 48**
hum=0<BR>temp=0<BR>fr=0<BR>res=0<BR>; moving average for 60 seconds<BR>M:mhum=0 60<BR>M:mtemp=0 60<BR>str=""
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 <BR>fl1("slog.txt")<BR>; delete file in case we want to start fresh<BR>;fd("slog.txt")
; 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<BR>fr=fo("/" 0)<BR>for cnt 1 20 1<BR>res=fr(str fr)<BR>if res>0<BR>then<BR>=>print %cnt% : %str%<BR>else<BR>break<BR>endif<BR>next<BR>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<BR>temp=BME280#Temperature<BR>hum=BME280#Humidity
; get sensor values
temp=BME280#Temperature
hum=BME280#Humidity
**>S**
; average sensor values every second
mhum=hum
mtemp=temp
; average sensor values every second<BR>mhum=hum<BR>mtemp=temp
; write average to sensor log every minute<BR>if upsecs%60==0<BR>then<BR>; open file for write<BR>fr=fo("slog.txt" 1)<BR>; compose string for tab delimited file entry<BR>str=s(upsecs)+"\t"+s(mhum)+"\t"+s(mtemp)+"\n"<BR>; write string to log file<BR>res=fw(str fr)<BR>; close file<BR>fc(fr)<BR>endif
; 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<BR>DisplayText substituted to save script space
Some vars are set from iobroker
DisplayText substituted to save script space
**>D**
hum=0<BR>temp=0<BR>press=0<BR>ahum=0<BR>tvoc=0<BR>eco2=0<BR>zwz=0<BR>wr1=0<BR>wr2=0<BR>wr3=0<BR>otmp=0<BR>pwl=0<BR>tmp=0<BR>DT="DisplayText"<BR>; preset units in case they are not available <BR>punit="hPa"<BR>tunit="C"
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<BR>=>%DT% [zD0]<BR>;clr display and draw a frame<BR>=>%DT% [x0y20h296x0y40h296]
;reset auto draw
=>%DT% [zD0]
;clr display and draw a frame
=>%DT% [x0y20h296x0y40h296]
**>T**
; get tele vars<BR>temp=BME280#Temperature<BR>hum=BME280#Humidity<BR>press=BME280#Pressure<BR>tvoc=SGP30#TVOC<BR>eco2=SGP30#eCO2<BR>ahum=SGP30#aHumidity<BR>tunit=TempUnit<BR>punit=PressureUnit
; 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
// update display every teleperiod time<BR>if upsecs%tper==0<BR>then<BR>dp2<BR>=>%DT% [f1p7x0y5]%temp% %tunit%<BR>=>%DT% [p5x70y5]%hum% %%[x250y5t] <BR>=>%DT% [p11x140y5]%press% %punit%<BR>=>%DT% [p10x30y25]TVOC: %tvoc% ppb<BR>=>%DT% [p10x160y25]eCO2: %eco2% ppm<BR>=>%DT% [p10c26l5]ahum: %ahum% g^m3
dp0<BR>=>%DT% [p25c1l5]WR 1 (Dach) : %wr1% W<BR>=>%DT% [p25c1l6]WR 2 (Garage): %-wr3% W<BR>=>%DT% [p25c1l7]WR 3 (Garten): %-wr2% W<BR>=>%DT% [p25c1l8]Aussentemperatur: %otmp% C<BR>=>%DT% [x170y95r120:30f2p6x185y100] %pwl% %%<BR>; now update screen<BR>=>%DT% [d]<BR>endif
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<BR>display switches on and off with proximity sensor
Shows various energy graphs
display switches on and off with proximity sensor
some vars are set from iobroker
**>D**
temp=0<BR>press=0<BR>zwz=0<BR>wr1=0<BR>wr2=0<BR>wr3=0<BR>otmp=0<BR>pwl=0<BR>tmp=0<BR>dist=0<BR>DT="DisplayText"<BR>punit="hPa"<BR>tunit="C"<BR>hour=0
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
**>B**
=>%DT% [z]
// define 2 graphs, 2. has 3 tracks<BR>=>%DT% [zCi1G2656:5:20:400:80:1440:-5000:5000:3Ci7f3x410y20]+5000 W[x410y95]-5000 W [Ci7f1x70y3] Zweirichtungsz~80hler - 24 Stunden<BR>=>%DT% [Ci1G2657:5:120:400:80:1440:0:5000:3Ci7f3x410y120]+5000 W[x410y195]0 W [Ci7f1x70y103] Wechselrichter 1-3 - 24 Stunden<BR>=>%DT% [Ci1G2658:5:120:400:80:1440:0:5000:16][Ci1G2659:5:120:400:80:1440:0:5000:5]<BR>=>%DT% [f1s1b0:260:260:100&#8203;:50:2:11:4:2:Rel 1:b1:370:260:100&#8203;:50:2:11:4:2:Dsp off:]<BR>=>mp3volume 100<BR>=>mp3track 4
// 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&#8203;:50:2:11:4:2:Rel 1:b1:370:260:100&#8203;:50:2:11:4:2:Dsp off:]
=>mp3volume 100
=>mp3track 4
**>T**
; get some tele vars
temp=BMP280#Temperature
press=BMP280#Pressure
tunit=TempUnit
punit=PressureUnit
dist=VL53L0X#Distance
; get some tele vars<BR>temp=BMP280#Temperature<BR>press=BMP280#Pressure<BR>tunit=TempUnit<BR>punit=PressureUnit<BR>dist=VL53L0X#Distance
; check proximity sensor to switch display on/off<BR>; to prevent burn in<BR>if dist>300<BR>then<BR>if pwr[2]>0<BR>then<BR>=>power2 0<BR>endif<BR>else<BR>if pwr[2]==0<BR>then<BR>=>power2 1<BR>endif<BR>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
**>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
; update graph every teleperiod<BR>if upsecs%tper==0<BR>then<BR>dp2<BR>=>%DT% [f1Ci3x40y260w30Ci1]<BR>=>%DT% [Ci7x120y220t]<BR>=>%DT% [Ci7x180y220T]<BR>=>%DT% [Ci7p8x120y240]%temp% %tunit% <BR>=>%DT% [Ci7x120y260]%press% %punit%<BR>=>%DT% [Ci7x120y280]%dist% mm<BR>dp0<BR>=>%DT% [g0:%zwz%g1:%wr1%g2:%-wr2%g3:%-wr3%]<BR>if zwz>0<BR>then<BR>=>%DT% [p-8x410y55Ci2Bi0]%zwz% W<BR>else<BR>=>%DT% [p-8x410y55Ci3Bi0]%zwz% W<BR>endif<BR>=>%DT% [p-8x410y140Ci3Bi0]%wr1% W<BR>=>%DT% [p-8x410y155Ci16Bi0]%-wr2% W<BR>=>%DT% [p-8x410y170Ci5Bi0]%-wr3% W<BR>endif
; chime every full hour<BR>hour=int(time/60)<BR>if chg[hour]>0<BR>then =>mp3track 4<BR>endif
; chime every full hour
hour=int(time/60)
if chg[hour]>0
then =>mp3track 4
endif
**>E**
**>R**
[Back To Top](#top)
------------------------------------------------------------------------------
@ -222,67 +519,177 @@ temp=0<BR>press=0<BR>zwz=0<BR>wr1=0<BR>wr2=0<BR>wr3=0<BR>otmp=0<BR>pwl=0<BR>tmp=
Used as display for solar house power input/output (+-5000 Watts)
**>D**
m:array=0 60 ;defines array for 60 led pixels<BR>cnt=0<BR>val=0<BR>ind=0<BR>; rgb values for grid<BR>colr1=0x050000<BR>colr2=0x050100<BR>colg1=0x000300<BR>colg2=0x020300<BR>ledbar=0<BR>blue=64<BR>pixels=60<BR>steps=10<BR>div=0<BR>tog=0<BR>max=5000<BR>min=-5000<BR>pos=0
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)
div=pixels/steps<BR>=#prep<BR>ws2812(array)
; ledbar is set from broker
; ledbar is set from broker<BR>**>S**
**>S**
if ledbar<min
then ledbar=min
endif
if ledbar<min<BR>then ledbar=min<BR>endif
if ledbar>max
then ledbar=max
endif
if ledbar>max<BR>then ledbar=max<BR>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
pos=(ledbar/max)*(pixels/2)<BR>if ledbar>0<BR>then<BR>pos+=(pixels/2)<BR>if pos>pixels-1<BR>then pos=pixels<BR>endif<BR>else<BR>pos+=(pixels/2)+1<BR>if pos>pixels-1<BR>then pos=1<BR>endif<BR>endif
if pos<1<BR>or pos>pixels<BR>then pos=1<BR>endif
if pos<1
or pos>pixels
then pos=1
endif
=#prep
if ledbar==0<BR>then<BR>array[pos]=blue<BR>array[pos-1]=blue<BR>else<BR>array[pos]=blue<BR>endif
if ledbar==0
then
array[pos]=blue
array[pos-1]=blue
else
array[pos]=blue
endif
; only used if power is off<BR>; so lets may be used normally if on<BR>if pwr[1]==0<BR>then<BR>ws2812(array)<BR>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<BR>#prep<BR>for cnt 1 pixels 1<BR>ind+=1<BR>if ind>div<BR>then ind=1<BR>tog^=1<BR>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<BR>then<BR>if tog>0<BR>then val=colr1<BR>else val=colr2<BR>endif<BR>else<BR>if tog>0<BR>then val=colg1<BR>else val=colg2<BR>endif<BR>endif<BR>array[cnt]=val<BR>next
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<BR>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]"
istr=""<BR>ws="websend [192.168.178.84]"
; event section
; event section<BR>**>E**
**>E**
; get ir data
istr=IrReceived#Data
; get ir data<BR>istr=IrReceived#Data
; on
if istr=="0x00F7C03F"
then
=>wakeup
=>%ws% wakeup
endif
; on<BR>if istr=="0x00F7C03F"<BR>then<BR>=>wakeup<BR>=>%ws% wakeup<BR>endif
; off
if istr=="0x00F740BF"
then
=>power1 0
=>%ws% power1 0
endif
; off<BR>if istr=="0x00F740BF"<BR>then<BR>=>power1 0<BR>=>%ws% power1 0<BR>endif
;white
if istr=="0x00F7E01F"
then
=>color 000000ff
=>%ws% color 000000ff
endif
;white<BR>if istr=="0x00F7E01F"<BR>then<BR>=>color 000000ff<BR>=>%ws% color 000000ff<BR>endif
;red
if istr=="0x00F720DF"
then
=>color ff000000
=>%ws% color ff000000
endif
;red<BR>if istr=="0x00F720DF"<BR>then<BR>=>color ff000000<BR>=>%ws% color ff000000<BR>endif
;green
if istr=="0x00F7A05F"
then
=>color 00ff0000
=>%ws% color 00ff0000
endif
;green<BR>if istr=="0x00F7A05F"<BR>then<BR>=>color 00ff0000<BR>=>%ws% color 00ff0000<BR>endif
;blue
if istr=="0x00F7609F"
then
=>color 0000ff00
=>%ws% color 0000ff00
endif
;blue<BR>if istr=="0x00F7609F"<BR>then<BR>=>color 0000ff00<BR>=>%ws% color 0000ff00<BR>endif
; dimmer up
if istr=="0x00F700FF"
then
=>dimmer +
=>%ws% dimmer +
endif
; dimmer up<BR>if istr=="0x00F700FF"<BR>then<BR>=>dimmer +<BR>=>%ws% dimmer +<BR>endif
;dimmer down<BR>if istr=="0x00F7807F"<BR>then<BR>=>dimmer -<BR>=>%ws% dimmer -<BR>endif
;dimmer down
if istr=="0x00F7807F"
then
=>dimmer -
=>%ws% dimmer -
endif
istr=""
@ -294,20 +701,54 @@ istr=""
; expand strings to hold websend
**>D 25**
sw=0<BR>ws="websend [192.168.178.86]"<BR>timer=0<BR>hold=0<BR>toggle=0
sw=0
ws="websend [192.168.178.86]"
timer=0
hold=0
toggle=0
**>B**
; gpio 5 button input
spinm(5,0)
; gpio 5 button input<BR>spinm(5,0)
; fast section 100ms
; fast section 100ms<BR>**>F**
**>F**
sw=pin[5]
; 100 ms timer
timer+=1
sw=pin[5]<BR>; 100 ms timer<BR>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
; 3 seconds long press<BR>; below 0,5 short press<BR>if sw==0<BR>and timer>5<BR>and timer<30<BR>then<BR>; short press<BR>;=>print short press<BR>toggle^=1<BR>=>%ws% power1 %toggle%<BR>endif
if sw>0<BR>then<BR>;pressed<BR>if timer>30<BR>then<BR>; hold<BR>hold=1<BR>;=>print hold=%timer%<BR>if toggle>0<BR>then<BR>=>%ws% dimmer +<BR>else<BR>=>%ws% dimmer -<BR>endif<BR>endif<BR>else<BR>timer=0<BR>hold=0<BR>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)
@ -317,31 +758,74 @@ if sw>0<BR>then<BR>;pressed<BR>if timer>30<BR>then<BR>; hold<BR>hold=1<BR>;=>pri
[#6085 (comment)](../issues/6085#issuecomment-512353010)
**>D**
sw1=0<BR>sw2=0<BR>cnt1=0<BR>cnt2=0<BR>timer1=0<BR>timer2=0<BR>toggle1=0<BR>toggle2=0
sw1=0
sw2=0
cnt1=0
cnt2=0
timer1=0
timer2=0
toggle1=0
toggle2=0
**>B**
=>print "WiFi 2-Gang Switch Script"
**>F**
; Counter1/2 and Relay1/2 configured in template
cnt1=pc[1]
cnt2=pc[2]
; Counter1/2 and Relay1/2 configured in template<BR>cnt1=pc[1]<BR>cnt2=pc[2]
if chg[cnt1]>0
then
; counter1 has changed, switch is on
sw1=1
else
; no change switch is off
sw1=0
endif
if chg[cnt1]>0<BR>then<BR>; counter1 has changed, switch is on<BR>sw1=1<BR>else<BR>; no change switch is off<BR>sw1=0<BR>endif
if chg[cnt2]>0
then
; counter2 has changed, switch is on
sw2=1
else
; no change switch is off
sw2=0
endif
if chg[cnt2]>0<BR>then<BR>; counter2 has changed, switch is on<BR>sw2=1<BR>else<BR>; no change switch is off<BR>sw2=0<BR>endif
; 100 ms timer
timer1+=1
timer2+=1
; 100 ms timer<BR>timer1+=1<BR>timer2+=1
if sw1==0
and timer1>2
and timer1<30
then
;=>print short press1
toggle1^=1
=>Power1 %toggle1%
endif
if sw1==0<BR>and timer1>2<BR>and timer1<30<BR>then<BR>;=>print short press1<BR>toggle1^=1<BR>=>Power1 %toggle1%<BR>endif
if sw1==0
then
timer1=0
endif
if sw1==0<BR>then<BR>timer1=0<BR>endif
if sw2==0
and timer2>2
and timer2<30
then
;=>print short press2
toggle2^=1
=>Power2 %toggle2%
endif
if sw2==0<BR>and timer2>2<BR>and timer2<30<BR>then<BR>;=>print short press2<BR>toggle2^=1<BR>=>Power2 %toggle2%<BR>endif
if sw2==0<BR>then<BR>timer2=0<BR>endif
if sw2==0
then
timer2=0
endif
[Back To Top](#top)
------------------------------------------------------------------------------<BR>
------------------------------------------------------------------------------