1
0
moha/hooks/scripts/rdc_temperature_int_ext.php

82 lines
2.2 KiB
PHP
Raw Normal View History

<?php
// script to prevent when exterior temperature become inferior or superior to interior one
class rdc_temperature_int_ext extends hook
{
public $hookName = "rdc_wc_eclairage";
public $active = true; //enable/disable hook (true => enabled)
2022-08-27 00:02:24 +02:00
public $tempSup = 25;
public $tempInf = 20;
protected $devicelist = array(
METEO=> "tempc",
);
function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $property, $value)
{
2022-08-27 00:02:24 +02:00
global $indexDevices, $hooks;
static $time;
$portes = array();
$status = -1;
2022-08-27 00:02:24 +02:00
$msg = "";
if (empty($time)) $time = now();
$indoorTemp = $device->properties["indoortempc"]["value"];
2022-08-27 00:02:24 +02:00
if ( $value > $indoorTemp)
{
2022-08-27 00:02:24 +02:00
if( ($indoorTemp <= $this->tempSup) and empty($portes))
{
$status = 1;
//logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif($indoorTemp >= $this -> tempSup and ! empty($portes))
{
$status = 0;
//logger(ALERT, _("Close doors to climate"), null, $device);
}
}elseif ( $value < $indoorTemp )
{
2022-08-27 00:02:24 +02:00
if (($indoorTemp >= $this->tempSup) and empty($portes) )
{
$status = 1;
//logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif ($indoorTemp <= $this->tempSup)
{
$status = 0;
//logger(ALERT, _("Close doors to climate"), null, $device);
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__, $device);
}
$portes = $hooks["alerte_intrusion"]->testPortes(false, true);
2022-08-27 00:02:24 +02:00
if ($status == 1)
{
if (empty($portes) and ($time->diff(now())->format("i")) > 5)
{
logger(ALERT, _("Open doors to climate"), null, $device);
$time = now();
}
2022-08-27 00:02:24 +02:00
}else
{
//$portes = $hooks["alerte_intrusion"]->testPortes(false, true);
if (!empty($portes) and ($time.diff(now()).format("i") > 5))
{
$time = now();
foreach($portes as $porte)
{
$msg .= $porte . "\n";
logger(ALERT, _("Close doors to climate\n") . $msg, null, $device);
}
}
}
}
}
$hooks["rdc_temperature_int_ext"] = new rdc_temperature_int_ext();
?>