diff --git a/apiserver/cmd_functions.php b/apiserver/cmd_functions.php
index 42ecc48..fe4623c 100644
--- a/apiserver/cmd_functions.php
+++ b/apiserver/cmd_functions.php
@@ -315,14 +315,14 @@ function apiGet($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($argList["topic"], $topics) )
{
$response = "SET: " . _("bad parameter passed: topic does not exists") . "
\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") . "
\n";
}
diff --git a/class/db.php b/class/db.php
index c4cc06e..6de043b 100644
--- a/class/db.php
+++ b/class/db.php
@@ -35,10 +35,11 @@ class db extends mysqli
return $this->real_escape_string($string);
}
- function logProperty($device, $property, $value, $oldValue = 0)
+ function logProperty(&$device, $property, $value)
{
global $mohaDB, $properties2log, $testMode;
$precision = 0;
+ $oldValue = $device->properties[$property]["lastValueLogged"];
//echo "############## logProperty ################\nproperty => " . $propertyTree .EOL;
//echo "logging in database";
//var_dump($device);
@@ -80,13 +81,14 @@ class db extends mysqli
{
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)
{
- $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__);
if(!$this->result = $this->query($query))
{
@@ -99,9 +101,6 @@ class db extends mysqli
logger(DEBUG, _("result is: ") . print_r($value, true), __FILE__ . ":" . __LINE__);
return $value[0];
}
-
-
-
}
}
diff --git a/config/devices_constants.php b/config/devices_constants.php
index 79ebee9..8ad1b13 100644
--- a/config/devices_constants.php
+++ b/config/devices_constants.php
@@ -15,7 +15,7 @@ $deviceTable = array(
"0x588e81fffe343e8f" => "RDC_SALON_ECLAIRAGE_PANNEAU",
"0x804b50fffef31656" => "RDC_SALON_RADIATEUR",
"0xbc33acfffe458c65" => "RDC_SDB_RADIATEUR",
- "0xa4c138b5a98db785" => "RDC_SDB_DOUCHE_MVMT",
+ "0xa4c1383c46112daf" => "RDC_SDB_DOUCHE_MVMT",
"0x842e14fffe1c0cd1" => "RDC_SDB_PLAFOND_MVMT",
"0x00124b0022ec05dc" => "RDC_SDB_MVMT",
"0x00158d0005c1a998" => "RDC_SDB_WC_ECLAIRAGE",
diff --git a/config/properties2log.php b/config/properties2log.php
index ba159d4..83b4ec5 100644
--- a/config/properties2log.php
+++ b/config/properties2log.php
@@ -13,7 +13,6 @@ $properties2log = array(
"local_temperature" => 0.5,
"state_l1" => null,
"state_l2" => null,
- "humidity" => 0.9,
"current_heating_setpoint" => null,
"position" => null,
"pressure" => 10,
@@ -22,7 +21,7 @@ $properties2log = array(
// "illuminance" => 8,
"requested_brightness_level" => function($value) {$r = ($value < 500?50:$value*10/100);return $r;},
"tempc" => 0.5,
- "humidity" => 1,
+ "humidity" => 2,
"dewptc" => 0.5,
"windchillc" => 0.5,
"winddir" => 40,
diff --git a/db_functions.php b/db_functions.php
index 954d866..3156c00 100644
--- a/db_functions.php
+++ b/db_functions.php
@@ -282,7 +282,7 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
if (array_key_exists($key, $properties2log))
{
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__);
}
$property["value"] = $value;
diff --git a/hooks/scripts/rdc_sdb_eclairage.php b/hooks/scripts/rdc_sdb_eclairage.php
index 4c33fd7..c5fc105 100644
--- a/hooks/scripts/rdc_sdb_eclairage.php
+++ b/hooks/scripts/rdc_sdb_eclairage.php
@@ -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;
diff --git a/hooks/scripts/rdc_store.php b/hooks/scripts/rdc_store.php
index 2f7b55c..68c5373 100644
--- a/hooks/scripts/rdc_store.php
+++ b/hooks/scripts/rdc_store.php
@@ -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);
diff --git a/hooks/scripts/rdc_wc_eclairage.php b/hooks/scripts/rdc_wc_eclairage.php
index 435d2b8..b7e1c46 100644
--- a/hooks/scripts/rdc_wc_eclairage.php
+++ b/hooks/scripts/rdc_wc_eclairage.php
@@ -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__);