1
0

some debbuging :-(

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

View File

@ -315,14 +315,14 @@ function apiGet($argList)
function apiSet($argList) function apiSet($argList)
{ {
global $indexFriendlyName; global $indexFriendlyNames, $topics;
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("value", $argList)) if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("value", $argList))
{ {
if (!array_key_exists($argList["topic"], $topics) ) if (!array_key_exists($argList["topic"], $topics) )
{ {
$response = "SET: " . _("bad parameter passed: topic does not exists") . "<br>\n"; $response = "SET: " . _("bad parameter passed: topic does not exists") . "<br>\n";
} }
if (!array_key_exists(!array_key_exists($argList["fn"], $indexFriendlyName))) if (!array_key_exists($argList["fn"], $indexFriendlyNames))
{ {
$response = "SET: " . _("bad parameter passed: fn does not exists") . "<br>\n"; $response = "SET: " . _("bad parameter passed: fn does not exists") . "<br>\n";
} }

View File

@ -35,10 +35,11 @@ class db extends mysqli
return $this->real_escape_string($string); return $this->real_escape_string($string);
} }
function logProperty($device, $property, $value, $oldValue = 0) function logProperty(&$device, $property, $value)
{ {
global $mohaDB, $properties2log, $testMode; global $mohaDB, $properties2log, $testMode;
$precision = 0; $precision = 0;
$oldValue = $device->properties[$property]["lastValueLogged"];
//echo "############## logProperty ################\nproperty => " . $propertyTree .EOL; //echo "############## logProperty ################\nproperty => " . $propertyTree .EOL;
//echo "logging in database"; //echo "logging in database";
//var_dump($device); //var_dump($device);
@ -80,13 +81,14 @@ class db extends mysqli
{ {
logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__); logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
} }
} $device->properties[$property]["lastValueLogged"] = $value;
logger(INFO, sprintf(_("New value (%s) of property: '%s' of device: %s stored in database"), bool2string($value), $property, $device->friendlyName), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("New value (%s) of property: '%s' of device: %s stored in database"), bool2string($value), $property, $device->friendlyName), __FILE__ . ":" . __LINE__);
} }
}
function moyenne($deviceObject, $property, $time) function moyenne($deviceObject, $property, $time)
{ {
$query = "SELECT AVG(value) as value FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), date) < '00:" . $time . "'"; $query = "SELECT AVG(value) as value FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), date) < '00:" . str_pad($time, 2, "0", STR_PAD_LEFT ) . "'";
logger(DEBUG, _("query is: ") . $query, __FILE__ . ":" . __LINE__); logger(DEBUG, _("query is: ") . $query, __FILE__ . ":" . __LINE__);
if(!$this->result = $this->query($query)) if(!$this->result = $this->query($query))
{ {
@ -99,9 +101,6 @@ class db extends mysqli
logger(DEBUG, _("result is: ") . print_r($value, true), __FILE__ . ":" . __LINE__); logger(DEBUG, _("result is: ") . print_r($value, true), __FILE__ . ":" . __LINE__);
return $value[0]; return $value[0];
} }
} }
} }

View File

@ -15,7 +15,7 @@ $deviceTable = array(
"0x588e81fffe343e8f" => "RDC_SALON_ECLAIRAGE_PANNEAU", "0x588e81fffe343e8f" => "RDC_SALON_ECLAIRAGE_PANNEAU",
"0x804b50fffef31656" => "RDC_SALON_RADIATEUR", "0x804b50fffef31656" => "RDC_SALON_RADIATEUR",
"0xbc33acfffe458c65" => "RDC_SDB_RADIATEUR", "0xbc33acfffe458c65" => "RDC_SDB_RADIATEUR",
"0xa4c138b5a98db785" => "RDC_SDB_DOUCHE_MVMT", "0xa4c1383c46112daf" => "RDC_SDB_DOUCHE_MVMT",
"0x842e14fffe1c0cd1" => "RDC_SDB_PLAFOND_MVMT", "0x842e14fffe1c0cd1" => "RDC_SDB_PLAFOND_MVMT",
"0x00124b0022ec05dc" => "RDC_SDB_MVMT", "0x00124b0022ec05dc" => "RDC_SDB_MVMT",
"0x00158d0005c1a998" => "RDC_SDB_WC_ECLAIRAGE", "0x00158d0005c1a998" => "RDC_SDB_WC_ECLAIRAGE",

View File

@ -13,7 +13,6 @@ $properties2log = array(
"local_temperature" => 0.5, "local_temperature" => 0.5,
"state_l1" => null, "state_l1" => null,
"state_l2" => null, "state_l2" => null,
"humidity" => 0.9,
"current_heating_setpoint" => null, "current_heating_setpoint" => null,
"position" => null, "position" => null,
"pressure" => 10, "pressure" => 10,
@ -22,7 +21,7 @@ $properties2log = array(
// "illuminance" => 8, // "illuminance" => 8,
"requested_brightness_level" => function($value) {$r = ($value < 500?50:$value*10/100);return $r;}, "requested_brightness_level" => function($value) {$r = ($value < 500?50:$value*10/100);return $r;},
"tempc" => 0.5, "tempc" => 0.5,
"humidity" => 1, "humidity" => 2,
"dewptc" => 0.5, "dewptc" => 0.5,
"windchillc" => 0.5, "windchillc" => 0.5,
"winddir" => 40, "winddir" => 40,

View File

@ -282,7 +282,7 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
if (array_key_exists($key, $properties2log)) if (array_key_exists($key, $properties2log))
{ {
logger(INFO, sprintf(_("Logging Device property %s, %s"), $propertyTree . $key, bool2string($value)), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("Logging Device property %s, %s"), $propertyTree . $key, bool2string($value)), __FILE__ . ":" . __LINE__);
$mohaDB->logProperty($parentDevice, $key, $value, $property["value"]); $mohaDB->logProperty($parentDevice, $key, $value);
logger(DEBUG, sprintf(_("old value was %s, new is %s" ), bool2string($property["value"]), bool2string($value)), __FILE__ . ":" . __LINE__); logger(DEBUG, sprintf(_("old value was %s, new is %s" ), bool2string($property["value"]), bool2string($value)), __FILE__ . ":" . __LINE__);
} }
$property["value"] = $value; $property["value"] = $value;

View File

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

View File

@ -10,7 +10,7 @@ class rdc_store extends hook
public $storeDownTime = 38; public $storeDownTime = 38;
public $storeUpTime = 41; public $storeUpTime = 41;
public $maxLevel; public $maxLevel;
protected $storeLevel; public $storeLevel;
protected $propertyInitialized =array(); protected $propertyInitialized =array();
protected $devicelist = array( protected $devicelist = array(
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
@ -29,15 +29,17 @@ class rdc_store extends hook
{ {
global $mohaDB, $devices, $indexDevices; global $mohaDB, $devices, $indexDevices;
if ($this->active)
logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__); logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__);
$rain = 0; $rain = 0;
static $rainS; static $rainS;
$exterieur_lux = 0; $exterieur_lux = 0;
$exterieurLuxMoyen =0;
$salon_lux = 0; $salon_lux = 0;
$rafale = 0; $rafale = 0;
$soleil = 0; $soleil = 0;
$storeDevice = $indexDevices[RDC_STORE]; $storeDevice = $indexDevices[RDC_STORE];
$this->maxLevel = 100; //$this->maxLevel = 100;
$r = 100; $r = 100;
if (array_key_exists("position", $storeDevice->properties)) 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)) 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) 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)) 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__); 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(METEO, $indexDevices))
{ {
if (array_key_exists("rainin", $indexDevices[METEO]->properties)) 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__); 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__); logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
} }
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties)) if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
@ -100,7 +128,7 @@ class rdc_store extends hook
return 0; return 0;
}elseif ($rafale != 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; //$this->maxLevel = 100 / $rafale;
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
} }
@ -108,30 +136,10 @@ class rdc_store extends hook
//$store2level = $this->maxLevel; //$store2level = $this->maxLevel;
switch ($property) switch ($property)
{ {
case "illuminance_lux": /*case "illuminance_lux":
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
if ($exterieur_lux > 30000 or $salon_lux >600)
{ break;*/
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;
case "rainin": case "rainin":
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
$this->close("Pluie"); $this->close("Pluie");
@ -153,11 +161,11 @@ class rdc_store extends hook
private function set ($level) private function set ($level)
{ {
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); 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__); logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
$this->send(100 - $level); $this->send(100 - $level);
//}else }//else
/*{ /*{
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__); 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) private function close ($reason)
{ {
if ($this->storeLevel != 0) if ($this->storeLevel > 0)
{ {
logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__); logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__);
$this->send(100); $this->send(100);

View File

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