1
0

some adjustments

This commit is contained in:
Daniel Tartavel 2022-08-27 00:02:24 +02:00
parent df94a6becf
commit f42df97c5c
10 changed files with 122 additions and 67 deletions

View File

@ -570,9 +570,20 @@ function apiDisplayByType($argList)
function test()
{
global $hooks;
$portes = array();
$msg = "";
logger(DEBUG, _("Testing doors") , __FILE__ . ":" . __LINE__);
echo "testing doors";
return $hooks["alerte_intrusion"]->testPortes();
$portes = $hooks["alerte_intrusion"]->testPortes();
if (!empty($portes))
{
foreach($portes as $value)
{
$msg .= $value . _(" is open") . EOL;
}
}
return nl2br($msg);
}
?>

View File

@ -5,7 +5,6 @@
// superior or inferior at value +/- x%
$properties2log = array(
"availability" => null,
"action" => null,
"state" =>null,
"contact" => null,

View File

@ -18,7 +18,7 @@ class availability extends hook
global $indexDevices;
foreach ($indexDevices as $ieeeAddress => $value)
{
$deviceList[] = array( $ieeeAdress => "availability");
$deviceList[] = array( $ieeeAddress => "availability");
}
$this->installHooksFunction($indexDevices);
}

View File

@ -28,30 +28,38 @@ class alerte_intrusion extends hook
case "contact":
if ($value == false)
{
logger(ALERT, sprintf(_("%s est ouverte alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__);
logger(ALERT, sprintf(_("%s vient de s'ouvrir alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__);
}else
{
logger(ALERT, sprintf(_("%s vient de se fermer alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__);
}
break;
}
}
public function testPortes()
public function testPortes($send=true) :array
{
global $indexDevices;
$portes = array();
logger(DEBUG, _("Function alerte_intrusion->testPorte"), __FILE__ . ":" . __LINE__);
$msg = "";
foreach ($this->devicelist as $device => $property)
{
if($indexDevices[$device]->properties[$property] != false)
if($indexDevices[$device]->properties[$property] == false)
{
$msg .= $indexDevices[$device]->friendlyName . " is open" . EOL;
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
}
if (!empty($msg))
if ($send)
{
logger(ALERT, $msg, __FILE__ . ":" . __LINE__);
logger(ALERT, _("doors opened :") . $msg, null ,$device);
}
return nl2br($msg);
return $portes;
}
}

View File

@ -9,7 +9,8 @@ class rdc_salon_eclairage extends hook
RDC_SALON_MVMT => "occupancy",
RDC_SALON_MVMT2 => "occupancy",
RDC_ENTREE_PORTE => "contact",
RDC_SALON_LUMINOSITE => "illuminance_lux"
RDC_SALON_LUMINOSITE => "illuminance_lux",
RDC_SALON_ECLAIRAGE_PANNEAU => "state"
);
protected $actionneurs = array(
array(RDC_SALON_MVMT, "occupancy", 1),
@ -34,15 +35,17 @@ class rdc_salon_eclairage extends hook
$lux = $indexDevices[RDC_SALON_LUMINOSITE];
$mvmt = $indexDevices[RDC_SALON_MVMT];
$mvmt2 = $indexDevices[RDC_SALON_MVMT2];
$method;
$illuminance = getValue(RDC_SALON_LUMINOSITE, "illuminance_lux");
logger (INFO, _("property => ") . $param . _("value =>") . bool2string($value), __FILE__ . ":" . __LINE__);
switch($param)
{
case "occupancy":
$method = $deviceTarget->properties["state"]["method"];
logger(INFO, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__);
//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
if ($value == ON)
if ($value == ON and $method == IDLE)
{
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
if ($illuminance <= $this->luminance_min)
@ -54,22 +57,24 @@ class rdc_salon_eclairage extends hook
}else
{
logger(INFO, _("Value is OFF"), __FILE__ . ":" . __LINE__);
if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
if ((getValue(RDC_SALON_MVMT, "occupancy") == OFF) and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF) and $method == AUTO)
{
logger(INFO, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
//$this->send($deviceTarget, "OFF", false, IDLE);
$this->send($deviceTarget, "OFF", false, IDLE);
removeEvent($deviceTarget, "state", "OFF");
}
}
break;
case "contact":
$method = $deviceTarget->properties["state"]["method"];
logger(INFO, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__);
if ($value == false and $illuminance <= $this->luminance_min)
if ($value == false and $illuminance <= $this->luminance_min and $method == IDLE)
{
logger(INFO, _("Door is open and illumance < min and method =>") . $deviceTarget->properties["state"]["method"], __FILE__ . ":" . __LINE__);
if ($deviceTarget->properties["state"]["method"] == IDLE)
if ($method == IDLE)
{
$this->send($deviceTarget, "ON", "OFF", AUTO);
$this->send($deviceTarget, "ON", false, AUTO);
removeEvent($deviceTarget, "state", "OFF");
}
}
break;
@ -78,17 +83,21 @@ class rdc_salon_eclairage extends hook
if ($value >= $this->luminance_max and $deviceTarget->properties["state"]["value"] == "ON")
{
logger(INFO, _("illuminace is > to max"), __FILE__ . ":" . __LINE__);
//$this->send($deviceTarget, "OFF", null, AUTO);
//removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF");
if (searchEvent($deviceTarget, "state", "OFF") === false)
{
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true, IDLE);
$this->send($deviceTarget, "OFF", false, IDLE);
removeEvent($deviceTarget, "state", "OFF");
}
}/*elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON || getValue(RDC_SALON_MVMT2,"occupancy") == ON))
break;
case "state":
logger(INFO, _("CASE : State"), __FILE__ . ":" . __LINE__);
$method = $deviceTarget->properties["state"]["method"];
if($value == "ON" and $method == IDLE)
{
logger(INFO, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "ON", false, AUTO);
}*/
$deviceTarget->properties["state"]["method"] = MANUAL;
removeEvent($deviceTarget, "state", "OFF");
}else
{
$deviceTarget->properties["state"]["method"] = IDLE;
}
break;
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $param, bool2string($value)), __FILE__ . ":" . __LINE__);
@ -99,17 +108,9 @@ class rdc_salon_eclairage extends hook
global $indexDevices;
$msg = array("state" => $state);
//if ($deviceTarget->properties["state"]["value"] != $state)
//{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
$deviceTarget->payload = $msg;
$deviceTarget->set("state", $method);
//$deviceTarget->properties["state"]["method"] = $method;
/*}else
{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
}*/
//echo 'delaystate = ' . var_dump($delayState);
if ($delayState !== false) setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", $delayState, true);
}
}

View File

@ -45,37 +45,40 @@ class rdc_sdb_eclairage extends hook
switch($property)
{
case "occupancy":
$method = $deviceTarget->properties["state_l1"]["method"];
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($value == ON)
{
if($deviceTarget->properties["state_l1"]["method"] == IDLE)
if($method == IDLE)
{
logger(DEBUG, _("lighting with method auto"), __FILE__ . ":" . __LINE__);
//$deviceTarget->properties["state_l1"]["method"] = AUTO;
$this->send("ON", AUTO);
removeEvent($deviceTarget, "state", "OFF");
}
}elseif (testActionneurs($this->actionneurs))
}elseif (!testActionneurs($this->actionneurs))
{
logger(DEBUG, _("Actionneurs are all false"), __FILE__ . ":" . __LINE__);
//setDelay($deviceTarget, $this->delay, $this->timeUnit, "state_l1", "OFF", true, IDLE);
$this->send("OFF", IDLE);
}
break;
case "state_l1":
$method = $deviceTarget->properties["state_l1"]["method"];
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($deviceTarget->properties["state_l1"]["method"] == IDLE)
if ($method == IDLE)
{
logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__);
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
removeEvent($deviceTarget, "state_l1", "OFF", MANUAL);
//setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}
}elseif ($value == "OFF")
{
removeEvent($deviceTarget, "state_l1", "OFF", IDLE);
$deviceTarget->properties["state_l1"]["method"] = IDLE;
logger(DEBUG, _("State_l1 is false light is off and method is ") . $deviceTarget->properties["state_l1"]["method"], __FILE__ . ":" . __LINE__);
//$deviceTarget->properties["state_l1"]["method"] = IDLE;
logger(DEBUG, _("State_l1 is false light is off and method is ") . $method, __FILE__ . ":" . __LINE__);
}
break;
}

View File

@ -156,9 +156,9 @@ class rdc_store extends hook
{
$store2level = $this->storeLevel + 15;
}
}elseif ($exterieurLuxMoyen < 6000 and $salon_lux < 200 and $soleil < 100)
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100)
{
logger(DEBUG, "exterieurLuxMoyen < 6000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__);
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}

View File

@ -23,7 +23,7 @@ class rdc_store extends hook
function installHooks(&$indexDevices)
{
$this->installHooksFunction($indexDevices);
return $this->installHooksFunction($indexDevices);
}
// callback fonction. Is called with these 3 parameters
@ -156,9 +156,9 @@ class rdc_store extends hook
{
$store2level = $this->storeLevel + 15;
}
}elseif ($exterieurLuxMoyen < 6000 and $salon_lux < 200 and $soleil < 100)
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 100 and $soleil < 100)
{
logger(DEBUG, "exterieurLuxMoyen < 6000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__);
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 100 and soleil < 100", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}

View File

@ -4,7 +4,9 @@ class rdc_temperature_int_ext extends hook
{
public $hookName = "rdc_wc_eclairage";
public $active = true; //enable/disable hook (true => enabled)
public $wantedTemp = 24;
public $tempSup = 25;
public $tempInf = 20;
protected $devicelist = array(
METEO=> "tempc",
@ -18,21 +20,52 @@ class rdc_temperature_int_ext extends hook
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $property, $value)
{
global $indexDevices;
static $status = -1;
global $indexDevices, $hooks;
static $time;
$portes = array();
$state = -1;
$msg = "";
$indoorTemp = $device->properties["indoortempc"]["value"];
if ( (($value > $this->wantedTemp and $indoorTemp < $this->wantedTemp) or ( $value < $this->wantedTemp and $indoorTemp >= $this->wantedTemp)) and $status === 1)
$portes = $hooks["alerte_intrusion"]->testPortes(false);
foreach($portes as $value)
{
$status = 0;
logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif ( (($value > $this->wantedTemp and $indoorTemp >= $this->wantedTemp) or ( $value < $this->wantedTemp and $indoorTemp <= $this->wantedTemp)) and $status === 0 )
$msg .= $value . "\n";
}
if ( $value > $indoorTemp)
{
if( ($indoorTemp <= $this->tempSup) and empty($portes))
{
$status = 1;
logger(ALERT, _("Close doors to climate"), null, $device);
//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);
}
if ($status == 1)
{
//if ($time - DateTime();
//logger(ALERT, _("Open doors to climate"), null ,$device);
}else
{
//logger(ALERT, _("Close doors to climate\n") . $msg, null, $device);
}
}
}
$hooks["rdc_temperature_int_ext"] = new rdc_temperature_int_ext();
?>

View File

@ -37,7 +37,7 @@ function checkTopicsAvailability()
}
}
function testActionneurs(array $actionneurs)
function testActionneurs(array $actionneurs) //return 0 for no actionneurs and 1 if one actionneur is on
{
global $indexDevices;
$r = 0;
@ -59,7 +59,7 @@ function testActionneurs(array $actionneurs)
logger(ERROR, _("no device : ") . $device[0] . bool2string($r), __FILE__ . ":" . __LINE__ );
}
}
return !$r;
return $r;
}
function htmlGetFriendlyNames($ieeeAddress = '')