diff --git a/Script-Cookbook.md b/Script-Cookbook.md index 7c17cbe5..b83901b5 100644 --- a/Script-Cookbook.md +++ b/Script-Cookbook.md @@ -1,5 +1,19 @@ -***example script*** (actually this code is too large) -meant to show some of the possibilities + +- [Scripting Language Example](Scripting-Language-Example) +- [Log Sensor](Log-Sensor) +- [ePaper 29 Display with SGP30 and BME280](ePaper-29-Display-with-SGP30-and-BME280) +- [ILI 9488 Color LCD Display with BMP280 and VL5310X](ILI-9488-Color-LCD-Display-with-BMP280-and-VL5310X) +- [Multiple IR Receiver Synchronization](Multiple-IR-Receiver-Synchronization) +- [Fast Polling](Fast-Polling) +- [Switching By Recognizing Mains Power Frequency](Switching-By-Recognizing-Mains-Power-Frequency) + + +[Back To Top](#top) + +------------------------------------------------------------------------------ + +#### Scripting Language Example +Actually this code is too large. This is meant to show some of the possibilities **\>D** ; define all vars here @@ -276,7 +290,12 @@ col=hn(255)+hn(0)+hn(0) **\>R** =\>print restarting now -**a log sensor example** + +[Back To Top](#top) + +------------------------------------------------------------------------------ + +#### Log Sensor ; define all vars here ; reserve large strings **\>D** 48 @@ -336,9 +355,11 @@ endif **\>R** +[Back To Top](#top) -**a real example** -epaper 29 with sgp30 and bme280 +------------------------------------------------------------------------------ + +#### ePaper 29 Display with SGP30 and BME280 some vars are set from iobroker DisplayText substituted to save script space **\>D** @@ -404,10 +425,15 @@ endif **\>R** -**another real example** -ILI 9488 color LCD Display shows various energy graphs + +[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 -BMP280 and vl5310x + some vars are set from iobroker **>D** @@ -493,4 +519,216 @@ endif **>E** -**>R** \ No newline at end of file +**>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 + +; 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 + +; on +if istr=="0x00F7C03F" +then +=>wakeup +=>%ws% wakeup +endif + +; off +if istr=="0x00F740BF" +then +=>power1 0 +=>%ws% power1 0 +endif + +;white +if istr=="0x00F7E01F" +then +=>color 000000ff +=>%ws% color 000000ff +endif + +;red +if istr=="0x00F720DF" +then +=>color ff000000 +=>%ws% color ff000000 +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) + +; 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) + +------------------------------------------------------------------------------ + +#### 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 + +>B +=>print "WiFi 2-Gang Switch Script" + +>F +; Counter1/2 and Relay1/2 configured in template +cnt1=pc[1] +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[cnt2]>0 +then +; counter2 has changed, switch is on +sw2=1 +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 +then +;=>print short press1 +toggle1^=1 +=>Power1 %toggle1% +endif + +if sw1==0 +then +timer1=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) + +------------------------------------------------------------------------------ +