127 lines
3.0 KiB
PHP
127 lines
3.0 KiB
PHP
<?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 = 20;
|
|
public $storeUpTime = 25;
|
|
protected $storeLevel;
|
|
|
|
protected $devicelist = array(
|
|
RDC_EXTERIEUR_LUMINOSITE => array("illuminance_lux", false), // "ON"/"OFF"
|
|
METEO => array("rainin", false),
|
|
//METEO => array("solarradiation", false),
|
|
METEO => array("windspeedkmh", false),
|
|
METEO => array("windgustkmh", false)
|
|
);
|
|
|
|
// 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;
|
|
|
|
$storeDevice = $indexDevices[RDC_STORE];
|
|
$storeLevel = $storeDevice->properties["position"];
|
|
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
|
|
$rain = $indexDevices[METEO]->properties["rainin"];
|
|
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
|
|
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
|
if ($rafale >= 6 or $rain != 0)
|
|
{
|
|
$maxLevel = 0;
|
|
}else
|
|
{
|
|
$maxLevel = 100 / $rafale;
|
|
}
|
|
switch ($property)
|
|
{
|
|
case "illuminance_lux":
|
|
if ($exterieur_lux > 3000)
|
|
{
|
|
if ($rain == 0 and $maxLevel != 0)
|
|
{
|
|
$store2level = storeLevel + 15;
|
|
if ( $store2level > $maxLevel )
|
|
{
|
|
$this->open($maxLevel);
|
|
}else
|
|
{
|
|
$this->open($max2level);
|
|
}
|
|
}
|
|
}elseif ($exterieur_lux < 25000)
|
|
{
|
|
$this->close("Luminosité faible");
|
|
}
|
|
break;
|
|
case "rainin":
|
|
$this->close("Pluie");
|
|
break;
|
|
case "windgustkmh";
|
|
case "windspeedkmh":
|
|
if($value > 50)
|
|
{
|
|
$this->close("Trop de vent");
|
|
}elseif ($value > 40 and $level > 20)
|
|
{
|
|
$this->maxLevel = 20;
|
|
$this->send(20);
|
|
}elseif ($value > 30 and $level > 40)
|
|
{
|
|
$this->maxLevel = 40;
|
|
$this->send(40);
|
|
}elseif ($value >20 and $level > 60)
|
|
{
|
|
$this->maxLevel = 60;
|
|
$this->send(60);
|
|
}elseif ($value >10 and $level > 80)
|
|
{
|
|
$this->maxLevel = 80;
|
|
$this->send(80);
|
|
}else
|
|
{
|
|
$this->maxLevel = 100;
|
|
}
|
|
$this->close("Fortes rafales de vent");
|
|
break;
|
|
}
|
|
}
|
|
|
|
private function open ($level)
|
|
{
|
|
if ($this->storeLevel < $level)
|
|
{
|
|
$this->send($level);
|
|
}
|
|
}
|
|
|
|
private function close ($reason)
|
|
{
|
|
if ($this->storeLevel != 0)
|
|
{
|
|
print ( "store fermé " . $reason);
|
|
}
|
|
}
|
|
|
|
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();
|
|
$deviceObject->method = AUTO;
|
|
}
|
|
}
|
|
|
|
$hooks["rdc_store"] = new rdc_store();
|
|
?>
|