DTux
/
dtux__moha
Archived
1
0
Fork 0
This commit is contained in:
Daniel Tartavel 2022-09-03 21:13:57 +02:00
parent a89cdd9b99
commit 7874ea1b7f
1 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,106 @@
<?php
// script to prevent when exterior temperature become inferior or superior to interior one
class etage_temperature_int_ext extends hook
{
public $hookName = "etage_temperature_int_ext";
public $active = false; //enable/disable hook (true => enabled)
public $tempSup = 25;
public $tempInf = 20;
protected $devicelist = array(
METEO=> "tempc",
);
protected $portesList = array(
ENTREE_PORTE => "contact",
//GARAGE_PORTE => "contact",
RDC_CHAMBRE_BAIE => "contact",
RDC_SALON_BAIE => "contact"
);
function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $property, $value)
{
global $indexDevices, $hooks;
static $time;
$portes = array();
$status = -1;
$msg = "";
if ($this->active)
{
logger(DEBUG, _("etage_temperature_int_ext hook"), null ,$device);
if (empty($time)) $time = now();
//echo "Time is " . var_dump($time) . EOL;
//echo "minutes since time :" . now()->format("U") - $time->format("U");
if ((now()->format("U") - $time->format("U")) > 300)
{
$indoorTemp = $device->properties["indoortempc"]["value"];
if ( $value > $indoorTemp)
{
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 )
{
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);
}
print_r($portes);
if ($status == 1)
{
$portes = $hooks["test_portes"]->testPortes($this->portesList, false, false);
if (empty($portes))
{
$time = now();
foreach($portes as $porte)
{
$msg .= $porte . "\n";
}
logger(ALERT, _("Open doors to climate") . $msg, null, $device);
}
}else
{
$portes = $hooks["test_portes"]->testPortes($this->portesList, false, true);
if (!empty($portes))
{
$time = now();
foreach($portes as $porte)
{
$msg .= $porte . "\n";
}
logger(ALERT, _("Close doors to climate\n") . $msg, null, $device);
}
}
}
}else
{
logger(DEBUG, _("etage_temperature_int_ext hook is inactive"), null ,$device);
}
}
}
$hooks["etage_temperature_int_ext"] = new etage_temperature_int_ext();
?>