1
0

some debbuging :-(

This commit is contained in:
2022-06-10 12:44:09 +02:00
parent cde4d728cf
commit b2f79dd49c
8 changed files with 80 additions and 64 deletions

View File

@ -9,15 +9,15 @@ class rdc_sdb_eclairage extends hook
// public $active = true;
//public $initlialized = false;
public $delay = 3; // amount of time in $timeunit
public $delayManual = 15; // amount of time in $timeunit for manual mode
public $delay = 1; // amount of time in $timeunit
public $delayManual = 20; // amount of time in $timeunit for manual mode
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
// list of devices we are listening to
// devicelist[$ieeAddress][0] => property to watch
// devicelist[$ieeAddress][1] => initialized = true
protected $devicelist = array(
RDC_SDB_DOUCHE_MVMT => "occupancy",
//RDC_SDB_DOUCHE_MVMT => "occupancy",
RDC_SDB_PLAFOND_MVMT => "occupancy",
RDC_SDB_MVMT => "occupancy",
RDC_SDB_WC_ECLAIRAGE => "state_l1"
@ -40,12 +40,10 @@ class rdc_sdb_eclairage extends hook
{
$this->send("ON");
$deviceTarget->properties["state_l1"]["method"] = AUTO;
}
break;
case "state_l1":
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
}else
{
//$delay = $this->delay;
//setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true, IDLE);
if ($deviceTarget->properties["state_l1"]["method"] != AUTO)
{
$delay = $this->delayManual;
@ -56,7 +54,17 @@ class rdc_sdb_eclairage extends hook
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
}
setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}elseif ($value == "OFF")
}
break;
case "state_l1":
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
/*if ($value == "ON")
{
}else*/
if ($value == "OFF")
{
removeEvent($deviceTarget, "state_l1", "OFF");
$deviceTarget->properties["state_l1"]["method"] = IDLE;

View File

@ -10,7 +10,7 @@ class rdc_store extends hook
public $storeDownTime = 38;
public $storeUpTime = 41;
public $maxLevel;
protected $storeLevel;
public $storeLevel;
protected $propertyInitialized =array();
protected $devicelist = array(
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
@ -29,15 +29,17 @@ class rdc_store extends hook
{
global $mohaDB, $devices, $indexDevices;
if ($this->active)
logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__);
$rain = 0;
static $rainS;
$exterieur_lux = 0;
$exterieurLuxMoyen =0;
$salon_lux = 0;
$rafale = 0;
$soleil = 0;
$storeDevice = $indexDevices[RDC_STORE];
$this->maxLevel = 100;
//$this->maxLevel = 100;
$r = 100;
if (array_key_exists("position", $storeDevice->properties))
@ -51,12 +53,13 @@ class rdc_store extends hook
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
{
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
$exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5);
if ($exterieur_lux == 0)
{
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
$exterieurLuxMoyen = $exterieur_lux;
}
logger(DEBUG, "exterieur_lux=" . $exterieur_lux, __FILE__ . ":" . __LINE__);
logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
{
@ -67,6 +70,27 @@ class rdc_store extends hook
}
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
}
if ($exterieur_lux > 30000 or $salon_lux >600)
{
logger(DEBUG, "exterieur_lux > 30000 or salon_lux >600", __FILE__ . ":" . __LINE__);
if ($this->maxLevel != 0 and $salon_lux > 100)
{
$store2level = $this->storeLevel + 15;
if ( $store2level > $this->maxLevel )
{
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->set($this->maxLevel);
}else
{
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
$this->set($store2level);
}
}
}elseif ($exterieurLuxMoyen < 9000 and $salon_lux < 1000)
{
logger(DEBUG, "exterieurLuxMoyen < 9000 and salon_lux < 1000", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}
if (array_key_exists(METEO, $indexDevices))
{
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
@ -82,7 +106,11 @@ class rdc_store extends hook
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__);
}
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"]; //$mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
if ($rafale == 0)
{
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
@ -100,7 +128,7 @@ class rdc_store extends hook
return 0;
}elseif ($rafale != 0)
{
$this->maxLevel = ($r = 100 - round($rafale/5, 0, PHP_ROUND_HALF_UP)*10)<0 ? 0 : $r;
$this->maxLevel = ($r = 120 - round($rafale/4, 0, PHP_ROUND_HALF_UP)*10)<0 ? 0 : $r;
//$this->maxLevel = 100 / $rafale;
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
@ -108,30 +136,10 @@ class rdc_store extends hook
//$store2level = $this->maxLevel;
switch ($property)
{
case "illuminance_lux":
/*case "illuminance_lux":
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
if ($exterieur_lux > 30000 or $salon_lux >600)
{
logger(DEBUG, "exterieur_lux > 30000", __FILE__ . ":" . __LINE__);
if ($this->maxLevel != 0 and $salon_lux > 100)
{
$store2level = $this->storeLevel + 15;
if ( $store2level > $this->maxLevel )
{
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->set($this->maxLevel);
}else
{
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
$this->set($store2level);
}
}
}elseif ($exterieur_lux < 12000 and $salon_lux < 150)
{
logger(DEBUG, "exterieur_lux < 15000", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}
break;
break;*/
case "rainin":
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
$this->close("Pluie");
@ -153,11 +161,11 @@ class rdc_store extends hook
private function set ($level)
{
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
//if ($this->storeLevel < $level)
//{
if ($this->storeLevel < $level AND $level <=100)
{
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
$this->send(100 - $level);
//}else
}//else
/*{
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);
}*/
@ -166,7 +174,7 @@ class rdc_store extends hook
private function close ($reason)
{
if ($this->storeLevel != 0)
if ($this->storeLevel > 0)
{
logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__);
$this->send(100);

View File

@ -9,7 +9,7 @@ class rdc_wc_eclairage extends hook
RDC_WC_MVMT => "occupancy"
);
public $delay = 5; // amount of time in $timeunit
public $delay = 3; // amount of time in $timeunit
public $delayManual = 15; // amount of time in $timeunit for manual mode
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
@ -26,27 +26,29 @@ class rdc_wc_eclairage extends hook
logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($targetDevice->properties["state_l1"]["method"] !== AUTO)
if ($targetDevice->properties["state_l2"]["method"] !== AUTO)
{
$targetDevice->properties["state_l1"]["method"] = MANUAL;
//setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
$targetDevice->properties["state_l2"]["method"] = MANUAL;
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
}
}elseif ($value == "OFF")
{
removeEvent($device, "state_l2", "OFF", IDLE);
$targetDevice->properties["state_l2"]["method"] = IDLE;
removeEvent($device, "state_l2", "OFF");
}
break;
case "occupancy":
logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
if ($value == true)
if ($value == true and $targetDevice->properties["state_l2"]["method"] == IDLE)
{
$targetDevice->properties["state_l2"]["method"] = AUTO;
//setDelay($device, $this->delay, $this->timeUnit, "state_l2", "OFF", true,IDLE);
$this->send($targetDevice, "ON");
}elseif ($targetDevice->properties["state_l2"]["method"] != MANUAL)
}elseif ($value == false and $targetDevice->properties["state_l2"]["method"] != MANUAL)
{
$targetDevice->properties["state_l2"]["method"] = IDLE;
$this->send($targetDevice, "OFF");
//$targetDevice->properties["state_l2"]["method"] = IDLE;
//$this->send($targetDevice, "OFF");
setDelay($device, $this->delay, $this->timeUnit, "state_l2", "OFF", true, IDLE);
}
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);