62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
class rdc_panneau_salon
|
|
{
|
|
// list of devices we are listening to
|
|
private $devicelist = array("0x00124b0022ebac5c", "0x588e81fffe2cf695", "0x00124b001f900753", "0x04cf8cdf3c78aff0");
|
|
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
|
|
foreach ($this->devicelist as $ieeeAddress)
|
|
{
|
|
$indexDevices[$ieeeAddress]->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["0x04cf8cdf3c78aff0"]->illuminance_lux <= $this->luminance_min)
|
|
{
|
|
$this->send("ON");
|
|
}
|
|
break;
|
|
case "contact":
|
|
if ($value == false and $indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= $this->luminance_min)
|
|
{
|
|
$this->send("ON");
|
|
}
|
|
break;
|
|
case "illuminance_lux":
|
|
if ($value >= $this->luminance_max) $this->send("OFF");
|
|
}
|
|
echo _("notification received from MQTT") . EOL;
|
|
//echo $param . "=> " . $value . EOL;
|
|
}
|
|
|
|
private function send($state)
|
|
{
|
|
global $devices, $indexDevices;
|
|
$msg = array("state" => $state);
|
|
$device = & $indexDevices["0x588e81fffe343e8f"];
|
|
logger(INFO, _("publishing ") . $msg . _(" message: ") . $device->friendlyName);
|
|
$device->payload = $msg;
|
|
$device->set(null);
|
|
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
|
|
}
|
|
}
|
|
|
|
$hooks["rdc/panneau/salon"] = new rdc_panneau_salon();
|
|
?>
|