- lots of debugging
- 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
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
class etage_plan_travail_eclairage extends hook
|
||||
{
|
||||
public $hookName = "etage_plan_travail_eclairage";
|
||||
public $active = false; //enable/disable hook (true => enabled)
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $timeUnit = "hour"; // unit of time for delay, second, minute, hour, day, week, month, year
|
||||
protected $devicelist = array(ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE => "state");
|
||||
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
// $device -> calling device
|
||||
// $property -> property of the device (given by mqtt)
|
||||
// $value -> value of the property
|
||||
public function callBack($device, $property, $value)
|
||||
{
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
// here your code
|
||||
if($value == "ON") // ON
|
||||
{
|
||||
$this->send("ON", "OFF");
|
||||
}elseif($value == "OFF")
|
||||
{
|
||||
$this->send("OFF", null, AUTO);
|
||||
}
|
||||
logger (INFO,sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value));
|
||||
}
|
||||
|
||||
private function send($state, $delayState = false, $method = MANUAL)
|
||||
{
|
||||
global $devices, $indexDevices;
|
||||
$device = & $indexDevices[ETAGE_CUISINE_PLAN_TRAVAIL_SPOT];
|
||||
$msg = array("state_l1" => $state);
|
||||
if ($device->state_l1["value"] != $state)
|
||||
{
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName));
|
||||
$device->payload = $msg;
|
||||
$device->set();
|
||||
$device->method = $method;
|
||||
}else
|
||||
{
|
||||
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $device->friendlyName));
|
||||
}
|
||||
//echo 'delaystate = ' . var_dump($delayState);
|
||||
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true);
|
||||
}
|
||||
}
|
||||
|
||||
$hooks["etage_plan_travail_eclairage"] = new etage_plan_travail_eclairage();
|
||||
?>
|
||||
Reference in New Issue
Block a user