1
0
moha/hooks/scripts/rdc_chambre_eclairage.php
daniel Tartavel 0d35b1ff3f - 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
2022-03-28 00:40:34 +02:00

69 lines
2.7 KiB
PHP

<?php
class rdc_chambre_eclairage extends hook
{
public $hookName = "rdc_chambre_eclairage";
public $active = true; //enable/disable hook (true => enabled)
public $delay = 5; // amount of time in $timeunit
public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year
public $luminance_min = 60;
public $luminance_max = 3000;
protected $devicelist = array(
RDC_CHAMBRE_AMBIANCE => "state", // "ON"/"OFF"
RDC_CHAMBRE_ECLAIRAGE => "state_l1", // "ON"/"OFF"
RDC_CHAMBRE_MVMT => "occupancy",
RDC_CHAMBRE_ARMOIRE_GAUCHE => "contact"
);
// 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)
{
global $devices, $indexDevices;
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
if ($property == "occupancy" and $value == ON)
{
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
$this->send($targetAmbiance, "state", "ON", "OFF", AUTO);
}elseif ($property == "contact")
{
if ($value == false)
{
$this->send($targetEclairage, "state_l1", "ON", "OFF", AUTO);
}elseif ($value == true)
{
$this->send($targetEclairage, "state_l1", "OFF", false, null);
}
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
}
private function send(&$deviceObject, $property, $state, $delayState = false, $method = MANUAL)
{
global $indexDevices;
$msg = array($property => $state);
//if ($deviceObject->properties[$property]["value"] != $state)
//{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set();
$deviceObject->method = $method;
///}else
/*{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
}*/
//echo 'delaystate = ' . var_dump($delayState);
if ($delayState !== false) setDelay($deviceObject, $this->delay, $this->timeUnit, "state", $delayState, true);
}
}
$hooks["rdc_chambre_eclairage"] = new rdc_chambre_eclairage();
?>