2021-12-31 23:09:58 +01:00
|
|
|
<?php
|
2022-01-01 06:26:02 +01:00
|
|
|
class rdc_panneau_salon
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
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-01 21:32:17 +01:00
|
|
|
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
2021-12-31 23:09:58 +01:00
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
global $indexDevices;
|
|
|
|
foreach ($this->devicelist as $ieeeAddress)
|
|
|
|
{
|
|
|
|
$indexDevices[$ieeeAddress]->functions[] = array($this,"callback");
|
|
|
|
//print_r($indexDevices[$ieeeAddress]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:26:02 +01:00
|
|
|
// callback fonction. Is called with these 4 parameters
|
2021-12-31 23:09:58 +01:00
|
|
|
public function callBack($topic, $fn, $param, $value)
|
|
|
|
{
|
|
|
|
global $devices, $indexDevices;
|
|
|
|
switch($param)
|
|
|
|
{
|
|
|
|
case "occupancy":
|
|
|
|
if ($value == 1) $this->send();
|
|
|
|
break;
|
|
|
|
case "contact":
|
|
|
|
if ($value == false) $this->send();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
echo _("notification received from MQTT") . EOL;
|
|
|
|
//echo $param . "=> " . $value . EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function send()
|
|
|
|
{
|
|
|
|
global $devices, $indexDevices;
|
|
|
|
if ($indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= 76)
|
|
|
|
{
|
|
|
|
$msg = array("state" => "ON");
|
|
|
|
$device = & $indexDevices["0x588e81fffe343e8f"];
|
|
|
|
$device->payload = $msg;
|
|
|
|
$device->set(null);
|
|
|
|
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 06:26:02 +01:00
|
|
|
$hooks["rdc/panneau/salon"] = new rdc_panneau_salon();
|
2021-12-31 23:09:58 +01:00
|
|
|
//assignation of the function to the sensors devices
|
|
|
|
//$indexDevices["0x00124b0022ebac5c"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt2
|
|
|
|
//$indexDevices["0x588e81fffe2cf695"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt
|
|
|
|
//$indexDevices["0x00124b001f900753"]->functions[] = array($panneau_salon,"getCallback"); // rdc-porte-entree
|
|
|
|
//$indexDevices["0x04cf8cdf3c78aff0"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-luminosite
|
|
|
|
?>
|