array("occupancy", false), RDC_SALON_MVMT2 => array("occupancy", false), RDC_ENTREE_PORTE => array("contact", false), RDC_SALON_LUMINOSITE => array("illuminance_lux", false) ); 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; // callback fonction. Is called with these 4 parameters public function callBack(&$device, $param, $value) { global $devices, $indexDevices; logger(INFO, _("hook : rdc_salon_eclairage")); switch($param) { case "occupancy": //print_r($indexDevices[RDC_SALON_LUMINOSITE]); if ($value == ON and $indexDevices[RDC_SALON_LUMINOSITE]->illuminance_lux["value"] <= $this->luminance_min) { $this->send("ON", "OFF", AUTO); } break; case "contact": if ($value == false and $indexDevices[RDC_SALON_LUMINOSITE]->illuminance_lux["value"] <= $this->luminance_min) { $this->send("ON", "OFF", AUTO); } break; case "illuminance_lux": if ($value >= $this->luminance_max) { $this->send("OFF"); } break; } logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $param, bool2string($value))); } private function send($state, $delayState = false, $method = MANUAL) { global $devices, $indexDevices; $device = & $indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU]; $msg = array("state" => $state); if ($device->state["value"] != $state) { logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName)); $device->payload = $msg; $device->set(); $device->method = $method; }else { logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $device->friendlyName)); } //echo 'delaystate = ' . var_dump($delayState); if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true); } } $hooks["rdc_salon_eclairage"] = new rdc_salon_eclairage(); ?>