added custom script plus some debugging
This commit is contained in:
75
hooks/scripts/rdc_sdb_eclairage.php
Normal file
75
hooks/scripts/rdc_sdb_eclairage.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
class rdc_sdb_eclairage
|
||||
{
|
||||
public $hookName = "rdc_sdb_eclairage";
|
||||
public $active = false;
|
||||
|
||||
// list of devices we are listening to
|
||||
// 0x00158d0003f0f3b4 douche mvmnt
|
||||
// 0x842e14fffe1c0cd1 plafond mvmnt
|
||||
// 0x00124b0022ec05dc mvmnt
|
||||
// 0x00158d0005c1a998 module commutateur => state_l1
|
||||
private $devicelist = array("0x00158d0003f0f3b4", "0x842e14fffe1c0cd1", "0x00124b0022ec05dc");
|
||||
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $delayManual = 15; // amount of time in $timeunit for manual mode
|
||||
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
||||
|
||||
function __construct()
|
||||
{
|
||||
global $indexDevices;
|
||||
|
||||
// assigne the function to the sensors devices
|
||||
if ($this->active === true)
|
||||
{
|
||||
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 == ON)
|
||||
{
|
||||
$this->send("ON");
|
||||
setDelay($device, $this->delay, $this->timeUnit, "state_l1", "OFF", true);
|
||||
$device->method = AUTO;
|
||||
}
|
||||
break;
|
||||
case "state_l1":
|
||||
if ($value == ON)
|
||||
{
|
||||
$this->send("ON");
|
||||
setDelay($device, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true);
|
||||
$device->method = MANUAL;
|
||||
}elseif ($value = OFF)
|
||||
{
|
||||
deleteEvent(searchEvent($device, "state_l1", "OFF"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
logger (INFO, _("%s: notification received from MQTT from %s => parameter: %s value: %s"), $hookName, $device["friendlyName"], $param, $value);
|
||||
}
|
||||
|
||||
private function send($state)
|
||||
{
|
||||
global $devices, $indexDevices;
|
||||
$msg = array("state_l1" => $state);
|
||||
$device = & $indexDevices["0x00158d0005c1a998"];
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), $msg, $device->friendlyName));
|
||||
$device->payload = $msg;
|
||||
$device->set(null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$hooks["rdc-sdb-eclairage"] = new rdc_sdb_eclairage();
|
||||
?>
|
Reference in New Issue
Block a user