1
0
moha/hooks/scripts/rdc_salon_eclairage.php

66 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2022-01-17 00:18:50 +01:00
class rdc_salon_eclairage extends hook
{
public $hookName = "rdc_salon_eclairage";
2022-01-01 06:26:02 +01:00
// list of devices we are listening to
2022-01-17 00:18:50 +01:00
protected $devicelist = array(
RDC_SALON_MVMT => array("occupancy", false),
RDC_SALON_MVMT2 => array("occupancy", false),
RDC_ENTREE_PORTE => array("contact", false),
RDC_SALON_LUMINOSITE => array("illuminance_lux", false)
);
2022-01-01 06:26:02 +01:00
public $delay = 3; // amount of time in $timeunit
2022-01-02 18:14:13 +01:00
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
2022-01-06 13:03:26 +01:00
public $luminance_min = 60;
public $luminance_max = 3000;
2022-01-01 06:26:02 +01:00
// callback fonction. Is called with these 4 parameters
2022-01-02 18:14:13 +01:00
public function callBack(&$device, $param, $value)
{
global $devices, $indexDevices;
switch($param)
{
case "occupancy":
if ($value == 1 and $indexDevices[RDC_SALON_LUMINOSITE]->illuminance_lux["value"] <= $this->luminance_min)
2022-01-02 18:14:13 +01:00
{
$this->send("ON");
}
break;
case "contact":
if ($value == false and $indexDevices[RDC_SALON_LUMINOSITE]->illuminance_lux["value"] <= $this->luminance_min)
2022-01-02 18:14:13 +01:00
{
$this->send("ON");
}
break;
case "illuminance_lux":
2022-01-02 18:14:13 +01:00
if ($value >= $this->luminance_max) $this->send("OFF");
break;
}
2022-01-04 08:54:06 +01:00
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $param, $value));
}
2022-01-02 18:14:13 +01:00
private function send($state)
{
global $devices, $indexDevices;
$device = & $indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU];
2022-01-17 00:18:50 +01:00
if ($device->state["value"] != $state)
2022-01-06 13:03:26 +01:00
{
$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));
}
}
}
$hooks["rdc_salon_eclairage"] = new rdc_salon_eclairage();
?>