74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
class rdc_salon_eclairage
|
|
{
|
|
public $hookName = "rdc_salon_eclairage";
|
|
public $active = true;
|
|
// list of devices we are listening to
|
|
|
|
private $devicelist = array(
|
|
RDC_SALON_MVMT => "occupancy",
|
|
RDC_SALON_MVMT2 => "occupancy",
|
|
RDC_ENTREE_PORTE => "contact",
|
|
RDC_SALON_LUMINOSITE => "illuminance_lux"
|
|
);
|
|
|
|
public $delay = 3; // amount of time in $timeunit
|
|
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
|
public $luminance_min = 80;
|
|
public $luminance_max = 3000;
|
|
|
|
|
|
function __construct()
|
|
{
|
|
global $indexDevices;
|
|
|
|
// assigne the function to the sensors devices
|
|
if ($this->active === true)
|
|
{
|
|
foreach ($this->devicelist as $ieeeAddress => $param)
|
|
{
|
|
$indexDevices[$ieeeAddress]->$param["functions"][] = array($this,"callback");
|
|
}
|
|
}
|
|
}
|
|
|
|
// callback fonction. Is called with these 4 parameters
|
|
public function callBack(&$device, $param, $value)
|
|
{
|
|
global $devices, $indexDevices;
|
|
switch($param)
|
|
{
|
|
case "occupancy":
|
|
if ($value == 1 and $indexDevices[RDC_SALON_LUMINOSITE]->illuminance_lux["value"] <= $this->luminance_min)
|
|
{
|
|
$this->send("ON");
|
|
}
|
|
break;
|
|
case "contact":
|
|
if ($value == false and $indexDevices[RDC_SALON_LUMINOSITE]->illuminance_lux["value"] <= $this->luminance_min)
|
|
{
|
|
$this->send("ON");
|
|
}
|
|
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, $value));
|
|
}
|
|
|
|
private function send($state)
|
|
{
|
|
global $devices, $indexDevices;
|
|
$msg = array("state" => $state);
|
|
$device = & $indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU];
|
|
logger(INFO, sprintf(_("publishing message: %s to %s"), $msg, $device->friendlyName));
|
|
$device->payload = $msg;
|
|
$device->set(null);
|
|
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
|
|
}
|
|
}
|
|
|
|
$hooks["rdc_salon_eclairage"] = new rdc_salon_eclairage();
|
|
?>
|