1
0

finished rdc_temperature_int_ext.php\ncontinued events.php (recurrence)

This commit is contained in:
2022-08-28 00:06:24 +02:00
parent f42df97c5c
commit b5c30b1ae4
6 changed files with 209 additions and 90 deletions

View File

@ -11,7 +11,10 @@ class alerte_intrusion extends hook
GARAGE_PORTE => "contact",
RDC_CHAMBRE_BAIE => "contact",
RDC_SALON_BAIE => "contact",
GARAGE_PORTAIL => "contact"
GARAGE_PORTAIL => "contact",
ETAGE_SALON_FENETRE => "contact",
ETAGE_CUISINE_FENETRE => "contact",
ETAGE_PORTE_FENETRE => "contact"
);
function installHooks(&$indexDevices)
@ -40,7 +43,7 @@ class alerte_intrusion extends hook
}
}
public function testPortes($send=true) :array
public function testPortes($send=true, $opened=true) :array
{
global $indexDevices;
$portes = array();
@ -49,10 +52,20 @@ class alerte_intrusion extends hook
$msg = "";
foreach ($this->devicelist as $device => $property)
{
if($indexDevices[$device]->properties[$property] == false)
if (!$opened)
{
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
if($indexDevices[$device]->properties[$property] == false)
{
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
}else
{
if($indexDevices[$device]->properties[$property] == true)
{
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
}
}
if ($send)
@ -66,6 +79,6 @@ class alerte_intrusion extends hook
$hooks["alerte_intrusion"] = new alerte_intrusion();
logger(DEBUG, _("Initializing event"), __FILE__ . ":" . __LINE__);
$function = array($hooks["alerte_intrusion"], "testPortes");
setRecurrentEvent($function, 0, 0, 0, 0, 0, 0, 21, 0, 0, 1, 0, 0, 0);
setRecurrentEvent($function, 0, 0, 0, false, 0, 0, 21, 0, 0, 0, 0, 0, 0);
?>

View File

@ -23,15 +23,12 @@ class rdc_temperature_int_ext extends hook
global $indexDevices, $hooks;
static $time;
$portes = array();
$state = -1;
$status = -1;
$msg = "";
if (empty($time)) $time = now();
$indoorTemp = $device->properties["indoortempc"]["value"];
$portes = $hooks["alerte_intrusion"]->testPortes(false);
foreach($portes as $value)
{
$msg .= $value . "\n";
}
if ( $value > $indoorTemp)
{
@ -57,13 +54,26 @@ class rdc_temperature_int_ext extends hook
}
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);
if ($status == 1)
{
//if ($time - DateTime();
//logger(ALERT, _("Open doors to climate"), null ,$device);
if (empty($portes) and ($time->diff(now())->format("i")) > 5)
{
logger(ALERT, _("Open doors to climate"), null, $device);
$time = now();
}
}else
{
//logger(ALERT, _("Close doors to climate\n") . $msg, null, $device);
//$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);
}
}
}
}
}