daniel Tartavel
0d35b1ff3f
- beginning to add graphical stats - beginning to add device by type - added a dashboard "etage" - begining to add notification to multiple recipients in freemobile hook
80 lines
2.3 KiB
PHP
80 lines
2.3 KiB
PHP
<?php
|
|
|
|
class rdc_sdb_eclairage extends hook
|
|
{
|
|
public $hookName = "rdc_sdb_eclairage";
|
|
public $active = true;
|
|
|
|
/* already defined in hook class */
|
|
// public $active = true;
|
|
//public $initlialized = false;
|
|
|
|
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
|
|
// list of devices we are listening to
|
|
|
|
// devicelist[$ieeAddress][0] => property to watch
|
|
// devicelist[$ieeAddress][1] => initialized = true
|
|
protected $devicelist = array(
|
|
RDC_SDB_DOUCHE_MVMT => "occupancy",
|
|
RDC_SDB_PLAFOND_MVMT => "occupancy",
|
|
RDC_SDB_MVMT => "occupancy",
|
|
RDC_SDB_WC_ECLAIRAGE => "state_l1"
|
|
);
|
|
|
|
// callback fonction. Is called with these 3 parameters
|
|
public function callBack(&$device, $property, $value)
|
|
{
|
|
global $indexDevices;
|
|
//var_dump($value);
|
|
$deviceTarget = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
|
|
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
|
|
switch($property)
|
|
{
|
|
case "occupancy":
|
|
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
|
if ($value == ON )
|
|
{
|
|
$this->send("ON");
|
|
$device->method = AUTO;
|
|
}
|
|
break;
|
|
case "state_l1":
|
|
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
|
|
if ($value == "ON")
|
|
{
|
|
if ($device->method != MANUAL)
|
|
{
|
|
$delay = $this->delay;
|
|
$device->method = AUTO;
|
|
}else
|
|
{
|
|
$delay = $this->delayManual;
|
|
$device->method = MANUAL;
|
|
}
|
|
setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true);
|
|
}elseif ($value == "OFF")
|
|
{
|
|
removeEvent($deviceTarget, "state_l1", "OFF");
|
|
$device->method = null;
|
|
}
|
|
break;
|
|
}
|
|
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, ($value == 0 ? "OFF" : "ON")), __FILE__ . ":" . __LINE__);
|
|
}
|
|
|
|
private function send($state)
|
|
{
|
|
global $indexDevices;
|
|
$msg = array("state_l1" => $state);
|
|
$device = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
|
|
logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__);
|
|
$device->payload = $msg;
|
|
$device->set(null);
|
|
}
|
|
}
|
|
$hooks["rdc_sdb_eclairage"] = new rdc_sdb_eclairage();
|
|
|
|
?>
|