modified init and some debugging
This commit is contained in:
62
hooks/scripts/availability.php
Normal file
62
hooks/scripts/availability.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
class availability
|
||||
{
|
||||
// by default all devices are listening for availability
|
||||
|
||||
function __construct()
|
||||
{
|
||||
global $devices;
|
||||
$this->iterate($devices);
|
||||
}
|
||||
|
||||
private function iterate(& $device)
|
||||
{
|
||||
foreach ($device as $key => $value)
|
||||
{
|
||||
if (gettype($value) == "array")
|
||||
{
|
||||
$this->iterate($value);
|
||||
}elseif (is_a($value, "device"))
|
||||
{
|
||||
|
||||
$value->availability["functions"][] = array($this,"callback");
|
||||
}
|
||||
}
|
||||
}
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
// $device -> calling device
|
||||
// $property -> parameter passed by mqtt
|
||||
// $value -> value of the parameter
|
||||
public function callBack($device, $property, $value)
|
||||
{
|
||||
switch($property)
|
||||
{
|
||||
case "availability": // theorically can't be other, but ....
|
||||
if ($device->availability != $value)
|
||||
{
|
||||
//echo "==========>>>>>> Availability $value" . EOL;
|
||||
if (!empty($device->availability))
|
||||
{
|
||||
$log = WARNING;
|
||||
}else
|
||||
{
|
||||
$log = INFO;
|
||||
}
|
||||
$device->availability = $value;
|
||||
logger($log, sprintf(_("Device: %s/%s is %s"), $device->topic, $device->friendlyName, $value));
|
||||
}
|
||||
break;
|
||||
}
|
||||
//echo sprintf(_("notification received from MQTT -> device %s is %s"), $device->friendlyName , $value). EOL;
|
||||
//echo $property . "=> " . $value . EOL;
|
||||
}
|
||||
/*
|
||||
public function getHook()
|
||||
{
|
||||
return array($this,"callback");
|
||||
}*/
|
||||
}
|
||||
|
||||
$hooks["availability"] = new availability();
|
||||
?>
|
44
hooks/scripts/rdc_portes_ouvertes.php
Normal file
44
hooks/scripts/rdc_portes_ouvertes.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
class alerte_intrusion
|
||||
{
|
||||
public $hookName = "alerte_intrusion";
|
||||
public $active = true;
|
||||
|
||||
private $devicelist = array(ENTREE_PORTE => "contact", GARAGE_PORTE => "contact", RDC_CHAMBRE_BAIE => "contact", RDC_SALON_BAIE => "contact");
|
||||
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $delayManual = 10; // 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 => $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 "contact":
|
||||
if ($value == false)
|
||||
{
|
||||
logger(ALERT, sprintf(_("%s est ouverte alors que personne n'est présent"), $device->friendlyName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$hooks["alerte_intrusion"] = new alerte_intrusion();
|
||||
|
||||
?>
|
@@ -14,7 +14,7 @@ class rdc_salon_eclairage
|
||||
|
||||
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_min = 60;
|
||||
public $luminance_max = 3000;
|
||||
|
||||
|
||||
@@ -60,12 +60,19 @@ class rdc_salon_eclairage
|
||||
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);
|
||||
if ($device->state_l1["value"] != $state)
|
||||
{
|
||||
$msg = array("state" => $state);
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName));
|
||||
$device->payload = $msg;
|
||||
$device->set(null);
|
||||
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
|
||||
}else
|
||||
{
|
||||
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $device->friendlyName));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,17 +3,22 @@
|
||||
class rdc_sdb_eclairage
|
||||
{
|
||||
public $hookName = "rdc_sdb_eclairage";
|
||||
public $active = false;
|
||||
public $active = true;
|
||||
|
||||
// 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");
|
||||
private $devicelist = array(
|
||||
"0x00158d0003f0f3b4" => "occupancy",
|
||||
"0x842e14fffe1c0cd1" => "occupancy",
|
||||
"0x00124b0022ec05dc" => "occupancy",
|
||||
RDC_SDB_WC_ECLAIRAGE => "state_l1"
|
||||
);
|
||||
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $delayManual = 15; // amount of time in $timeunit for manual mode
|
||||
public $delayManual = 10; // amount of time in $timeunit for manual mode
|
||||
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
||||
|
||||
function __construct()
|
||||
@@ -23,18 +28,19 @@ class rdc_sdb_eclairage
|
||||
// assigne the function to the sensors devices
|
||||
if ($this->active === true)
|
||||
{
|
||||
foreach ($this->devicelist as $ieeeAddress => $param)
|
||||
foreach ($this->devicelist as $ieeeAddress => $property)
|
||||
{
|
||||
$indexDevices[$ieeeAddress]->$param["functions"][] = array($this,"callback");
|
||||
$indexDevices[$ieeeAddress]->$property["functions"][] = array($this,"callback");
|
||||
print_r($indexDevices[$ieeeAddress]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// callback fonction. Is called with these 4 parameters
|
||||
public function callBack(&$device, $param, $value)
|
||||
public function callBack(&$device, $property, $value)
|
||||
{
|
||||
global $devices, $indexDevices;
|
||||
switch($param)
|
||||
switch($property)
|
||||
{
|
||||
case "occupancy":
|
||||
if ($value == ON)
|
||||
@@ -47,7 +53,6 @@ class rdc_sdb_eclairage
|
||||
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)
|
||||
@@ -56,7 +61,7 @@ class rdc_sdb_eclairage
|
||||
}
|
||||
break;
|
||||
}
|
||||
logger (INFO, _("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $param, $value);
|
||||
logger (INFO, _("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value);
|
||||
}
|
||||
|
||||
private function send($state)
|
||||
@@ -67,7 +72,6 @@ class rdc_sdb_eclairage
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), $msg, $device->friendlyName));
|
||||
$device->payload = $msg;
|
||||
$device->set(null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
50
hooks/scripts/rdc_wc_eclairage.php
Normal file
50
hooks/scripts/rdc_wc_eclairage.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
class rdc_wc_eclairage
|
||||
{
|
||||
public $hookName = "rdc_wc_eclairage";
|
||||
public $active = true;
|
||||
|
||||
private $devicelist = array(RDC_SDB_WC_ECLAIRAGE => "state_l2");
|
||||
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $delayManual = 10; // 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 => $property)
|
||||
{
|
||||
$indexDevices[$ieeeAddress]->$property["functions"][] = array($this,"callback");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// callback fonction. Is called with these 4 parameters
|
||||
public function callBack(&$device, $property, $value)
|
||||
{
|
||||
global $devices, $indexDevices;
|
||||
switch($property)
|
||||
{
|
||||
case "state_l2":
|
||||
if ($value == ON)
|
||||
{
|
||||
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
|
||||
$device->method = MANUAL;
|
||||
}elseif ($value = OFF)
|
||||
{
|
||||
deleteEvent(searchEvent($device, "state_l2", "OFF"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
logger (INFO, _("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$hooks["rdc_wc_eclairage"] = new rdc_wc_eclairage();
|
||||
?>
|
Reference in New Issue
Block a user