2021-12-31 23:09:58 +01:00
|
|
|
<?php
|
2022-01-03 21:11:52 +01:00
|
|
|
class rdc_salon_eclairage
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
2022-01-03 21:11:52 +01:00
|
|
|
public $hookName = "rdc_salon_eclairage";
|
|
|
|
public $active = true;
|
2022-01-01 06:26:02 +01:00
|
|
|
// list of devices we are listening to
|
2021-12-31 23:09:58 +01:00
|
|
|
private $devicelist = array("0x00124b0022ebac5c", "0x588e81fffe2cf695", "0x00124b001f900753", "0x04cf8cdf3c78aff0");
|
2022-01-01 06:26:02 +01:00
|
|
|
public $delay = 3; // amount of time in $timeunit
|
2022-01-02 18:14:13 +01:00
|
|
|
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
2022-01-02 12:14:30 +01:00
|
|
|
public $luminance_min = 80;
|
|
|
|
public $luminance_max = 3000;
|
|
|
|
|
2021-12-31 23:09:58 +01:00
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
global $indexDevices;
|
2022-01-02 12:14:30 +01:00
|
|
|
|
|
|
|
// assigne the function to the sensors devices
|
2022-01-03 21:11:52 +01:00
|
|
|
if ($this->active === true)
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
2022-01-03 21:11:52 +01:00
|
|
|
foreach ($this->devicelist as $ieeeAddress)
|
|
|
|
{
|
|
|
|
$indexDevices[$ieeeAddress]->functions[] = array($this,"callback");
|
|
|
|
}
|
2021-12-31 23:09:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:26:02 +01:00
|
|
|
// callback fonction. Is called with these 4 parameters
|
2022-01-02 18:14:13 +01:00
|
|
|
public function callBack(&$device, $param, $value)
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
|
|
|
global $devices, $indexDevices;
|
|
|
|
switch($param)
|
|
|
|
{
|
|
|
|
case "occupancy":
|
2022-01-02 18:14:13 +01:00
|
|
|
if ($value == 1 and $indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= $this->luminance_min)
|
|
|
|
{
|
|
|
|
$this->send("ON");
|
|
|
|
}
|
2021-12-31 23:09:58 +01:00
|
|
|
break;
|
|
|
|
case "contact":
|
2022-01-02 18:14:13 +01:00
|
|
|
if ($value == false and $indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= $this->luminance_min)
|
|
|
|
{
|
|
|
|
$this->send("ON");
|
|
|
|
}
|
2021-12-31 23:09:58 +01:00
|
|
|
break;
|
2022-01-02 12:14:30 +01:00
|
|
|
case "illuminance_lux":
|
2022-01-02 18:14:13 +01:00
|
|
|
if ($value >= $this->luminance_max) $this->send("OFF");
|
2022-01-03 21:11:52 +01:00
|
|
|
break;
|
2021-12-31 23:09:58 +01:00
|
|
|
}
|
2022-01-04 08:54:06 +01:00
|
|
|
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $param, $value));
|
2021-12-31 23:09:58 +01:00
|
|
|
}
|
|
|
|
|
2022-01-02 18:14:13 +01:00
|
|
|
private function send($state)
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
|
|
|
global $devices, $indexDevices;
|
2022-01-02 18:14:13 +01:00
|
|
|
$msg = array("state" => $state);
|
|
|
|
$device = & $indexDevices["0x588e81fffe343e8f"];
|
2022-01-03 21:11:52 +01:00
|
|
|
logger(INFO, sprintf(_("publishing message: %s to %s"), $msg, $device->friendlyName));
|
2022-01-02 18:14:13 +01:00
|
|
|
$device->payload = $msg;
|
|
|
|
$device->set(null);
|
|
|
|
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
|
2021-12-31 23:09:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 21:11:52 +01:00
|
|
|
$hooks["rdc_salon_eclairage"] = new rdc_salon_eclairage();
|
2021-12-31 23:09:58 +01:00
|
|
|
?>
|