From 1d85c1669fa7b9e5478143385aad08b93bbbfbc4 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 1 Jul 2018 21:48:20 +0200 Subject: [PATCH] =?UTF-8?q?import=20regu=C5=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rules/README | 5 ++ rules/WC.txt | 8 +++ rules/d1mini03.prototyp.rules | 49 ++++++++++++++++ rules/kuchnia.okap.rules | 64 +++++++++++++++++++++ rules/kuchnia.rules | 12 ++++ rules/przedpokój.rules | 53 ++++++++++++++++++ rules/salon.cottonballs.rules | 51 +++++++++++++++++ rules/salon.kodi.rules | 45 +++++++++++++++ rules/salon.lampka-stolowa.rules | 90 ++++++++++++++++++++++++++++++ rules/salon.mpd-concat.rules | 7 +++ rules/sypialnia.lampka-nocna.rules | 27 +++++++++ rules/wc.rules | 26 +++++++++ rules/łazienka.rules | 29 ++++++++++ 13 files changed, 466 insertions(+) create mode 100644 rules/README create mode 100644 rules/WC.txt create mode 100644 rules/d1mini03.prototyp.rules create mode 100644 rules/kuchnia.okap.rules create mode 100644 rules/kuchnia.rules create mode 100644 rules/przedpokój.rules create mode 100644 rules/salon.cottonballs.rules create mode 100644 rules/salon.kodi.rules create mode 100644 rules/salon.lampka-stolowa.rules create mode 100644 rules/salon.mpd-concat.rules create mode 100644 rules/sypialnia.lampka-nocna.rules create mode 100644 rules/wc.rules create mode 100644 rules/łazienka.rules diff --git a/rules/README b/rules/README new file mode 100644 index 0000000..7fb9e0f --- /dev/null +++ b/rules/README @@ -0,0 +1,5 @@ +Put any file containing rule definitions here. They will be activated automatically. + +Note: Rule definition files must have the extension '*.rules' + +Demo-files can be obtained from the archive 'distribution-demo-*.zip'. diff --git a/rules/WC.txt b/rules/WC.txt new file mode 100644 index 0000000..1381dbc --- /dev/null +++ b/rules/WC.txt @@ -0,0 +1,8 @@ + +co minute odczyt czujnika swiatla +jesli jasno -> switch wc_occupied ON + +rule wc_occupied changed to off -> psiknij (GPIO short pulse pewnie) + +jakies timery, ze jesli jestesmy w domu to psikaj co godzine, +przed naszym przyjsciem, rano przy budziku diff --git a/rules/d1mini03.prototyp.rules b/rules/d1mini03.prototyp.rules new file mode 100644 index 0000000..e99d217 --- /dev/null +++ b/rules/d1mini03.prototyp.rules @@ -0,0 +1,49 @@ + +rule "d1m03 przełączaj zielone" +when + Item sD1MINI03_button_green received update +then + if (sOWFS01.state == ON) { + sOWFS01.sendCommand(OFF) + } else { + sOWFS01.sendCommand(ON) + } +end + +rule "d1m03 przełączaj żółte" +when + Item sD1MINI03_button_yellow received update +then + if (Mpd_quodlibet_StartStop.state == ON) { + Mpd_quodlibet_StartStop.sendCommand(OFF) + } else { + Mpd_quodlibet_StartStop.sendCommand(ON) + } +end + + +rule "d1m03 przełączaj czerwone" +when + Item sD1MINI03_button_red received update +then +/* if (sD1MINI04_refresh.state == ON) { + sD1MINI04_refresh.sendCommand(OFF) + } else {*/ + sD1MINI04_refresh.sendCommand(ON) +/* }*/ +end + + +rule "d1mini03 synchronizuj kolorki" +when + Item sOWFS01 received update or + Item Mpd_quodlibet_StartStop received update or + Item sD1MINI04_refresh received update +then + sD1MINI03_light_green.sendCommand(sOWFS01.state.toString()) + + sD1MINI03_light_yellow.sendCommand(Mpd_quodlibet_StartStop.state.toString()) + + sD1MINI03_light_red.sendCommand(sD1MINI04_refresh.state.toString()) +end + diff --git a/rules/kuchnia.okap.rules b/rules/kuchnia.okap.rules new file mode 100644 index 0000000..cd2feb1 --- /dev/null +++ b/rules/kuchnia.okap.rules @@ -0,0 +1,64 @@ + +/* +example of switch https://community.openhab.org/t/examples-of-scenes/16411/5 +*/ + +/* 0="OFF", 1="Bieg 1", 2="Bieg 2", 3="Bieg max"] +*/ + +rule "Ustaw prędkość okapu" +when + Item sOKAP_speed received update +then + switch (sOKAP_speed.state) { + case 0: { + sD1MINI01_bieg1.sendCommand(OFF) + sD1MINI01_bieg2.sendCommand(OFF) + sD1MINI01_bieg3.sendCommand(OFF) + } + + case 1: { + sD1MINI01_bieg1.sendCommand(ON) + sD1MINI01_bieg2.sendCommand(OFF) + sD1MINI01_bieg3.sendCommand(OFF) + } + /* 40% = 1 bieg */ + case 40: { + sD1MINI01_bieg1.sendCommand(ON) + sD1MINI01_bieg2.sendCommand(OFF) + sD1MINI01_bieg3.sendCommand(OFF) + } + /* turn ON == 100% == 1 bieg */ + case 100: { + sD1MINI01_bieg1.sendCommand(ON) + + sD1MINI01_bieg2.sendCommand(OFF) + sD1MINI01_bieg3.sendCommand(OFF) + } + + case 2: { + sD1MINI01_bieg2.sendCommand(ON) + + sD1MINI01_bieg1.sendCommand(OFF) + sD1MINI01_bieg3.sendCommand(OFF) + } + /* 70% = 2 bieg */ + case 70: { + sD1MINI01_bieg2.sendCommand(ON) + + sD1MINI01_bieg1.sendCommand(OFF) + sD1MINI01_bieg3.sendCommand(OFF) + } + + case 3: { + sD1MINI01_bieg3.sendCommand(ON) + + sD1MINI01_bieg1.sendCommand(OFF) + sD1MINI01_bieg2.sendCommand(OFF) + } + default: { + logInfo("okap","incorrect state: {}", sOKAP_speed.state) + } + } + +end diff --git a/rules/kuchnia.rules b/rules/kuchnia.rules new file mode 100644 index 0000000..7d4f846 --- /dev/null +++ b/rules/kuchnia.rules @@ -0,0 +1,12 @@ + +rule "Kuchnia: przełącz LED" +when + Item sD1MINI02LEDS received update +then + if (sD1MINI02MOS.state == ON) { + sD1MINI02MOS.sendCommand(OFF) + /* zrobic PWM DIMM */ + } else { + sD1MINI02MOS.sendCommand(ON) + } +end diff --git a/rules/przedpokój.rules b/rules/przedpokój.rules new file mode 100644 index 0000000..c3f92ef --- /dev/null +++ b/rules/przedpokój.rules @@ -0,0 +1,53 @@ + +rule "Przedpokój: przełącz światło" +when + /* If there is no action the button returns 0. When you touch it it shows a state of 1 . */ + Item sSONOFF06KEY received update ON or + Item sD1MINI06KEY received update +then + if (sSONOFF06.state == ON) { + sSONOFF06.sendCommand(OFF) + } else { + sSONOFF06.sendCommand(ON) + } +end + + +/* podswietlenie bedzie caly czas ON, ustawione jako dioda statusu */ +/*rule "Przedpokój: synchronizuj podświetlenia przycisków" +when + Item sSONOFF06 received update +then + if (sSONOFF06.state == ON) { + sSONOFF06LED.sendCommand(OFF) + sD1MINI03_light_red.sendCommand(OFF) + } else { + sSONOFF06LED.sendCommand(ON) + sD1MINI03_light_red.sendCommand(ON) + } +end*/ + + +/* jak się urwie od internetu przyciskowi, zsynchronizuj stan światła na OFF */ +when + Item rSONOFF06 received update OFF +then + sSONOFF06.postUpdate(OFF) +end + + + +rule "Przedpokój: zapal rano" +when + Time cron "0 50 5 ? * MON-FRI *" +then + sSONOFF06.sendCommand(ON) +end + +rule "Przedpokój: zgaś rano" +when + Time cron "0 50 6 ? * MON-FRI *" +then + sSONOFF06.sendCommand(OFF) +end + diff --git a/rules/salon.cottonballs.rules b/rules/salon.cottonballs.rules new file mode 100644 index 0000000..8a4c8ca --- /dev/null +++ b/rules/salon.cottonballs.rules @@ -0,0 +1,51 @@ + +rule "Zapal cottonballs, kanapowe i blat rano" +when + Time cron "0 45 5 ? * MON-FRI *" +then + sOWFS01.sendCommand(ON) +/* sSONOFF01.sendCommand(ON) */ + sD1MINI02MOS.sendCommand(ON) +end + +rule "Zgaś cottonballs, kanapowe i blat rano" +when + Time cron "0 35 6 * * ?" +then + sOWFS01.sendCommand(OFF) + sSONOFF01.sendCommand(OFF) + sD1MINI02MOS.sendCommand(OFF) +end + +/* kanapowe zmierzchowe sterowane z lampki stolowej */ + +rule "Zapal cottonballsy i blat przed zmierzchem" +when + Item sSunset_Event_in_hour received update ON +then + sOWFS01.sendCommand(ON) + sOWFS01_expected.postUpdate(ON) + +/* HOLIDAY */ + D1MINI02MOS.sendCommand(ON) +end + +rule "Zgaś cottonballsy wieczorem" +when + Time cron "0 20 22 * * ?" +then + sOWFS01.sendCommand(OFF) + sOWFS01_expected.postUpdate(OFF) +end + + + +/* +1 Seconds +2 Minutes +3 Hours +4 Day-of-Month +5 Month +6 Day-of-Week +7 Year (optional field) +*/ diff --git a/rules/salon.kodi.rules b/rules/salon.kodi.rules new file mode 100644 index 0000000..24668b7 --- /dev/null +++ b/rules/salon.kodi.rules @@ -0,0 +1,45 @@ + + +rule "Gramy!" +when + Item Kodi_State changed to Play +then + sOWFS01.sendCommand(OFF) + + Mpd_quodlibet_StartStop_expected.postUpdate(Mpd_quodlibet_StartStop.state) + Mpd_quodlibet_StartStop.sendCommand(OFF) +end + + +rule "Nie gramy" +when + Item Kodi_State changed to Stop or + Item Kodi_State changed to Pause +then + /* bezpośrednie odwoływanie się do tych zmiennych powoduje jakieś nulle */ + var preCB = sOWFS01_expected.state.toString() +/* ponizsze generuje w linijce z ifem: The name ' == ' cannot be resolved to an item or type. + var OnOffType preQL = Mpd_quodlibet_StartStop_expected.state */ + var preQL = Mpd_quodlibet_StartStop_expected.state.toString() + + logInfo("niegramy", "Restore QL to {}", preQL) +/* Mpd_quodlibet_StartStop.sendCommand(preQL.toString())*/ +/* nie działa: preQL as StringType + preQL.toString() +*/ + if (preQL == "ON") { + sendCommand(Mpd_quodlibet_StartStop, ON) + } else { +// logInfo("niegramy", "Did not restore QL. why?") + } + + logInfo("niegramy", "Restore sOWFS01 to {}", preCB) +/* sOWFS01.sendCommand(preCB) */ +/* sOWFS01.sendCommand(sOWFS01_expected.state.toString()) zakomentowane, bo null instance */ +/* sendCommand(sOWFS01, preCB) */ + if (preCB == "ON") { + sendCommand(sOWFS01, ON) + } + +end + diff --git a/rules/salon.lampka-stolowa.rules b/rules/salon.lampka-stolowa.rules new file mode 100644 index 0000000..34ab9b1 --- /dev/null +++ b/rules/salon.lampka-stolowa.rules @@ -0,0 +1,90 @@ + +/* +rule "Zapal stółlampkę rano" +when + Time cron "0 47 5 ? * MON-FRI *" +then + sSONOFF02.sendCommand(ON) +end +*/ + + +rule "Zgaś stółlampkę rano" +when + Time cron "0 30 6 * * ?" +then + sSONOFF02.sendCommand(OFF) +end + + + +rule "Zapal sufitowe przed zachodem" +when + Item sSunset_Event_in_hour received update ON +then +/* HOLIDAY */ + sD1MINI01_lampki_sufitowe.sendCommand(ON) +end + + + +rule "Zapal lampkę i kanapowe przed zmierzchem" +when + Item sSunset_Event_in_halfhour received update ON +then + dSONOFF01LED.sendCommand(0) + dSONOFF02LED.sendCommand(0) + Thread::sleep(500) + dSONOFF01LED.sendCommand(1023) + dSONOFF02LED.sendCommand(1023) + Thread::sleep(500) + + dSONOFF01LED.sendCommand(0) + dSONOFF02LED.sendCommand(0) + Thread::sleep(500) + dSONOFF01LED.sendCommand(1023) + dSONOFF02LED.sendCommand(1023) + Thread::sleep(500) + + dSONOFF01LED.sendCommand(0) + dSONOFF02LED.sendCommand(0) + Thread::sleep(500) + dSONOFF01LED.sendCommand(1023) + dSONOFF02LED.sendCommand(1023) + Thread::sleep(500) + + sSONOFF02.sendCommand(ON) + sSONOFF02_expected.postUpdate(ON) + + sSONOFF01.sendCommand(ON) +end + +rule "Przedzgaś stółlampkę wieczorem" +when + Time cron "0 12 22 * * ?" +then + dSONOFF01LED.sendCommand(0) + dSONOFF02LED.sendCommand(0) +end + +rule "Zgaś stółlampkę i kanapowe wieczorem" +when + Time cron "0 15 22 * * ?" +then + sSONOFF02.sendCommand(OFF) + sSONOFF02_expected.postUpdate(OFF) + dSONOFF02LED.sendCommand(1023) + + sSONOFF01.sendCommand(OFF) + dSONOFF01LED.sendCommand(1023) +end + +/* +1 Seconds +2 Minutes +3 Hours +4 Day-of-Month +5 Month +6 Day-of-Week +7 Year (optional field) +*/ diff --git a/rules/salon.mpd-concat.rules b/rules/salon.mpd-concat.rules new file mode 100644 index 0000000..3767644 --- /dev/null +++ b/rules/salon.mpd-concat.rules @@ -0,0 +1,7 @@ +rule "mpd-concat" +when + Item Mpd_CurrentTrack received update or + Item Mpd_CurrentArtist received update +the + Mpd_ConcatInfo.postUpdate(Mpd_CurrentTrack.state.toString + " / " + Mpd_CurrentArtist.state.toString) +end diff --git a/rules/sypialnia.lampka-nocna.rules b/rules/sypialnia.lampka-nocna.rules new file mode 100644 index 0000000..01292ba --- /dev/null +++ b/rules/sypialnia.lampka-nocna.rules @@ -0,0 +1,27 @@ + + +rule "Zapal lampkę rano" +when + Time cron "0 39 5 ? * MON-FRI *" +then + sOWFS02.sendCommand(ON) +end + + +rule "Zgaś lampkę rano" +when + Time cron "0 20 6 * * ?" +then + sOWFS02.sendCommand(OFF) +end + + +/* +1 Seconds +2 Minutes +3 Hours +4 Day-of-Month +5 Month +6 Day-of-Week +7 Year (optional field) +*/ diff --git a/rules/wc.rules b/rules/wc.rules new file mode 100644 index 0000000..da9d489 --- /dev/null +++ b/rules/wc.rules @@ -0,0 +1,26 @@ + +rule "Sprawdzaj zajętość WC" +when + Item lWC_lux received update +then + if (lWC_lux.state > 3) { + sWC_occupied.postUpdate(ON) + } else { + sWC_occupied.postUpdate(OFF) + } +end + +/* HOLIDAY */ + +rule "Psikaj w WC" +when + Item sWC_occupied changed from ON to OFF or + Time cron "0 50 05 * * ?" or + Time cron "0 20 15 ? * MON-FRI" or + Time cron "0 10/20 15-21 ? * MON-FRI" or + Time cron "0 0,20,40 8-22 ? * SAT,SUN" +then + sD1MINI04_refresh.sendCommand(ON) +end + + diff --git a/rules/łazienka.rules b/rules/łazienka.rules new file mode 100644 index 0000000..4eafc9a --- /dev/null +++ b/rules/łazienka.rules @@ -0,0 +1,29 @@ + +val int h_low = 55 +val int h_high = 65 + +rule "Włącz wiatrak przy dużej wilgotności" +when + Item h_lazienka received update +then + + if (h_lazienka.state > h_high) { + /* wlaczyc wiatrak i diodke */ + sSONOFF03.sendCommand(ON) + dSONOFF03LED.sendCommand(0) + + else if (h_lazienka.state < h_low) { + sSONOFF03.sendCommand(OFF) + dSONOFF03LED.sendCommand(1023) + + else { + /* pomiedzy 55 a 65 */ + val h_lazienka_int = h_lazienka.state as Number + var led_pwm = (h_high - h_lazienka_int) * ( 1023 / (h_high - h_low) ) + if (led_pwm < 0) { led_pwm = 0 } + + dSONOFF03LED.sendCommand(led_pwm) + } +end + +/* if dzien roboczy 7-15, wlacz wiatrak */