diff --git a/class/db.php b/class/db.php index c38b765..ede00f7 100644 --- a/class/db.php +++ b/class/db.php @@ -75,7 +75,7 @@ class db extends mysqli logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__); } } - logger(INFO, sprintf(_("New value of property: '%s' of device: %s stored in database"), $propertyTree, $device->friendlyName, $value), __FILE__ . ":" . __LINE__); + logger(INFO, sprintf(_("New value (%s) of property: '%s' of device: %s stored in database"), $value, $propertyTree, $device->friendlyName), __FILE__ . ":" . __LINE__); } } } diff --git a/events.php b/events.php index 04a694e..f087af9 100644 --- a/events.php +++ b/events.php @@ -170,7 +170,7 @@ function removeEvent($device, $property , $value) function searchEvent($device, $property , $value) { global $events; - logger(DEBUG, _("searching event for device %s, property %s and value %s"), $device->friendlyName, $property, bool2string($value), __FILE__ . ":" . __LINE__); + logger(DEBUG, sprintf(_("searching event for device %s, property %s and value %s"), $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__); foreach($events as $key => $event) { //echo "Event : $event => $value" . EOL; diff --git a/hooks/scripts/rdc_chambre_eclairage.php b/hooks/scripts/rdc_chambre_eclairage.php index 964c89d..4013579 100644 --- a/hooks/scripts/rdc_chambre_eclairage.php +++ b/hooks/scripts/rdc_chambre_eclairage.php @@ -3,14 +3,14 @@ class rdc_chambre_eclairage extends hook { public $hookName = "rdc_chambre_eclairage"; - public $active = false; //enable/disable hook (true => enabled) + public $active = true; //enable/disable hook (true => enabled) public $delay = 5; // amount of time in $timeunit public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year public $luminance_min = 60; public $luminance_max = 3000; protected $devicelist = array( - "RDC_CHAMBRE_AMBIANCE" => array("state", false), - "RDC_CHAMBRE_ECLAIRAGE" => array("state_l1", false), + "RDC_CHAMBRE_AMBIANCE" => array("state", false), // "ON"/"OFF" + "RDC_CHAMBRE_ECLAIRAGE" => array("state_l1", false), // "ON"/"OFF" "RDC_CHAMBRE_MVMT" => array("occupancy", false), "RDC_CHAMBRE_ARMOIRE_GAUCHE" => array("contact", false) ); @@ -25,7 +25,10 @@ class rdc_chambre_eclairage extends hook $lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->illuminance_lux; if ($property == "occupancy" and $value == "ON") { - $this->send(RDC_CHAMBRE_LUMINOSITE, "ON", "OFF", AUTO); + $this->send(RDC_CHAMBRE_AMBIANCE, "ON", "OFF", AUTO); + }elseif ($property == "contact" and $value = true and getValue(RDC_CHAMBRE_ECLAIRAGE) == "OFF") + { + $this->send(RDC_CHAMBRE_ECLAIRAGE, "ON", "OFF", AUTO); } logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value), __FILE__ . ":" . __LINE__); } diff --git a/hooks/scripts/rdc_salon_eclairage.php b/hooks/scripts/rdc_salon_eclairage.php index f47de5b..f52bdef 100644 --- a/hooks/scripts/rdc_salon_eclairage.php +++ b/hooks/scripts/rdc_salon_eclairage.php @@ -13,7 +13,7 @@ class rdc_salon_eclairage extends hook public $delay = 3; // amount of time in $timeunit public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year - public $luminance_min = 60; + public $luminance_min = 70; public $luminance_max = 3000; @@ -26,7 +26,7 @@ class rdc_salon_eclairage extends hook { case "occupancy": logger(DEBUG, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__); - //print_r($indexDevices[RDC_SALON_LUMINOSITE]); + //print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux")); if ($value == ON and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min) { logger(DEBUG, _("setting to ON"), __FILE__ . ":" . __LINE__); @@ -35,23 +35,26 @@ class rdc_salon_eclairage extends hook }elseif ($value == OFF) { logger(DEBUG, _("Value is OFF"), __FILE__ . ":" . __LINE__); - if (getValue(RDC_SALON_MVMT, "occupancy") == OFF) + if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF)) { - if (getValue(RDC_SALON_MVMT2, "occupancy") == OFF) - { - logger(DEBUG, _("Setting to OFF"), __FILE__ . ":" . __LINE__); - setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true); - //$this->send("ON", "OFF", AUTO); - } + logger(DEBUG, _("Setting to OFF"), __FILE__ . ":" . __LINE__); + setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true); + //$this->send("ON", "OFF", AUTO); } } break; case "contact": logger(DEBUG, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__); - if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min) + if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min and getValue(RDC_SALON_ECLAIRAGE_PANNEAU, "state") == "OFF") { logger(DEBUG, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__); - $this->send("ON", "OFF", AUTO); + if (getValue(RDC_SALON_MVMT, "occupancy") == ON or getValue(RDC_SALON_MVMT2, "occupancy") == ON) + { + $this->send("ON", null, AUTO); + }else + { + $this->send("ON", "OFF", AUTO); + } } break; case "illuminance_lux": @@ -60,7 +63,8 @@ class rdc_salon_eclairage extends hook { logger(DEBUG, _("illuminace is > to max"), __FILE__ . ":" . __LINE__); //$this->send("OFF", null, AUTO); - removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF"); + //removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF"); + setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true); }elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON OR getValue(RDC_SALON_MVMT2,"occupancy") == ON)) { logger(DEBUG, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__); diff --git a/hooks/scripts/rdc_sdb_eclairage.php b/hooks/scripts/rdc_sdb_eclairage.php index 8e5ba96..775d04b 100644 --- a/hooks/scripts/rdc_sdb_eclairage.php +++ b/hooks/scripts/rdc_sdb_eclairage.php @@ -23,7 +23,7 @@ class rdc_sdb_eclairage extends hook RDC_SDB_WC_ECLAIRAGE => array("state_l1", false) ); - // callback fonction. Is called with these 4 parameters + // callback fonction. Is called with these 3 parameters public function callBack(&$device, $property, $value) { global $devices, $indexDevices; @@ -33,19 +33,22 @@ class rdc_sdb_eclairage extends hook case "occupancy": if ($value == ON) { - $this->send("ON"); - setDelay($device, $this->delay, $this->timeUnit, "state_l1", "OFF", true); + if (getValue(RDC_SDB_WC_ECLAIRAGE, "state_l1") != "ON") + { + $this->send("ON"); + } + //setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delay, $this->timeUnit, "state_l1", "OFF", true); $device->method = AUTO; } break; case "state_l1": if ($value == ON) { - setDelay($device, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true); + setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delayManual, $this->timeUnit, "state_l1", "OFF", true); $device->method = MANUAL; }elseif ($value = OFF) { - deleteEvent(searchEvent($device, "state_l1", "OFF")); + removeEvent($indexDevices[RDC_SDB_WC_ECLAIRAGE], "state_l1", "OFF"); } break; } diff --git a/moha.php b/moha.php index 5a50f5a..cce2504 100644 --- a/moha.php +++ b/moha.php @@ -33,6 +33,7 @@ $logFh = null; // filehandle of log file $curlErr = 0; // Number of errors returned by curl $configDir = "./config"; // default config dir (production value is /etc/moha/) $hooksInitialized = 0; // are all hooks initialized ? false/true +$flagHooks = false; $mqttServerIp = "127.0.0.1"; // IP address of mqttserver in production mode if ($testMode) { @@ -264,9 +265,10 @@ while (true) } } $hooksInitialized = $i; - }else + }elseif($flagHooks === false) { - logger(DEBUG,_("All hooks initialized"), __FILE__ . ":" . __LINE__); + logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__); + $flagHooks = true; } checkEvents(); askWebServer($read); diff --git a/topics_callbacks/zigbee2mqtt.php b/topics_callbacks/zigbee2mqtt.php index 83ff25d..efdf635 100644 --- a/topics_callbacks/zigbee2mqtt.php +++ b/topics_callbacks/zigbee2mqtt.php @@ -42,11 +42,11 @@ $callback = function($topic, $message) $fnTree = explode ("/" , $topic[1]); // get friendlyname echo $topic[0] . " => " . $topic[1] . EOL; //$devices[$topic[0]][$fnTree[0]]->json = json_decode($message->payload); - if ($fnTree[array_key_last($fnTree)] == "availability" and is_string($message->payload)) + if ($fnTree[array_key_last($fnTree)] == "availability") { unset ($fnTree[array_key_last($fnTree)]); $payloadArray = array("availability" => $message->payload); - //print_r($payloadArray); + //TODO payload can be a json object }else { $payloadArray = json_decode($message->payload); diff --git a/utils.php b/utils.php index 9dfc67a..00c1953 100644 --- a/utils.php +++ b/utils.php @@ -41,10 +41,10 @@ function mktopic($device) return $device->topic . "/" . $device->friendlyName; } -function getValue($fn, $property) +function getValue($ieeeAddress, $property) { global $indexDevices; - return $indexDevices[$fn]->$property["value"]; + return $indexDevices[$ieeeAddress]->$property["value"]; } function setValue($fn, $property, $value)