2022-03-04 23:32:39 +01:00
|
|
|
<?php
|
|
|
|
|
2022-03-06 01:30:33 +01:00
|
|
|
class rdc_store extends hook
|
2022-03-04 23:32:39 +01:00
|
|
|
{
|
|
|
|
public $hookName = "rdc_store";
|
|
|
|
public $active = true; //enable/disable hook (true => enabled)
|
|
|
|
public $timer = 0;
|
|
|
|
public $luminance_min = 60;
|
|
|
|
public $luminance_max = 3000;
|
2022-03-13 22:33:26 +01:00
|
|
|
public $storeDownTime = 38;
|
|
|
|
public $storeUpTime = 41;
|
2022-03-28 00:40:34 +02:00
|
|
|
public $maxLevel;
|
2022-03-06 01:30:33 +01:00
|
|
|
protected $storeLevel;
|
2022-03-13 22:33:26 +01:00
|
|
|
protected $propertyInitialized =array();
|
2022-03-04 23:32:39 +01:00
|
|
|
protected $devicelist = array(
|
2022-03-28 00:40:34 +02:00
|
|
|
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
|
2022-04-23 02:00:52 +02:00
|
|
|
RDC_SALON_LUMINOSITE => "illuminance_lux",
|
2022-03-13 22:33:26 +01:00
|
|
|
METEO => "rainin",
|
2022-04-23 02:00:52 +02:00
|
|
|
METEO => "solarradiation",
|
2022-03-13 22:33:26 +01:00
|
|
|
METEO => "windspeedkmh",
|
|
|
|
METEO => "windgustkmh"
|
2022-03-04 23:32:39 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2022-03-06 01:30:33 +01:00
|
|
|
global $mohaDB, $devices, $indexDevices;
|
2022-03-04 23:32:39 +01:00
|
|
|
|
2022-03-13 22:33:26 +01:00
|
|
|
logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__);
|
|
|
|
$rain = 0;
|
2022-05-05 21:28:26 +02:00
|
|
|
static $rainS;
|
2022-03-13 22:33:26 +01:00
|
|
|
$exterieur_lux = 0;
|
2022-03-28 00:40:34 +02:00
|
|
|
$salon_lux = 0;
|
2022-03-13 22:33:26 +01:00
|
|
|
$rafale = 0;
|
|
|
|
$soleil = 0;
|
2022-03-06 01:30:33 +01:00
|
|
|
$storeDevice = $indexDevices[RDC_STORE];
|
2022-04-23 02:00:52 +02:00
|
|
|
$this->maxLevel = 100;
|
2022-04-07 01:44:17 +02:00
|
|
|
$r = 100;
|
2022-03-28 00:40:34 +02:00
|
|
|
|
2022-03-13 22:33:26 +01:00
|
|
|
if (array_key_exists("position", $storeDevice->properties))
|
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
$this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
|
|
|
|
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
|
2022-03-13 22:33:26 +01:00
|
|
|
}else
|
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
$this->storeLevel = 0;
|
|
|
|
//return true;
|
2022-03-13 22:33:26 +01:00
|
|
|
}
|
|
|
|
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
|
|
|
|
{
|
|
|
|
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
|
2022-04-23 02:00:52 +02:00
|
|
|
if ($exterieur_lux == 0)
|
|
|
|
{
|
|
|
|
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
|
|
|
|
}
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "exterieur_lux=" . $exterieur_lux, __FILE__ . ":" . __LINE__);
|
2022-03-13 22:33:26 +01:00
|
|
|
}
|
2022-03-28 00:40:34 +02:00
|
|
|
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
|
2022-03-13 22:33:26 +01:00
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
|
2022-04-23 02:00:52 +02:00
|
|
|
if ($salon_lux == 0)
|
|
|
|
{
|
|
|
|
$salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"];
|
|
|
|
}
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
|
2022-03-13 22:33:26 +01:00
|
|
|
}
|
2022-03-28 00:40:34 +02:00
|
|
|
if (array_key_exists(METEO, $indexDevices))
|
2022-03-13 22:33:26 +01:00
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
|
|
|
|
{
|
2022-05-05 21:28:26 +02:00
|
|
|
$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"];
|
|
|
|
$rain = $rainTmp - $rainS;
|
|
|
|
$rainS = $rainTmp;
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "rain=" . var_dump($rain), __FILE__ . ":" . __LINE__);
|
|
|
|
}
|
|
|
|
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
|
|
|
|
{
|
2022-04-23 02:00:52 +02:00
|
|
|
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
|
|
|
|
{
|
|
|
|
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__);
|
|
|
|
}
|
|
|
|
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 7);
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
|
|
|
|
}
|
|
|
|
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
|
|
|
|
{
|
|
|
|
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
2022-04-23 02:00:52 +02:00
|
|
|
logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
|
2022-03-28 00:40:34 +02:00
|
|
|
}
|
2022-03-13 22:33:26 +01:00
|
|
|
}
|
|
|
|
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
2022-03-28 00:40:34 +02:00
|
|
|
if ($rafale >= 60 or $rain != 0)
|
2022-03-06 01:30:33 +01:00
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
$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)
|
2022-03-06 01:30:33 +01:00
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
$this->maxLevel = ($r = 100 - round(($rafale-10)/5, 0, PHP_ROUND_HALF_UP)*20)<0 ? 0 : $r;
|
|
|
|
//$this->maxLevel = 100 / $rafale;
|
|
|
|
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
|
2022-03-06 01:30:33 +01:00
|
|
|
}
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
|
|
|
|
//$store2level = $this->maxLevel;
|
2022-03-06 01:30:33 +01:00
|
|
|
switch ($property)
|
|
|
|
{
|
2022-05-05 21:28:26 +02:00
|
|
|
case "illuminance_lux":
|
2022-03-13 22:33:26 +01:00
|
|
|
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
|
2022-04-23 02:00:52 +02:00
|
|
|
if ($exterieur_lux > 30000)
|
2022-03-06 01:30:33 +01:00
|
|
|
{
|
2022-04-23 02:00:52 +02:00
|
|
|
logger(DEBUG, "exterieur_lux > 30000", __FILE__ . ":" . __LINE__);
|
|
|
|
if ($this->maxLevel != 0 and $salon_lux > 100)
|
2022-03-06 01:30:33 +01:00
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
$store2level = $this->storeLevel + 15;
|
|
|
|
if ( $store2level > $this->maxLevel )
|
2022-03-06 01:30:33 +01:00
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
|
|
|
|
$this->set($this->maxLevel);
|
2022-03-06 01:30:33 +01:00
|
|
|
}else
|
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
|
|
|
|
$this->set($store2level);
|
2022-03-06 01:30:33 +01:00
|
|
|
}
|
|
|
|
}
|
2022-05-05 21:28:26 +02:00
|
|
|
}elseif ($exterieur_lux < 15000 and $salon_lux < 110)
|
2022-03-06 01:30:33 +01:00
|
|
|
{
|
2022-04-23 02:00:52 +02:00
|
|
|
logger(DEBUG, "exterieur_lux < 15000", __FILE__ . ":" . __LINE__);
|
2022-03-06 01:30:33 +01:00
|
|
|
$this->close("Luminosité faible");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "rainin":
|
2022-03-13 22:33:26 +01:00
|
|
|
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
|
2022-03-06 01:30:33 +01:00
|
|
|
$this->close("Pluie");
|
|
|
|
break;
|
|
|
|
case "windgustkmh";
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
|
|
|
|
//case "windspeedkmh":
|
|
|
|
// logger(DEBUG, "CASE: windspeedkmh:" . $value, __FILE__ . ":" . __LINE__);
|
|
|
|
|
|
|
|
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
|
|
|
|
if ($this->storeLevel > $this->maxLevel)
|
2022-03-06 01:30:33 +01:00
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
$this->set($this->maxLevel);
|
2022-03-06 01:30:33 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-03-13 22:33:26 +01:00
|
|
|
default:
|
2022-03-28 00:40:34 +02:00
|
|
|
}
|
2022-04-07 01:44:17 +02:00
|
|
|
/*if ($store2level <= $this->storeLevel)
|
2022-03-28 00:40:34 +02:00
|
|
|
{
|
|
|
|
$this->set($store2level);
|
2022-04-07 01:44:17 +02:00
|
|
|
}*/
|
2022-03-06 01:30:33 +01:00
|
|
|
}
|
2022-03-04 23:32:39 +01:00
|
|
|
|
2022-03-28 00:40:34 +02:00
|
|
|
private function set ($level)
|
2022-03-06 01:30:33 +01:00
|
|
|
{
|
2022-04-23 02:00:52 +02:00
|
|
|
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
|
|
|
|
//if ($this->storeLevel < $level)
|
|
|
|
//{
|
2022-03-13 22:33:26 +01:00
|
|
|
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
|
|
|
|
$this->send(100 - $level);
|
2022-04-23 02:00:52 +02:00
|
|
|
//}else
|
|
|
|
/*{
|
|
|
|
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);
|
|
|
|
}*/
|
|
|
|
|
2022-03-06 01:30:33 +01:00
|
|
|
}
|
2022-03-04 23:32:39 +01:00
|
|
|
|
2022-03-06 01:30:33 +01:00
|
|
|
private function close ($reason)
|
|
|
|
{
|
|
|
|
if ($this->storeLevel != 0)
|
|
|
|
{
|
2022-03-28 00:40:34 +02:00
|
|
|
logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__);
|
2022-03-13 22:33:26 +01:00
|
|
|
$this->send(100);
|
2022-03-06 01:30:33 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-04 23:32:39 +01:00
|
|
|
|
2022-03-06 01:30:33 +01:00
|
|
|
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;
|
2022-03-13 22:33:26 +01:00
|
|
|
$deviceObject->set(AUTO);
|
2022-03-06 01:30:33 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-04 23:32:39 +01:00
|
|
|
|
2022-03-06 01:30:33 +01:00
|
|
|
$hooks["rdc_store"] = new rdc_store();
|
2022-03-04 23:32:39 +01:00
|
|
|
?>
|