From b726173b4b4a4853a23d52b08112c4cb30735938 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Mon, 19 Sep 2022 23:40:29 +0200 Subject: [PATCH] added templates --- .gitignore | 4 - class/db.php | 5 + config/devices_constants.php | 2 + config/liste_telephones.php | 1 + config/properties2log.php | 2 +- config/users.php.template | 2 - .../scripts/example.php.template | 17 +- hooks/scripts/rdc_sdb_eclairage.php | 93 +++--- hooks/scripts/rdc_store.php | 315 +++++++++--------- hooks/scripts/rdc_store.php~ | 315 +++++++++--------- hooks/scripts/rdc_temperature_int_ext.php | 4 +- systemd/moha.service | 2 +- 12 files changed, 391 insertions(+), 371 deletions(-) delete mode 100644 .gitignore rename docs/template.php => hooks/scripts/example.php.template (67%) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bf5ad37..0000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*~ -*swp -*kdev4* -*.log diff --git a/class/db.php b/class/db.php index 947da0e..5a82d63 100644 --- a/class/db.php +++ b/class/db.php @@ -111,6 +111,11 @@ class db extends mysqli return $value[0]; } } + + /*function lastTime($deviceObject, $property) + { + $query = "SELECT date FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), date) < '00:" . str_pad($time, 2, "0", STR_PAD_LEFT ) . "'"; + }*/ } $mohaDB = new db(); diff --git a/config/devices_constants.php b/config/devices_constants.php index 58c7a14..946dc89 100644 --- a/config/devices_constants.php +++ b/config/devices_constants.php @@ -10,6 +10,7 @@ $deviceTable = array( "0x00124b0022ebac5c" => "RDC_SALON_MVMT2", "0x588e81fffe2cf695" => "RDC_SALON_MVMT", "0xe0798dfffe4ffa2c" => "RDC_SALON_PRESENCE", + "0x00158d00047bc298" => "RDC_SALON_TEMPERATURE", "0x00124b001f900753" => "RDC_ENTREE_PORTE", "0x00158d0001923c21" => "RDC_CHAMBRE_RADIATEUR", "0x04cf8cdf3c78aff0" => "RDC_SALON_LUMINOSITE", @@ -53,6 +54,7 @@ $deviceTable = array( "0x00124b00234484ad" => "RDC_CHAMBRE_MVMT", "0x04cf8cdf3c7b6056" => "RDC_CHAMBRE_LUMINOSITE", "0x00158d0006c0447c" => "RDC_CHAMBRE_ARMOIRE_GAUCHE", + "0x00158d0005782096" => "RDC_CHAMBRE_TEMPERATURE", "0x842e14fffe9be0fc" => "RDC_STORE", "0xa4c138165e31c0e8" => "RDC_STORE_VIBRATION", "0x04cf8cdf3c7b3d64" => "RDC_EXTERIEUR_LUMINOSITE", diff --git a/config/liste_telephones.php b/config/liste_telephones.php index 36a878e..7a0e5a3 100644 --- a/config/liste_telephones.php +++ b/config/liste_telephones.php @@ -4,6 +4,7 @@ $macAddresses = array( "E8:78:29:C2:79:22" => "Daniel", //"84:CF:BF:8E:E6:A6" => "daniel", "D0:9C:7A:DA:8E:D8" => "Maryclaire", +"D0:9C:7A:E4:B3:B9" => "Maryclaire", "FA:61:B1:D8:3C:D4" => "Maryclaire", "26:4D:40:5F:1E:10" => "Terence" ); diff --git a/config/properties2log.php b/config/properties2log.php index 9a82680..a851c9e 100644 --- a/config/properties2log.php +++ b/config/properties2log.php @@ -26,7 +26,7 @@ $properties2log = array( "winddir" => 40, "windspeedkmh" => 5, "windgustkmh" => 5, - "rainin" => 0.5, + "rainin" => 0.005, //"dailyrainin" => null, //"weeklyrainin" => null, //"monthlyrainin" => null, diff --git a/config/users.php.template b/config/users.php.template index 9e59fe4..5c8b45f 100644 --- a/config/users.php.template +++ b/config/users.php.template @@ -5,5 +5,3 @@ $users = array( ) ?> - - diff --git a/docs/template.php b/hooks/scripts/example.php.template similarity index 67% rename from docs/template.php rename to hooks/scripts/example.php.template index 53e6c31..5497571 100644 --- a/docs/template.php +++ b/hooks/scripts/example.php.template @@ -5,9 +5,10 @@ class extends hook public $hookName = ; public $active = true; //enable/disable hook (true => enabled) - protected $devicelist = array( => array(, false)); + protected $devicelist = array( + => array(, false)); - // if you need some initialisation when creating the object, uncomment andput your code here. + // if you need some initialisation when creating the object, uncomment the funcion init below and put your code here. // If existing, This function is called by __construct /*protected function init() { @@ -15,14 +16,22 @@ class extends hook } */ + // you can intercept the hook installation in this function. + function installHooks(&$indexDevices) + { + return $this->installHooksFunction($indexDevices); + } + // callback fonction. Is called with these 3 parameters // $device -> calling device // $property -> property of the device (given by mqtt) // $value -> value of the property public function callBack(&$device, $property, $value) { - // here your code - + if ($this->active == true) + { + // here your code + } logger (INFO,sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__); } } diff --git a/hooks/scripts/rdc_sdb_eclairage.php b/hooks/scripts/rdc_sdb_eclairage.php index 1d6acfa..af801dd 100644 --- a/hooks/scripts/rdc_sdb_eclairage.php +++ b/hooks/scripts/rdc_sdb_eclairage.php @@ -38,67 +38,72 @@ class rdc_sdb_eclairage extends hook { global $indexDevices; //var_dump($value); - $deviceTarget = &$indexDevices[RDC_SDB_WC_ECLAIRAGE]; - if ($deviceTarget !== null) + if ($this->active) { - logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__); - switch($property) + if (array_key_exists(RDC_SDB_WC_ECLAIRAGE, $indexDevices)) { - case "occupancy": - $method = $deviceTarget->properties["state_l1"]["method"]; - logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__); - if ($value == ON) - { - if($method == IDLE) + $deviceTarget = &$indexDevices[RDC_SDB_WC_ECLAIRAGE]; + logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__); + $method = $deviceTarget->properties["state_l1"]["method"]; + switch($property) + { + case "occupancy": + logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__); + if ($value == ON) { - logger(DEBUG, _("lighting with method auto"), __FILE__ . ":" . __LINE__); - //$deviceTarget->properties["state_l1"]["method"] = AUTO; - $this->send("ON", AUTO); + if($method == IDLE) + { + logger(DEBUG, _("lighting with method auto"), __FILE__ . ":" . __LINE__); + //$deviceTarget->properties["state_l1"]["method"] = AUTO; + $this->send("ON", AUTO); + removeEvent($deviceTarget, "state", "OFF"); + } + }elseif (!testActionneurs($this->actionneurs)) + { + logger(DEBUG, _("Actionneurs are all false"), __FILE__ . ":" . __LINE__); + $this->send("OFF", IDLE); removeEvent($deviceTarget, "state", "OFF"); } - }elseif (!testActionneurs($this->actionneurs)) - { - logger(DEBUG, _("Actionneurs are all false"), __FILE__ . ":" . __LINE__); - $this->send("OFF", IDLE); - } - break; - case "state_l1": - $method = $deviceTarget->properties["state_l1"]["method"]; - - logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__); - if ($value == "ON") - { - if ($method == IDLE) + break; + case "state_l1": + logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__); + if ($value == "ON") { - logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__); + if ($method == IDLE) + { + logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__); + 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" and $method == MANUAL) + { + $deviceTarget->properties["state_l1"]["method"] = IDLE; removeEvent($deviceTarget, "state_l1", "OFF"); - $deviceTarget->properties["state_l1"]["method"] = MANUAL; - //setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE); + //$deviceTarget->properties["state_l1"]["method"] = IDLE; + logger(DEBUG, _("State_l1 is false light is off and method is ") . $method, __FILE__ . ":" . __LINE__); } - }elseif ($value == "OFF") - { - $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; + break; + } + 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__); } - 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) { global $indexDevices; - $msg = array("state_l1" => $state); + $device = &$indexDevices[RDC_SDB_WC_ECLAIRAGE]; - logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__); + $device->properties["state_l1"]["method"] = $method; + $msg = array("state_l1" => $state); $device->payload = $msg; - $device->set("state_l1", $method); + $device->set("state_l1"); + logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__); + } } $hooks["rdc_sdb_eclairage"] = new rdc_sdb_eclairage(); diff --git a/hooks/scripts/rdc_store.php b/hooks/scripts/rdc_store.php index c9b97c6..f00b044 100644 --- a/hooks/scripts/rdc_store.php +++ b/hooks/scripts/rdc_store.php @@ -11,7 +11,6 @@ class rdc_store extends hook public $storeUpTime = 41; public $maxLevel; public $storeLevel; - public $motorReversal = false; protected $propertyInitialized =array(); protected $devicelist = array( RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", @@ -45,186 +44,190 @@ class rdc_store extends hook $rafale = 0; $soleil = 0; $storeDevice = $indexDevices[RDC_STORE]; - $r = 100; + $r = 0; $moving = "STOP"; $store2level = false; + $lastVibration = 0; - if (array_key_exists("moving", $storeDevice->properties)) + if ($this->active == true) { - $moving = $storeDevice->properties["moving"]["value"]; - logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__); - } - if (array_key_exists("motor_reversal", $storeDevice->properties)) - { - if ($storeDevice->properties["motor_reversal"]["value"] == "ON") + if (array_key_exists("vibration", $indexDevices[RDC_store_vibration]->properties)) { - $this->motorReversal = true; + $lastVibration = $mohaDB->moyenne($indexDevices[RDC_store_vibration], "vibration", 5); + logger(DEBUG, "Last vibration inferior to 5 minutes" . bool2string($lastVibration ), __FILE__ . ":" . __LINE__); + } + if (array_key_exists("moving", $storeDevice->properties)) + { + $moving = $storeDevice->properties["moving"]["value"]; + logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__); + } + if (array_key_exists(METEO, $indexDevices)) + { + if (array_key_exists("rainin", $indexDevices[METEO]->properties)) + { + $rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; + $rain = $rainTmp - $rainS; + $rainS = $rainTmp; + logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); + } + if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) + { + 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", 10); + if ($rafale == 0) + { + $rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; + } + logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); + } + 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", 10); + logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__); + } + } + if (array_key_exists("position", $storeDevice->properties)) + { + $this->storeLevel = $storeDevice->properties["position"]["value"]; + logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__); }else { - $this->motorReversal = false; + $this->storeLevel = 0; } - logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__); - } - if (array_key_exists(METEO, $indexDevices)) - { - if (array_key_exists("rainin", $indexDevices[METEO]->properties)) + if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties)) { - $rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; - $rain = $rainTmp - $rainS; - $rainS = $rainTmp; - logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); - } - if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) - { - if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50) + $facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"]; + $facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 10); + if ($facadeLuxMoyen == 0) { - logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device); + $facadeLuxMoyen = $facade_lux; } - $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); - if ($rafale == 0) + 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", 10); + if ($exterieurLuxMoyen == 0) { - $rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; + $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__); + } + + // Calcul de la position du store + + if ($exterieurLuxMoyen > 36000 or $exterieur_lux > 50000 or $salon_lux >600) + { + logger(DEBUG, "exterieurLuxMoyen > 36000 or exterieur_lux > 50000 or salon_lux >600", __FILE__ . ":" . __LINE__); + $store2level = $this->storeLevel + 20; + }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100 and $facadeLuxMoyen < 10000) + { + logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100 and facadeLuxMoyen < 10000", __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; + }else + { + $r = 100 - $r; + } + + if ($lastVibration == 0) + { + $this->maxLevel = 100 - $r; } logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); } - 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("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; - } + logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); - 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) + switch ($property) { - $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 < 10000) - { - 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"); + 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($tmpStore, AUTO); + }*/ + $this->maxLevel -= 20; + default: break; - case "windgustkmh": - logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); - break; - case "vibration": - $tmpStore = $this->storeLevel - 20; - if ($store2level == false or $store2level > $tmpStore) + } + if ($this->maxLevel < 0) + { + $this->maxLevel = 0; + } + 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); } - 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); + logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__); } - }else - { - logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__); } - } private function setTo($level, $method) @@ -254,8 +257,6 @@ 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; diff --git a/hooks/scripts/rdc_store.php~ b/hooks/scripts/rdc_store.php~ index f6ab556..f00b044 100644 --- a/hooks/scripts/rdc_store.php~ +++ b/hooks/scripts/rdc_store.php~ @@ -11,7 +11,6 @@ class rdc_store extends hook public $storeUpTime = 41; public $maxLevel; public $storeLevel; - public $motorReversal = false; protected $propertyInitialized =array(); protected $devicelist = array( RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", @@ -45,186 +44,190 @@ class rdc_store extends hook $rafale = 0; $soleil = 0; $storeDevice = $indexDevices[RDC_STORE]; - $r = 100; + $r = 0; $moving = "STOP"; $store2level = false; + $lastVibration = 0; - if (array_key_exists("moving", $storeDevice->properties)) + if ($this->active == true) { - $moving = $storeDevice->properties["moving"]["value"]; - logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__); - } - if (array_key_exists("motor_reversal", $storeDevice->properties)) - { - if ($storeDevice->properties["motor_reversal"]["value"] == "ON") + if (array_key_exists("vibration", $indexDevices[RDC_store_vibration]->properties)) { - $this->motorReversal = true; + $lastVibration = $mohaDB->moyenne($indexDevices[RDC_store_vibration], "vibration", 5); + logger(DEBUG, "Last vibration inferior to 5 minutes" . bool2string($lastVibration ), __FILE__ . ":" . __LINE__); + } + if (array_key_exists("moving", $storeDevice->properties)) + { + $moving = $storeDevice->properties["moving"]["value"]; + logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__); + } + if (array_key_exists(METEO, $indexDevices)) + { + if (array_key_exists("rainin", $indexDevices[METEO]->properties)) + { + $rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; + $rain = $rainTmp - $rainS; + $rainS = $rainTmp; + logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); + } + if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) + { + 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", 10); + if ($rafale == 0) + { + $rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; + } + logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); + } + 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", 10); + logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__); + } + } + if (array_key_exists("position", $storeDevice->properties)) + { + $this->storeLevel = $storeDevice->properties["position"]["value"]; + logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__); }else { - $this->motorReversal = false; + $this->storeLevel = 0; } - logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__); - } - if (array_key_exists(METEO, $indexDevices)) - { - if (array_key_exists("rainin", $indexDevices[METEO]->properties)) + if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties)) { - $rainTmp = $indexDevices[METEO]->properties["rainin"]["value"]; - $rain = $rainTmp - $rainS; - $rainS = $rainTmp; - logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__); - } - if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties)) - { - if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50) + $facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"]; + $facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 10); + if ($facadeLuxMoyen == 0) { - logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device); + $facadeLuxMoyen = $facade_lux; } - $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); - if ($rafale == 0) + 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", 10); + if ($exterieurLuxMoyen == 0) { - $rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; + $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__); + } + + // Calcul de la position du store + + if ($exterieurLuxMoyen > 36000 or $exterieur_lux > 50000 or $salon_lux >600) + { + logger(DEBUG, "exterieurLuxMoyen > 36000 or exterieur_lux > 50000 or salon_lux >600", __FILE__ . ":" . __LINE__); + $store2level = $this->storeLevel + 20; + }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100 and $facadeLuxMoyen < 10000) + { + logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100 and facadeLuxMoyen < 10000", __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; + }else + { + $r = 100 - $r; + } + + if ($lastVibration == 0) + { + $this->maxLevel = 100 - $r; } logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); } - 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("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; - } + logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); - 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) + switch ($property) { - $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"); + 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($tmpStore, AUTO); + }*/ + $this->maxLevel -= 20; + default: break; - case "windgustkmh": - logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); - break; - case "vibration": - $tmpStore = $this->storeLevel - 20; - if ($store2level == false or $store2level > $tmpStore) + } + if ($this->maxLevel < 0) + { + $this->maxLevel = 0; + } + 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); } - 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); + logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__); } - }else - { - logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__); } - } private function setTo($level, $method) @@ -254,8 +257,6 @@ 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; diff --git a/hooks/scripts/rdc_temperature_int_ext.php b/hooks/scripts/rdc_temperature_int_ext.php index 27e165c..5e26697 100644 --- a/hooks/scripts/rdc_temperature_int_ext.php +++ b/hooks/scripts/rdc_temperature_int_ext.php @@ -9,7 +9,9 @@ class rdc_temperature_int_ext extends hook protected $devicelist = array( - METEO=> "tempc", + METEO => "tempc", + RDC_CHAMBRE_TEMPERATURE => "temperature", + RDC_SALON_TEMPERATURE => "temperature" ); protected $portesList = array( diff --git a/systemd/moha.service b/systemd/moha.service index fc498a8..f26f619 100644 --- a/systemd/moha.service +++ b/systemd/moha.service @@ -13,7 +13,7 @@ StandardOutput=inherit StandardError=inherit Restart=always User=domotique -roup=domotique +Group=domotique [Install] WantedBy=multi-user.target