From 918a571b5cb0fe87f3d361b32aac2d172dfc53bb Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Fri, 9 Sep 2022 16:53:19 +0200 Subject: [PATCH] debbuging hooks --- hooks/notifiers/notificationfreemobile.php | 1 + hooks/scripts/etage_temperature_int_ext.php | 22 +- hooks/scripts/rdc_chambre_eclairage.php | 6 +- hooks/scripts/rdc_salon_eclairage.php | 7 +- hooks/scripts/rdc_sdb_eclairage.php | 9 +- hooks/scripts/rdc_store.php | 274 ++++++++++---------- hooks/scripts/rdc_store.php~ | 274 ++++++++++---------- 7 files changed, 304 insertions(+), 289 deletions(-) diff --git a/hooks/notifiers/notificationfreemobile.php b/hooks/notifiers/notificationfreemobile.php index abf15d5..fbc1700 100644 --- a/hooks/notifiers/notificationfreemobile.php +++ b/hooks/notifiers/notificationfreemobile.php @@ -19,6 +19,7 @@ class notificationFreemobile function send($message, $destinataire=NOTIF_DEFAULT_DEST) { + logger(DEBUG, _("Function send SMS (with Curl)"), __FILE__ . ":" . __LINE__); $error = false; if ($this->active === true) { diff --git a/hooks/scripts/etage_temperature_int_ext.php b/hooks/scripts/etage_temperature_int_ext.php index cea8a59..c062b9e 100644 --- a/hooks/scripts/etage_temperature_int_ext.php +++ b/hooks/scripts/etage_temperature_int_ext.php @@ -9,14 +9,22 @@ class etage_temperature_int_ext extends hook protected $devicelist = array( - METEO=> "tempc", - ); + METEO=> "tempc", + ); protected $portesList = array( - ENTREE_PORTE => "contact", - //GARAGE_PORTE => "contact", - RDC_CHAMBRE_BAIE => "contact", - RDC_SALON_BAIE => "contact" + ETAGE_BUREAU_FENETRE => "contact", + ETAGE_CHAMBRE_FENETRE => "contact", + ETAGE_SALON_FENETRE => "contact", + ETAGE_CUISINE_FENETRE => "contact", + ETAGE_PORTE_FENETRE => "contact" + ); + + protected $paires = array( + ETAGE_BUREAU_TEMP => ETAGE_BUREAU_FENETRE, + ETAGE_SALON_TEMP => ETAGE_SALON_FENETRE, + ETAGE_SALON_TEMP => ETAGE_PORTE_FENETRE, + ETAGE_CHAMBRE_TEMP => ETAGE_CHAMBRE_FENETRE ); function installHooks(&$indexDevices) @@ -37,8 +45,6 @@ class etage_temperature_int_ext extends hook logger(DEBUG, _("etage_temperature_int_ext hook"), null ,$device); if (empty($time)) $time = now(); - //echo "Time is " . var_dump($time) . EOL; - //echo "minutes since time :" . now()->format("U") - $time->format("U"); if ((now()->format("U") - $time->format("U")) > 300) { diff --git a/hooks/scripts/rdc_chambre_eclairage.php b/hooks/scripts/rdc_chambre_eclairage.php index 62a682c..33ed6a2 100644 --- a/hooks/scripts/rdc_chambre_eclairage.php +++ b/hooks/scripts/rdc_chambre_eclairage.php @@ -71,15 +71,15 @@ class rdc_chambre_eclairage extends hook { logger(DEBUG, _("CASE: state => value = 'OFF'"), __FILE__ . ":" . __LINE__); $targetAmbiance->properties[$property]["method"] = IDLE; - removeEvent($targetAmbiance, $property, "OFF", IDLE); + removeEvent($targetAmbiance, $property, "OFF"); } }elseif ($property == "state_l1") { if ($value == "OFF") { logger(DEBUG, _("CASE: state_l1 => value = 'OFF'"), __FILE__ . ":" . __LINE__); - //$targetEclairage->properties[$property]["method"] = IDLE; - removeEvent($targetAmbiance, $property, "OFF", IDLE); + $targetEclairage->properties[$property]["method"] = IDLE; + removeEvent($targetAmbiance, $property, "OFF"); } }elseif ($property == "action") { diff --git a/hooks/scripts/rdc_salon_eclairage.php b/hooks/scripts/rdc_salon_eclairage.php index bdb9986..7d28a24 100644 --- a/hooks/scripts/rdc_salon_eclairage.php +++ b/hooks/scripts/rdc_salon_eclairage.php @@ -44,10 +44,9 @@ class rdc_salon_eclairage extends hook switch($param) { case "presence": - logger(INFO, _("CASE: Présence => ") . bool2string($value), __FILE__ . ":" . __LINE__); case "occupancy": $method = $deviceTarget->properties["state"]["method"]; - logger(INFO, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__); + logger(INFO, sprintf (_("CASE: %s => "), $param) . bool2string($value), __FILE__ . ":" . __LINE__); //print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux")); if ($value == ON and $method == IDLE) { @@ -60,8 +59,8 @@ class rdc_salon_eclairage extends hook } }else { - logger(INFO, _("Value is OFF"), __FILE__ . ":" . __LINE__); - if (testActionneurs($this->actionneurs) === false and $method == AUTO) + logger(INFO, _("Value is OFF and method is ") . $method, __FILE__ . ":" . __LINE__); + if ((testActionneurs($this->actionneurs) == false) and ($method == AUTO)) //if ((getValue(RDC_SALON_MVMT, "occupancy") == OFF) and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF) and $method == AUTO) { logger(INFO, _("Setting to OFF"), __FILE__ . ":" . __LINE__); diff --git a/hooks/scripts/rdc_sdb_eclairage.php b/hooks/scripts/rdc_sdb_eclairage.php index fb42354..1d6acfa 100644 --- a/hooks/scripts/rdc_sdb_eclairage.php +++ b/hooks/scripts/rdc_sdb_eclairage.php @@ -71,23 +71,24 @@ class rdc_sdb_eclairage extends hook if ($method == IDLE) { logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__); - removeEvent($deviceTarget, "state_l1", "OFF", MANUAL); + removeEvent($deviceTarget, "state_l1", "OFF"); + $deviceTarget->properties["state_l1"]["method"] = MANUAL; //setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE); } }elseif ($value == "OFF") { - removeEvent($deviceTarget, "state_l1", "OFF", IDLE); + $deviceTarget->properties["state_l1"]["method"] = IDLE; + removeEvent($deviceTarget, "state_l1", "OFF"); //$deviceTarget->properties["state_l1"]["method"] = IDLE; logger(DEBUG, _("State_l1 is false light is off and method is ") . $method, __FILE__ . ":" . __LINE__); } break; } - logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__); + logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s method: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value), $deviceTarget->properties["state_l1"]["method"]), __FILE__ . ":" . __LINE__); }else { logger (ERROR, RDC_SDB_WC_ECLAIRAGE . _(" does not exists"), __FILE__ . ":" . __LINE__); } - } private function send($state, $method) diff --git a/hooks/scripts/rdc_store.php b/hooks/scripts/rdc_store.php index 254ede4..f3d6eeb 100644 --- a/hooks/scripts/rdc_store.php +++ b/hooks/scripts/rdc_store.php @@ -45,7 +45,6 @@ class rdc_store extends hook $rafale = 0; $soleil = 0; $storeDevice = $indexDevices[RDC_STORE]; - //$this->maxLevel = 100; $r = 100; $moving = "STOP"; $store2level = false; @@ -67,151 +66,159 @@ class rdc_store extends hook logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__); } - if ($moving == "STOP" or $moving == null) + if (array_key_exists(METEO, $indexDevices)) { - if (array_key_exists("position", $storeDevice->properties)) + if (array_key_exists("rainin", $indexDevices[METEO]->properties)) { - if ($this->motorReversal) - { - $this->storeLevel = $storeDevice->properties["position"]["value"]; - }else - { - $this->storeLevel = 100 - $storeDevice->properties["position"]["value"]; - } - logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__); - }else - { - $this->storeLevel = 0; - //return true; + $rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; + $rain = $rainTmp - $rainS; + $rainS = $rainTmp; + logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); } - - if (array_key_exists(METEO, $indexDevices)) + if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) { - if (array_key_exists("rainin", $indexDevices[METEO]->properties)) + if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50) { - $rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; - $rain = $rainTmp - $rainS; - $rainS = $rainTmp; - logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); + logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device); } - if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) + $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); + if ($rafale == 0) { - if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50) - { - logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device); - } - $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); - if ($rafale == 0) - { - $rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; - } - logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); + $rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; } - if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties)) - { - if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50) - { - logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device); - } - $vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6); - if ($vent == 0) - { - $vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"]; - } - logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__); - } - if ($vent > $rafale) - { - $rafale = $vent; - } - if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) - { - $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 6); - logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__); - } - } - - if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties)) - { - $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"]; - $exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5); - if ($exterieurLuxMoyen == 0) - { - $exterieurLuxMoyen = $exterieur_lux; - } - logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__); - } - if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties)) - { - $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10); - if ($salon_lux == 0) - { - $salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"]; - } - logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__); - } - if ($exterieur_lux > 33000 or $salon_lux >600) - { - logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); - if ($this->maxLevel != 0 and $salon_lux > 100) - { - $store2level = $this->storeLevel + 20; - } - }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100) - { - logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__); - $this->close("Luminosité faible"); - } - - logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__); - if ($rafale >= 70 or $rain != 0) - { - $this->maxLevel = 0; - logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__); - $this->close("vent trop fort ou pluie"); - return 0; - }elseif ($rafale != 0) - { - //calcul du maxlevel par rapport a la vitesse des rafales - $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10; - if ($r < 0) $r = 0; - $this->maxLevel = 100 - $r; logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); } - logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); - - switch ($property) + if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties)) { - case "rainin": - logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); - $this->close("Pluie"); - break; - case "windgustkmh": - logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); - break; - case "vibration": - $tmpStore = $this->storeLevel - 20; - if ($store2level == false or $store2level > $tmpStore) - { - $this->setTo($store2level, AUTO); - } - default: + if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50) + { + logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device); + } + $vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6); + if ($vent == 0) + { + $vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"]; + } + logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__); } - logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); - if ($this->storeLevel > $this->maxLevel) + if ($vent > $rafale) { - $this->setTo($this->maxLevel, AUTO); - }elseif ($store2level !== false) //$store2level = false then no change on store position + $rafale = $vent; + } + if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) { - if ( $store2level > $this->maxLevel ) + $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 6); + logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__); + } + } + if (array_key_exists("position", $storeDevice->properties)) + { + if ($this->motorReversal) + { + $this->storeLevel = 100 - $storeDevice->properties["position"]["value"]; + }else + { + $this->storeLevel = $storeDevice->properties["position"]["value"]; + } + logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__); + }else + { + $this->storeLevel = 0; + //return true; + } + + if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties)) + { + $facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"]; + $facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 5); + if ($facadeLuxMoyen == 0) + { + $facadeLuxMoyen = $facade_lux; + } + logger(DEBUG, "facade_lux=" . $facade_lux . " et facadeLuxMoyen=" . $facadeLuxMoyen, __FILE__ . ":" . __LINE__); + } + + if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties)) + { + $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"]; + $exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5); + if ($exterieurLuxMoyen == 0) + { + $exterieurLuxMoyen = $exterieur_lux; + } + logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__); + } + if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties)) + { + $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10); + if ($salon_lux == 0) + { + $salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"]; + } + logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__); + } + if ($exterieur_lux > 33000 or $salon_lux >600) + { + logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); + if ($this->maxLevel != 0 and $salon_lux > 100) + { + $store2level = $this->storeLevel + 20; + } + }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100 and $facadeLuxMoyen < 8000) + { + logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__); + $this->close("Luminosité faible"); + } + + logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__); + if ($rafale >= 70 or $rain != 0) + { + $this->maxLevel = 0; + logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__); + $this->close("vent trop fort ou pluie"); + return 0; + }elseif ($rafale != 0) + { + //calcul du maxlevel par rapport a la vitesse des rafales + $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10; + if ($r < 0) $r = 0; + $this->maxLevel = 100 - $r; + logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); + } + logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); + + switch ($property) + { + case "rainin": + logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); + $this->close("Pluie"); + break; + case "windgustkmh": + logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); + break; + case "vibration": + $tmpStore = $this->storeLevel - 20; + if ($store2level == false or $store2level > $tmpStore) { - logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__); - $this->setTo($this->maxLevel, AUTO); - }else - { - logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__); $this->setTo($store2level, AUTO); } + default: + break; + } + logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); + if ($this->storeLevel > $this->maxLevel) + { + $this->setTo($this->maxLevel, AUTO); + }elseif ($store2level !== false) //$store2level = false then no change on store position + { + if ( $store2level > $this->maxLevel ) + { + logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__); + $this->setTo($this->maxLevel, AUTO); + }else + { + logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__); + $this->setTo($store2level, AUTO); } }else { @@ -223,10 +230,6 @@ class rdc_store extends hook private function setTo($level, $method) { logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); - if (!$this->motorReversal) - { - $level = 100 - $level; - } if ($level <= 100) { logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); @@ -243,7 +246,7 @@ class rdc_store extends hook if ($this->storeLevel > 0) { logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__); - $this->send(100, IDLE); + $this->send(0, IDLE); } } @@ -251,6 +254,8 @@ class rdc_store extends hook { global $indexDevices; $deviceObject = $indexDevices[RDC_STORE]; + $level = 100 - $level; + $msg = array("position" => $level); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__); $deviceObject->payload = $msg; @@ -261,4 +266,3 @@ class rdc_store extends hook $hooks["rdc_store"] = new rdc_store(); ?> -print_r($function[0], true) diff --git a/hooks/scripts/rdc_store.php~ b/hooks/scripts/rdc_store.php~ index 66f7a10..f6ab556 100644 --- a/hooks/scripts/rdc_store.php~ +++ b/hooks/scripts/rdc_store.php~ @@ -45,7 +45,6 @@ class rdc_store extends hook $rafale = 0; $soleil = 0; $storeDevice = $indexDevices[RDC_STORE]; - //$this->maxLevel = 100; $r = 100; $moving = "STOP"; $store2level = false; @@ -67,151 +66,159 @@ class rdc_store extends hook logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__); } - if ($moving == "STOP" or $moving == null) + if (array_key_exists(METEO, $indexDevices)) { - if (array_key_exists("position", $storeDevice->properties)) + if (array_key_exists("rainin", $indexDevices[METEO]->properties)) { - if ($this->motorReversal) - { - $this->storeLevel = $storeDevice->properties["position"]["value"]; - }else - { - $this->storeLevel = 100 - $storeDevice->properties["position"]["value"]; - } - logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__); - }else - { - $this->storeLevel = 0; - //return true; + $rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; + $rain = $rainTmp - $rainS; + $rainS = $rainTmp; + logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); } - - if (array_key_exists(METEO, $indexDevices)) + if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) { - if (array_key_exists("rainin", $indexDevices[METEO]->properties)) + if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50) { - $rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; - $rain = $rainTmp - $rainS; - $rainS = $rainTmp; - logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); + logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device); } - if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) + $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); + if ($rafale == 0) { - if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50) - { - logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__); - } - $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); - if ($rafale == 0) - { - $rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; - } - logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); + $rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; } - if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties)) - { - if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50) - { - logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__); - } - $vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6); - if ($vent == 0) - { - $vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"]; - } - logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__); - } - if ($vent > $rafale) - { - $rafale = $vent; - } - if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) - { - $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 6); - logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__); - } - } - - if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties)) - { - $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"]; - $exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5); - if ($exterieurLuxMoyen == 0) - { - $exterieurLuxMoyen = $exterieur_lux; - } - logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__); - } - if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties)) - { - $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10); - if ($salon_lux == 0) - { - $salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"]; - } - logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__); - } - if ($exterieur_lux > 33000 or $salon_lux >600) - { - logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); - if ($this->maxLevel != 0 and $salon_lux > 100) - { - $store2level = $this->storeLevel + 20; - } - }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100) - { - logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__); - $this->close("Luminosité faible"); - } - - logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__); - if ($rafale >= 70 or $rain != 0) - { - $this->maxLevel = 0; - logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__); - $this->close("vent trop fort ou pluie"); - return 0; - }elseif ($rafale != 0) - { - //calcul du maxlevel par rapport a la vitesse des rafales - $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10; - if ($r < 0) $r = 0; - $this->maxLevel = 100 - $r; logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); } - logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); - - switch ($property) + if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties)) { - case "rainin": - logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); - $this->close("Pluie"); - break; - case "windgustkmh": - logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); - break; - case "vibration": - $tmpStore = $this->storeLevel - 20; - if ($store2level == false or $store2level > $tmpStore) - { - $this->setTo($store2level, AUTO); - } - default: + if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50) + { + logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device); + } + $vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6); + if ($vent == 0) + { + $vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"]; + } + logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__); } - logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); - if ($this->storeLevel > $this->maxLevel) + if ($vent > $rafale) { - $this->setTo($this->maxLevel, AUTO); - }elseif ($store2level !== false) //$store2level = false then no change on store position + $rafale = $vent; + } + if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) { - if ( $store2level > $this->maxLevel ) + $soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 6); + logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__); + } + } + if (array_key_exists("position", $storeDevice->properties)) + { + if ($this->motorReversal) + { + $this->storeLevel = 100 - $storeDevice->properties["position"]["value"]; + }else + { + $this->storeLevel = $storeDevice->properties["position"]["value"]; + } + logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__); + }else + { + $this->storeLevel = 0; + //return true; + } + + if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties)) + { + $facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"]; + $facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 5); + if ($facadeLuxMoyen == 0) + { + $facadeLuxMoyen = $facade_lux; + } + logger(DEBUG, "facade_lux=" . $facade_lux . " et facadeLuxMoyen=" . $facadeLuxMoyen, __FILE__ . ":" . __LINE__); + } + + if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties)) + { + $exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"]; + $exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5); + if ($exterieurLuxMoyen == 0) + { + $exterieurLuxMoyen = $exterieur_lux; + } + logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__); + } + if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties)) + { + $salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10); + if ($salon_lux == 0) + { + $salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"]; + } + logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__); + } + if ($exterieur_lux > 33000 or $salon_lux >600) + { + logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); + if ($this->maxLevel != 0 and $salon_lux > 100) + { + $store2level = $this->storeLevel + 20; + } + }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100 and $facadeLuxMoyen < 5000) + { + logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__); + $this->close("Luminosité faible"); + } + + logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__); + if ($rafale >= 70 or $rain != 0) + { + $this->maxLevel = 0; + logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__); + $this->close("vent trop fort ou pluie"); + return 0; + }elseif ($rafale != 0) + { + //calcul du maxlevel par rapport a la vitesse des rafales + $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10; + if ($r < 0) $r = 0; + $this->maxLevel = 100 - $r; + logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); + } + logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); + + switch ($property) + { + case "rainin": + logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); + $this->close("Pluie"); + break; + case "windgustkmh": + logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); + break; + case "vibration": + $tmpStore = $this->storeLevel - 20; + if ($store2level == false or $store2level > $tmpStore) { - logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__); - $this->setTo($this->maxLevel, AUTO); - }else - { - logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__); $this->setTo($store2level, AUTO); } + default: + break; + } + logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); + if ($this->storeLevel > $this->maxLevel) + { + $this->setTo($this->maxLevel, AUTO); + }elseif ($store2level !== false) //$store2level = false then no change on store position + { + if ( $store2level > $this->maxLevel ) + { + logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__); + $this->setTo($this->maxLevel, AUTO); + }else + { + logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__); + $this->setTo($store2level, AUTO); } }else { @@ -223,10 +230,6 @@ class rdc_store extends hook private function setTo($level, $method) { logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); - if (!$this->motorReversal) - { - $level = 100 - $level; - } if ($level <= 100) { logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); @@ -243,7 +246,7 @@ class rdc_store extends hook if ($this->storeLevel > 0) { logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__); - $this->send(100, IDLE); + $this->send(0, IDLE); } } @@ -251,6 +254,8 @@ class rdc_store extends hook { global $indexDevices; $deviceObject = $indexDevices[RDC_STORE]; + $level = 100 - $level; + $msg = array("position" => $level); logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__); $deviceObject->payload = $msg; @@ -261,4 +266,3 @@ class rdc_store extends hook $hooks["rdc_store"] = new rdc_store(); ?> -print_r($function[0], true)