debug rdc_store et rdc_wc_eclairage\nmise en page constant.php
This commit is contained in:
parent
71c8ce246f
commit
da3f4ab51f
@ -5,8 +5,10 @@ define("EOL", "\n");
|
||||
define("EOLR", "\n\r");
|
||||
define("EOLH", "<br>\n");
|
||||
define("Z2M", "zigbee2mqtt");
|
||||
|
||||
define("ON", true);
|
||||
define("OFF", false);
|
||||
|
||||
define("IDLE", 1);
|
||||
define("AUTO", 2);
|
||||
define("MANUAL", 3);
|
||||
|
@ -42,6 +42,7 @@ class rdc_store extends hook
|
||||
$r = 100;
|
||||
$moving = "STOP";
|
||||
$motorReversal = false;
|
||||
$store2level = false;
|
||||
|
||||
if (array_key_exists("moving", $storeDevice->properties))
|
||||
{
|
||||
@ -102,15 +103,6 @@ class rdc_store extends hook
|
||||
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 < 5000 and $salon_lux < 450)
|
||||
{
|
||||
@ -172,7 +164,7 @@ class rdc_store extends hook
|
||||
}elseif ($rafale != 0)
|
||||
{
|
||||
//calcul du maxlevel par rapport a la vitesse des rafales
|
||||
$r = round(($rafale-20)/5, 0, PHP_ROUND_HALF_UP)*10;
|
||||
$r = round(($rafale-30)/4, 0, PHP_ROUND_HALF_UP)*10;
|
||||
if ($r < 0) $r = 0;
|
||||
if ($motorReversal)
|
||||
{
|
||||
@ -200,6 +192,17 @@ class rdc_store extends hook
|
||||
if ($this->storeLevel > $this->maxLevel)
|
||||
{
|
||||
$this->set($this->maxLevel);
|
||||
}elseif ($store2level !== false) //$store2level = false then no change on store position
|
||||
{
|
||||
if ( $store2level > $this->maxLevel )
|
||||
{
|
||||
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($this->maxLevel);
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($store2level);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
|
251
hooks/scripts/rdc_store.php~
Normal file
251
hooks/scripts/rdc_store.php~
Normal file
@ -0,0 +1,251 @@
|
||||
<?php
|
||||
|
||||
class rdc_store extends hook
|
||||
{
|
||||
public $hookName = "rdc_store";
|
||||
public $active = true; //enable/disable hook (true => enabled)
|
||||
public $timer = 0;
|
||||
public $luminance_min = 60;
|
||||
public $luminance_max = 3000;
|
||||
public $storeDownTime = 38;
|
||||
public $storeUpTime = 41;
|
||||
public $maxLevel;
|
||||
public $storeLevel;
|
||||
protected $propertyInitialized =array();
|
||||
protected $devicelist = array(
|
||||
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
|
||||
RDC_SALON_LUMINOSITE => "illuminance_lux",
|
||||
METEO => "rainin",
|
||||
METEO => "solarradiation",
|
||||
METEO => "windspeedkmh",
|
||||
METEO => "windgustkmh"
|
||||
);
|
||||
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
// $device -> calling device
|
||||
// $property -> property of the device (given by mqtt)
|
||||
// $value -> value of the property
|
||||
public function callBack($device, $property, $value)
|
||||
{
|
||||
global $mohaDB, $devices, $indexDevices;
|
||||
|
||||
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;
|
||||
$r = 100;
|
||||
$moving = "STOP";
|
||||
$motorReversal = false;
|
||||
$store2level = false;
|
||||
|
||||
if (array_key_exists("moving", $storeDevice->properties))
|
||||
{
|
||||
$moving = $storeDevice->properties["moving"]["value"];
|
||||
logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("motor_reversal", $storeDevice->properties))
|
||||
{
|
||||
if ($storeDevice->properties["motor_reversal"]["value"] == "ON")
|
||||
{
|
||||
$motorReversal = true;
|
||||
}else
|
||||
{
|
||||
$motorReversal = false;
|
||||
}
|
||||
logger(DEBUG, "Motor reversal =" . bool2string($motorReversal), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
|
||||
if ($moving == "STOP")
|
||||
{
|
||||
if (array_key_exists("position", $storeDevice->properties))
|
||||
{
|
||||
if ($motorReversal)
|
||||
{
|
||||
$this->storeLevel = $storeDevice->properties["position"]["value"];
|
||||
}else
|
||||
{
|
||||
$this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
|
||||
}
|
||||
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
|
||||
}else
|
||||
{
|
||||
$this->storeLevel = 0;
|
||||
//return true;
|
||||
}
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
|
||||
{
|
||||
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
|
||||
$exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5);
|
||||
if ($exterieurLuxMoyen == 0)
|
||||
{
|
||||
$exterieurLuxMoyen = $exterieur_lux;
|
||||
}
|
||||
logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
|
||||
{
|
||||
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
|
||||
if ($salon_lux == 0)
|
||||
{
|
||||
$salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"];
|
||||
}
|
||||
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;
|
||||
}
|
||||
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 450)
|
||||
{
|
||||
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 1000", __FILE__ . ":" . __LINE__);
|
||||
$this->close("Luminosité faible");
|
||||
}
|
||||
if (array_key_exists(METEO, $indexDevices))
|
||||
{
|
||||
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"];
|
||||
$rain = $rainTmp - $rainS;
|
||||
$rainS = $rainTmp;
|
||||
logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
|
||||
{
|
||||
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
|
||||
{
|
||||
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$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("windspeedkmh", $indexDevices[METEO]->properties))
|
||||
{
|
||||
if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50)
|
||||
{
|
||||
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6);
|
||||
if ($vent == 0)
|
||||
{
|
||||
$vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"];
|
||||
}
|
||||
logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if ($vent > $rafale)
|
||||
{
|
||||
$rafale = $vent;
|
||||
}
|
||||
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
||||
logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
if ($rafale >= 70 or $rain != 0)
|
||||
{
|
||||
$this->maxLevel = 0;
|
||||
logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
|
||||
$this->close("vent trop fort ou pluie");
|
||||
return 0;
|
||||
}elseif ($rafale != 0)
|
||||
{
|
||||
//calcul du maxlevel par rapport a la vitesse des rafales
|
||||
$r = round(($rafale-30)/4, 0, PHP_ROUND_HALF_UP)*10;
|
||||
if ($r < 0) $r = 0;
|
||||
if ($motorReversal)
|
||||
{
|
||||
$this->maxLevel = $r;
|
||||
}else
|
||||
{
|
||||
$this->maxLevel = 100 - $r;
|
||||
}
|
||||
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
|
||||
|
||||
switch ($property)
|
||||
{
|
||||
case "rainin":
|
||||
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
|
||||
$this->close("Pluie");
|
||||
break;
|
||||
case "windgustkmh";
|
||||
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
|
||||
if ($this->storeLevel > $this->maxLevel)
|
||||
{
|
||||
$this->set($this->maxLevel);
|
||||
}elseif ($store2level !== false)
|
||||
{
|
||||
if ( $store2level > $this->maxLevel )
|
||||
{
|
||||
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($this->maxLevel);
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($store2level);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function set ($level)
|
||||
{
|
||||
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
|
||||
if ($level <= 100)
|
||||
{
|
||||
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
|
||||
$this->send(100 - $level);
|
||||
}//else
|
||||
/*{
|
||||
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
private function close ($reason)
|
||||
{
|
||||
if ($this->storeLevel > 0)
|
||||
{
|
||||
logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__);
|
||||
$this->send(100);
|
||||
}
|
||||
}
|
||||
|
||||
private function send($level)
|
||||
{
|
||||
global $indexDevices;
|
||||
$deviceObject = $indexDevices[RDC_STORE];
|
||||
$msg = array("position" => $level);
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
$deviceObject->payload = $msg;
|
||||
$deviceObject->set(AUTO);
|
||||
}
|
||||
}
|
||||
|
||||
$hooks["rdc_store"] = new rdc_store();
|
||||
|
||||
?>
|
||||
print_r($function[0], true)
|
@ -3,14 +3,15 @@
|
||||
class rdc_wc_eclairage extends hook
|
||||
{
|
||||
public $hookName = "rdc_wc_eclairage";
|
||||
public $active = true; //enable/disable hook (true => enabled)
|
||||
|
||||
protected $devicelist = array(
|
||||
RDC_SDB_WC_ECLAIRAGE => "state_l2",
|
||||
RDC_WC_MVMT => "occupancy"
|
||||
);
|
||||
|
||||
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 = 10; // amount of time in $timeunit for manual mode
|
||||
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
||||
|
||||
// callback fonction. Is called with these 4 parameters
|
||||
@ -26,7 +27,7 @@ class rdc_wc_eclairage extends hook
|
||||
logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
|
||||
if ($value == "ON")
|
||||
{
|
||||
if ($targetDevice->properties["state_l2"]["method"] !== AUTO)
|
||||
if ($targetDevice->properties["state_l2"]["method"] == IDLE)
|
||||
{
|
||||
$targetDevice->properties["state_l2"]["method"] = MANUAL;
|
||||
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
|
||||
@ -39,12 +40,11 @@ class rdc_wc_eclairage extends hook
|
||||
break;
|
||||
case "occupancy":
|
||||
logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
|
||||
if ($value == true and $targetDevice->properties["state_l2"]["method"] == IDLE)
|
||||
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 ($value == false and $targetDevice->properties["state_l2"]["method"] != MANUAL)
|
||||
}elseif ($value === false and $targetDevice->properties["state_l2"]["method"] == AUTO)
|
||||
{
|
||||
//$targetDevice->properties["state_l2"]["method"] = IDLE;
|
||||
//$this->send($targetDevice, "OFF");
|
||||
|
68
hooks/scripts/rdc_wc_eclairage.php~
Normal file
68
hooks/scripts/rdc_wc_eclairage.php~
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
class rdc_wc_eclairage extends hook
|
||||
{
|
||||
public $hookName = "rdc_wc_eclairage";
|
||||
public $active = true; //enable/disable hook (true => enabled)
|
||||
|
||||
protected $devicelist = array(
|
||||
RDC_SDB_WC_ECLAIRAGE => "state_l2",
|
||||
RDC_WC_MVMT => "occupancy"
|
||||
);
|
||||
|
||||
public $delay = 1; // amount of time in $timeunit
|
||||
public $delayManual = 10; // amount of time in $timeunit for manual mode
|
||||
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
||||
|
||||
// callback fonction. Is called with these 4 parameters
|
||||
public function callBack(&$device, $property, $value)
|
||||
{
|
||||
global $indexDevices;
|
||||
|
||||
$targetDevice = &$indexDevices[RDC_SDB_WC_ECLAIRAGE]; //var_dump($value);
|
||||
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
|
||||
switch($property)
|
||||
{
|
||||
case "state_l2":
|
||||
logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
|
||||
if ($value == "ON")
|
||||
{
|
||||
if ($targetDevice->properties["state_l2"]["method"] == IDLE)
|
||||
{
|
||||
$targetDevice->properties["state_l2"]["method"] = MANUAL;
|
||||
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
|
||||
}
|
||||
}elseif ($value == "OFF")
|
||||
{
|
||||
$targetDevice->properties["state_l2"]["method"] = IDLE;
|
||||
removeEvent($device, "state_l2", "OFF");
|
||||
}
|
||||
break;
|
||||
case "occupancy":
|
||||
logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
|
||||
if ($value === true and $targetDevice->properties["state_l2"]["method"] == IDLE)
|
||||
{
|
||||
$targetDevice->properties["state_l2"]["method"] = AUTO;
|
||||
$this->send($targetDevice, "ON");
|
||||
}elseif ($value === false and $targetDevice->properties["state_l2"]["method"] != MANUAL)
|
||||
{
|
||||
//$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__);
|
||||
}
|
||||
private function send($targetDevice, $state)
|
||||
{
|
||||
global $indexDevices;
|
||||
|
||||
$msg = array("state_l2" => $state);
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $targetDevice->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
$targetDevice->payload = $msg;
|
||||
$targetDevice->set(null);
|
||||
}
|
||||
}
|
||||
|
||||
$hooks["rdc_wc_eclairage"] = new rdc_wc_eclairage();
|
||||
?>
|
Loading…
Reference in New Issue
Block a user