1
0
This commit is contained in:
2022-02-23 10:23:16 +01:00
parent 7d1dd25f2a
commit 34dca81ba5
21 changed files with 738 additions and 533 deletions

View File

@@ -19,38 +19,40 @@ class rdc_chambre_eclairage extends hook
// $device -> calling device
// $property -> property of the device (given by mqtt)
// $value -> value of the property
public function callBack(&$device, $property, $value)
public function callBack($device, $property, $value)
{
global $devices, $indexDevices;
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->illuminance_lux;
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
if ($property == "occupancy" and $value == "ON")
{
$this->send(RDC_CHAMBRE_AMBIANCE, "ON", "OFF", AUTO);
$this->send($targetAmbiance, "ON", "OFF", AUTO);
}elseif ($property == "contact" and $value = true and getValue(RDC_CHAMBRE_ECLAIRAGE, "state_l1") == "OFF")
{
$this->send(RDC_CHAMBRE_ECLAIRAGE, "ON", "OFF", AUTO);
$this->send($targetEclairage, "ON", "OFF", AUTO);
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
}
private function send($device, $state, $delayState = false, $method = MANUAL)
private function send($deviceObject, $state, $delayState = false, $method = MANUAL)
{
global $devices, $indexDevices;
$device = &$indexDevices[$device];
$msg = array("state" => $state);
if ($device->state["value"] != $state)
if ($deviceObject->properties["state"]["value"] != $state)
{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
$device->payload = $msg;
$device->set();
$device->method = $method;
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set();
$deviceObject->method = $method;
}else
{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
}
//echo 'delaystate = ' . var_dump($delayState);
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true);
if ($delayState !== false) setDelay($deviceObject, $this->delay, $this->timeUnit, "state", $delayState, true);
}
}