- lots of debugging
- beginning to add graphical stats - beginning to add device by type - added a dashboard "etage" - begining to add notification to multiple recipients in freemobile hook
This commit is contained in:
@ -1,17 +1,20 @@
|
||||
<?php
|
||||
class notificationFreemobile
|
||||
{
|
||||
private $url = "https://smsapi.free-mobile.fr/sendmsg?user=32886706&pass=JTGUY6l5OG73zX&msg=";
|
||||
private $url = "https://smsapi.free-mobile.fr/sendmsg?user=";
|
||||
private $name = "freemobile";
|
||||
public $active = true;
|
||||
public $level;
|
||||
private $dest = array(
|
||||
"32886706&pass=JTGUY6l5OG73zX", //daniel
|
||||
);
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->level = ALERT | ERROR;
|
||||
}
|
||||
|
||||
function send($message)
|
||||
function send($message, $destinataire=0)
|
||||
{
|
||||
global $curlErr;
|
||||
$result = false;
|
||||
@ -19,25 +22,22 @@ class notificationFreemobile
|
||||
{
|
||||
$ch = curl_init();
|
||||
// set url
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url . urlencode(trim($message)));
|
||||
curl_setopt($ch, CURLOPT_URL, $this->url . $dest["destinataire"] . "&msg=" . urlencode(trim($message)));
|
||||
echo $this->url . urlencode(trim($message)) . EOL;
|
||||
//return the transfer as a string
|
||||
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
// $result contains the output string
|
||||
//echo "1 curlErr =>"; var_dump($curlErr); echo EOL;
|
||||
if ($curlErr <= 10)
|
||||
{
|
||||
$result = curl_exec($ch);
|
||||
//echo "1 result => "; var_dump($result);echo EOL;
|
||||
if ($result === false)
|
||||
{
|
||||
$curlErr += 1;
|
||||
logger(ERROR, sprintf( _("Curl return error %d: %s when sending notification"), curl_errno($ch), curl_error($ch)), false, __FILE__ . ":" . __LINE__);
|
||||
}/*else
|
||||
}else
|
||||
{
|
||||
logger(INFO, sprintf(_("Curl return: %s when sending notification"), $result), false);
|
||||
}*/
|
||||
logger(DEBUG, sprintf(_("Curl return: %s when sending notification"), $result), false);
|
||||
}
|
||||
} //TODO managing curl errors
|
||||
// close curl resource to free up system resources
|
||||
curl_close($ch);
|
||||
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
class etage_plan_travail_eclairage extends hook
|
||||
{
|
||||
public $hookName = "etage_plan_travail_eclairage";
|
||||
public $active = false; //enable/disable hook (true => enabled)
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $timeUnit = "hour"; // unit of time for delay, second, minute, hour, day, week, month, year
|
||||
protected $devicelist = array(ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE => "state");
|
||||
|
||||
// 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)
|
||||
{
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
// here your code
|
||||
if($value == "ON") // ON
|
||||
{
|
||||
$this->send("ON", "OFF");
|
||||
}elseif($value == "OFF")
|
||||
{
|
||||
$this->send("OFF", null, AUTO);
|
||||
}
|
||||
logger (INFO,sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value));
|
||||
}
|
||||
|
||||
private function send($state, $delayState = false, $method = MANUAL)
|
||||
{
|
||||
global $devices, $indexDevices;
|
||||
$device = & $indexDevices[ETAGE_CUISINE_PLAN_TRAVAIL_SPOT];
|
||||
$msg = array("state_l1" => $state);
|
||||
if ($device->state_l1["value"] != $state)
|
||||
{
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName));
|
||||
$device->payload = $msg;
|
||||
$device->set();
|
||||
$device->method = $method;
|
||||
}else
|
||||
{
|
||||
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $device->friendlyName));
|
||||
}
|
||||
//echo 'delaystate = ' . var_dump($delayState);
|
||||
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true);
|
||||
}
|
||||
}
|
||||
|
||||
$hooks["etage_plan_travail_eclairage"] = new etage_plan_travail_eclairage();
|
||||
?>
|
@ -11,33 +11,31 @@ class radiateurs extends hook
|
||||
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
|
||||
// list of devices we are listening to
|
||||
|
||||
// devicelist[$ieeAddress][0] => property to watch
|
||||
// devicelist[$ieeAddress][1] => initialized = true
|
||||
// list of devices we are listening to: ieeeAddress => property to watch
|
||||
protected $devicelist = array(
|
||||
RDC_CHAMBRE_BAIE => "contact",
|
||||
RDC_SALON_BAIE => "contact",
|
||||
RDC_ENTREE_PORTE => "contact",
|
||||
ETAGE_ENTREE_PORTE => "contact",
|
||||
// RDC_SALON_BAIE => "contact",
|
||||
// RDC_ENTREE_PORTE => "contact",
|
||||
ETAGE_PORTE_ENTREE => "contact",
|
||||
ETAGE_CUISINE_FENETRE => "contact",
|
||||
ETAGE_SALON_FENETRE => "contact",
|
||||
ETAGE_SALON_PORTE_FENETRE => "contact",
|
||||
ETAGE_CHAMBRE_FENETRE => "contact",
|
||||
ETAGE_BUREAU_FENETRE => "contact"
|
||||
ETAGE_PORTE_FENETRE => "contact",
|
||||
// ETAGE_CHAMBRE_FENETRE => "contact",
|
||||
// ETAGE_BUREAU_FENETRE => "contact"
|
||||
);
|
||||
|
||||
PROTECTED $hvac = array(
|
||||
protected $hvac = array(
|
||||
RDC_CHAMBRE_BAIE => RDC_CHAMBRE_RADIATEUR,
|
||||
RDC_SALON_BAIE => RDC_SALON_RADIATEUR,
|
||||
RDC_ENTREE_PORTE => RDC_SALON_RADIATEUR,
|
||||
RDC_GARAGE_PORTE => RDC_SDB_RADIATEUR,
|
||||
ETAGE_ENTREE_PORTE => ETAGE_SALON_RADIATEUR,
|
||||
GARAGE_PORTE => RDC_SDB_RADIATEUR,
|
||||
ETAGE_PORTE_ENTREE => ETAGE_SALON_RADIATEUR,
|
||||
ETAGE_CUISINE_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||
ETAGE_SALON_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||
ETAGE_SALON_PORTE_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||
ETAGE_PORTE_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||
// ETAGE_CHAMBRE_FENETRE => ETAGE_CHAMBRE_RADIATEUR,
|
||||
ETAGE_BUREAU_FENETRE => ETAGE_BUREAU_RADIATEUR,
|
||||
// ETAGE_BUREAU_FENETRE => ETAGE_BUREAU_RADIATEUR,
|
||||
// ETAGE_SDB_FENETRE => ETAGE_SDB_RADIATEUR
|
||||
);
|
||||
|
||||
@ -55,38 +53,42 @@ class radiateurs extends hook
|
||||
public function callBack(&$device, $property, $value)
|
||||
{
|
||||
global $indexDevices;
|
||||
$now = date("MM");
|
||||
if ($now <= 5 or $now >= 11)
|
||||
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
|
||||
if ($this->active === true)
|
||||
{
|
||||
if ($value === false)
|
||||
$now = date("MM");
|
||||
if ($now <= 5 or $now >= 11)
|
||||
{
|
||||
send($indexDevices[$hvac[$device->ieeeAddress]], true);
|
||||
/* switch ($device->$ieeeAdress)
|
||||
if ($value === false)
|
||||
{
|
||||
send($indexDevices[$hvac[$device->ieeeAddress]], false);
|
||||
case RDC_CHAMBRE_BAIE:
|
||||
break;
|
||||
case RDC_SALON_BAIE:
|
||||
case RDC_ENTREE_PORTE:
|
||||
break;
|
||||
case RDC_GARAGE_PORTE:
|
||||
break;
|
||||
case ETAGE_CUISINE_FENETRE:
|
||||
case ETAGE_SALON_FENETRE:
|
||||
case ETAGE_SALON_PORTE_FENETRE:
|
||||
case ETAGE_ENTREE_PORTE:
|
||||
$this->send($indexDevices[$this->hvac[$device->ieeeAddress]], true);
|
||||
/* switch ($device->$ieeeAddress)
|
||||
{
|
||||
send($indexDevices[$hvac[$device->ieeeAddress]], false);
|
||||
case RDC_CHAMBRE_BAIE:
|
||||
break;
|
||||
case RDC_SALON_BAIE:
|
||||
case RDC_ENTREE_PORTE:
|
||||
break;
|
||||
case RDC_GARAGE_PORTE:
|
||||
break;
|
||||
case ETAGE_CUISINE_FENETRE:
|
||||
case ETAGE_SALON_FENETRE:
|
||||
case ETAGE_SALON_PORTE_FENETRE:
|
||||
case ETAGE_ENTREE_PORTE:
|
||||
|
||||
break;
|
||||
case ETAGE_CHAMBRE_FENETRE:
|
||||
break;
|
||||
case ETAGE_CHAMBRE_FENETRE:
|
||||
|
||||
break;
|
||||
case ETAGE_BUREAU_FENETRE:
|
||||
break;
|
||||
case ETAGE_BUREAU_FENETRE:
|
||||
|
||||
break;
|
||||
}*/
|
||||
}else
|
||||
{
|
||||
send($indexDevices[$hvac[$device->ieeeAddress]], false);
|
||||
break;
|
||||
}*/
|
||||
}else
|
||||
{
|
||||
$this->send($indexDevices[$this->hvac[$device->ieeeAddress]], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,31 +96,33 @@ class radiateurs extends hook
|
||||
function send($device, $state)
|
||||
{
|
||||
global $indexDevices;
|
||||
$flag = false;
|
||||
if ($state === false)
|
||||
{
|
||||
$t = getValue($device, "current_heating_setpoint");
|
||||
if ($t != $minTemp)
|
||||
$t = getValue($device->ieeeAddress, "current_heating_setpoint");
|
||||
if ($t != $this->minTemp)
|
||||
{
|
||||
$prevTemp[$device] = getValue($device, "current_heating_setpoint");
|
||||
$this->prevTemp[$device->ieeeAddress] = getValue($device->ieeeAddress, "current_heating_setpoint");
|
||||
}
|
||||
}else
|
||||
{
|
||||
$r = array_keys($hvac, $device->ieeeAddress);
|
||||
$r = array_keys($this->hvac, $device->ieeeAddress);
|
||||
foreach($r as $value)
|
||||
{
|
||||
if (getValue($indexDevices[$value], "contact") === true)
|
||||
logger(DEBUG, "Device to test for contact " . $value, __FILE__ . ":" . __LINE__);
|
||||
if (getValue($device->ieeeAddress, "contact") === true)
|
||||
{
|
||||
$flag = true;
|
||||
$flag &= true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($flag === false)
|
||||
{
|
||||
$msg = array("current_heating_setpoint" => (!empty($prevTemp[$device])?$prevTemp[$device]:19));
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
$deviceTarget->payload = $msg;
|
||||
$deviceTarget->set();
|
||||
$deviceTarget->method = AUTO;
|
||||
$msg = array("current_heating_setpoint" => (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19));
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
$device->payload = $msg;
|
||||
$device->set();
|
||||
$device->method = AUTO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ class rdc_chambre_eclairage extends hook
|
||||
public function callBack($device, $property, $value)
|
||||
{
|
||||
global $devices, $indexDevices;
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
|
||||
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
|
||||
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
|
||||
@ -32,12 +33,12 @@ class rdc_chambre_eclairage extends hook
|
||||
$this->send($targetAmbiance, "state", "ON", "OFF", AUTO);
|
||||
}elseif ($property == "contact")
|
||||
{
|
||||
if ($value == false and getValue(RDC_CHAMBRE_ECLAIRAGE, "state_l1") == "OFF")
|
||||
if ($value == false)
|
||||
{
|
||||
$this->send($targetEclairage, "state_l1", "ON", "OFF", AUTO);
|
||||
}elseif ($value == true and getValue(RDC_CHAMBRE_ECLAIRAGE, "state_l1") == "ON")
|
||||
}elseif ($value == true)
|
||||
{
|
||||
$this->send($targetEclairage, "state_l1", "OFF", null, null);
|
||||
$this->send($targetEclairage, "state_l1", "OFF", false, null);
|
||||
}
|
||||
}
|
||||
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
|
||||
@ -47,17 +48,17 @@ class rdc_chambre_eclairage extends hook
|
||||
{
|
||||
global $indexDevices;
|
||||
$msg = array($property => $state);
|
||||
if ($deviceObject->properties[$property]["value"] != $state)
|
||||
{
|
||||
//if ($deviceObject->properties[$property]["value"] != $state)
|
||||
//{
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
$deviceObject->payload = $msg;
|
||||
$deviceObject->set();
|
||||
$deviceObject->method = $method;
|
||||
}else
|
||||
{
|
||||
///}else
|
||||
/*{
|
||||
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
|
||||
}
|
||||
}*/
|
||||
//echo 'delaystate = ' . var_dump($delayState);
|
||||
if ($delayState !== false) setDelay($deviceObject, $this->delay, $this->timeUnit, "state", $delayState, true);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class alerte_intrusion extends hook
|
||||
// callback fonction. Is called with these 4 parameters
|
||||
public function callBack($device, $property, $value)
|
||||
{
|
||||
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
switch($property)
|
||||
{
|
||||
case "contact":
|
||||
|
@ -21,7 +21,7 @@ class rdc_salon_eclairage extends hook
|
||||
public function callBack($device, $param, $value)
|
||||
{
|
||||
global $indexDevices;
|
||||
logger(INFO, _("hook : rdc_salon_eclairage"), __FILE__ . ":" . __LINE__);
|
||||
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
|
||||
$deviceTarget = &$indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU];
|
||||
$lux = $indexDevices[RDC_SALON_LUMINOSITE];
|
||||
$mvmt = $indexDevices[RDC_SALON_MVMT];
|
||||
@ -40,7 +40,7 @@ class rdc_salon_eclairage extends hook
|
||||
if ($illuminance <= $this->luminance_min)
|
||||
{
|
||||
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
|
||||
$this->send($deviceTarget, "ON", null, AUTO);
|
||||
$this->send($deviceTarget, "ON", false, AUTO);
|
||||
removeEvent($deviceTarget, "state", "OFF");
|
||||
}
|
||||
}else
|
||||
@ -61,7 +61,7 @@ class rdc_salon_eclairage extends hook
|
||||
logger(INFO, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__);
|
||||
if (getValue(RDC_SALON_MVMT, "occupancy") == ON or getValue(RDC_SALON_MVMT2, "occupancy") == ON)
|
||||
{
|
||||
$this->send($deviceTarget, "ON", null, AUTO);
|
||||
$this->send($deviceTarget, "ON", false, AUTO);
|
||||
}else
|
||||
{
|
||||
$this->send($deviceTarget, "ON", "OFF", AUTO);
|
||||
@ -82,7 +82,7 @@ class rdc_salon_eclairage extends hook
|
||||
}elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON || getValue(RDC_SALON_MVMT2,"occupancy") == ON))
|
||||
{
|
||||
logger(INFO, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__);
|
||||
$this->send($deviceTarget, "ON", null, AUTO);
|
||||
$this->send($deviceTarget, "ON", false, AUTO);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -94,16 +94,16 @@ class rdc_salon_eclairage extends hook
|
||||
global $indexDevices;
|
||||
|
||||
$msg = array("state" => $state);
|
||||
if ($deviceTarget->properties["state"]["value"] != $state)
|
||||
{
|
||||
//if ($deviceTarget->properties["state"]["value"] != $state)
|
||||
//{
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
$deviceTarget->payload = $msg;
|
||||
$deviceTarget->set();
|
||||
$deviceTarget->method = $method;
|
||||
}else
|
||||
/*}else
|
||||
{
|
||||
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}*/
|
||||
//echo 'delaystate = ' . var_dump($delayState);
|
||||
if ($delayState !== false) setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", $delayState, true);
|
||||
}
|
||||
|
@ -29,18 +29,14 @@ class rdc_sdb_eclairage extends hook
|
||||
global $indexDevices;
|
||||
//var_dump($value);
|
||||
$deviceTarget = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
|
||||
switch($property)
|
||||
{
|
||||
case "occupancy":
|
||||
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
||||
if ($value == ON)
|
||||
if ($value == ON )
|
||||
{
|
||||
if (getValue($deviceTarget->ieeeAddress, "state_l1") != "ON")
|
||||
{
|
||||
$this->send("ON");
|
||||
}
|
||||
//setDelay($indexDevices[RDC_SDB_WC_ECLAIRAGE], $this->delay, $this->timeUnit, "state_l1", "OFF", true);
|
||||
$this->send("ON");
|
||||
$device->method = AUTO;
|
||||
}
|
||||
break;
|
||||
@ -48,11 +44,20 @@ class rdc_sdb_eclairage extends hook
|
||||
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
|
||||
if ($value == "ON")
|
||||
{
|
||||
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state_l1", "OFF", true);
|
||||
$device->method = MANUAL;
|
||||
}elseif ($value = "OFF")
|
||||
if ($device->method != MANUAL)
|
||||
{
|
||||
$delay = $this->delay;
|
||||
$device->method = AUTO;
|
||||
}else
|
||||
{
|
||||
$delay = $this->delayManual;
|
||||
$device->method = MANUAL;
|
||||
}
|
||||
setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true);
|
||||
}elseif ($value == "OFF")
|
||||
{
|
||||
removeEvent($deviceTarget, "state_l1", "OFF");
|
||||
$device->method = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -9,12 +9,13 @@ class rdc_store extends hook
|
||||
public $luminance_max = 3000;
|
||||
public $storeDownTime = 38;
|
||||
public $storeUpTime = 41;
|
||||
public $maxLevel;
|
||||
protected $storeLevel;
|
||||
protected $propertyInitialized =array();
|
||||
protected $devicelist = array(
|
||||
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", // "ON"/"OFF"
|
||||
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
|
||||
METEO => "rainin",
|
||||
//METEO => array("solarradiation", false),
|
||||
//METEO => "solarradiation",
|
||||
METEO => "windspeedkmh",
|
||||
METEO => "windgustkmh"
|
||||
);
|
||||
@ -30,62 +31,86 @@ class rdc_store extends hook
|
||||
logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__);
|
||||
$rain = 0;
|
||||
$exterieur_lux = 0;
|
||||
$salon_lux = 0;
|
||||
$rafale = 0;
|
||||
$soleil = 0;
|
||||
$storeDevice = $indexDevices[RDC_STORE];
|
||||
|
||||
if (array_key_exists("position", $storeDevice->properties))
|
||||
{
|
||||
$storeLevel = $storeDevice->properties["position"];
|
||||
$this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
|
||||
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
|
||||
}else
|
||||
{
|
||||
return true;
|
||||
$this->storeLevel = 0;
|
||||
//return true;
|
||||
}
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
|
||||
{
|
||||
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
|
||||
logger(DEBUG, "exterieur_lux=" . $exterieur_lux, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
|
||||
{
|
||||
$rain = $indexDevices[METEO]->properties["rainin"];
|
||||
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
|
||||
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
|
||||
if (array_key_exists(METEO, $indexDevices))
|
||||
{
|
||||
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
|
||||
}
|
||||
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
||||
}
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
if ($rafale >= 6 or $rain != 0)
|
||||
{
|
||||
$maxLevel = 0;
|
||||
}else
|
||||
{
|
||||
if ($rafale != 0)
|
||||
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$maxLevel = 100 / $rafale;
|
||||
$rain = $indexDevices[METEO]->properties["rainin"]["value"];
|
||||
logger(DEBUG, "rain=" . var_dump($rain), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
|
||||
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
|
||||
logger(DEBUG, "soleil=" . $exterieur_lux, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
if ($rafale >= 60 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)
|
||||
{
|
||||
$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__);
|
||||
}
|
||||
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
|
||||
//$store2level = $this->maxLevel;
|
||||
switch ($property)
|
||||
{
|
||||
case "illuminance_lux":
|
||||
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
|
||||
if ($exterieur_lux > 3000)
|
||||
if ($exterieur_lux > 40000)
|
||||
{
|
||||
if ($rain == 0 and $maxLevel != 0)
|
||||
logger(DEBUG, "exterieur_lux > 40000", __FILE__ . ":" . __LINE__);
|
||||
if ($this->maxLevel != 0 and $salon_lux > 150)
|
||||
{
|
||||
$store2level = storeLevel + 15;
|
||||
if ( $store2level > $maxLevel )
|
||||
$store2level = $this->storeLevel + 15;
|
||||
if ( $store2level > $this->maxLevel )
|
||||
{
|
||||
$this->open($maxLevel);
|
||||
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($this->maxLevel);
|
||||
}else
|
||||
{
|
||||
$this->open($max2level);
|
||||
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
|
||||
$this->set($store2level);
|
||||
}
|
||||
}
|
||||
}elseif ($exterieur_lux < 25000)
|
||||
}elseif ($exterieur_lux < 35000)
|
||||
{
|
||||
logger(DEBUG, "exterieur_lux < 35000", __FILE__ . ":" . __LINE__);
|
||||
$this->close("Luminosité faible");
|
||||
}
|
||||
break;
|
||||
@ -94,40 +119,25 @@ class rdc_store extends hook
|
||||
$this->close("Pluie");
|
||||
break;
|
||||
case "windgustkmh";
|
||||
logger(DEBUG, "CASE: windgustkmh:" . $value, __FILE__ . ":" . __LINE__);
|
||||
case "windspeedkmh":
|
||||
logger(DEBUG, "CASE: windspeedkmh:" . $value, __FILE__ . ":" . __LINE__);
|
||||
if($value > 50)
|
||||
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)
|
||||
{
|
||||
$this->close("Trop de vent");
|
||||
}elseif ($value > 40 and $this->storeLevel > 20)
|
||||
{
|
||||
$this->maxLevel = 20;
|
||||
$this->send(20);
|
||||
}elseif ($value > 30 and $this->storeLevel > 40)
|
||||
{
|
||||
$this->maxLevel = 40;
|
||||
$this->send(40);
|
||||
}elseif ($value >20 and $this->storeLevel > 60)
|
||||
{
|
||||
$this->maxLevel = 60;
|
||||
$this->send(60);
|
||||
}elseif ($value >10 and $this->storeLevel > 80)
|
||||
{
|
||||
$this->maxLevel = 80;
|
||||
$this->send(80);
|
||||
}else
|
||||
{
|
||||
$this->maxLevel = 100;
|
||||
$this->set($this->maxLevel);
|
||||
}
|
||||
$this->close("Fortes rafales de vent");
|
||||
break;
|
||||
default:
|
||||
|
||||
}
|
||||
if ($store2level <= $this->storeLevel)
|
||||
{
|
||||
$this->set($store2level);
|
||||
}
|
||||
}
|
||||
|
||||
private function open ($level)
|
||||
private function set ($level)
|
||||
{
|
||||
if ($this->storeLevel < $level)
|
||||
{
|
||||
@ -140,8 +150,7 @@ class rdc_store extends hook
|
||||
{
|
||||
if ($this->storeLevel != 0)
|
||||
{
|
||||
logger(DEBUG, "Close store :" . $level, __FILE__ . ":" . __LINE__);
|
||||
print ( "store fermé " . $reason);
|
||||
logger(DEBUG, "Close store :" . $reason, __FILE__ . ":" . __LINE__);
|
||||
$this->send(100);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class rdc_wc_eclairage extends hook
|
||||
);
|
||||
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $delayManual = 8; // 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
|
||||
|
||||
// callback fonction. Is called with these 4 parameters
|
||||
@ -18,23 +18,32 @@ class rdc_wc_eclairage extends hook
|
||||
{
|
||||
global $indexDevices;
|
||||
//var_dump($value);
|
||||
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
|
||||
switch($property)
|
||||
{
|
||||
case "state_l2":
|
||||
logger(DEBUG, _("CASE: state_l2"), __FILE__ . ":" . __LINE__);
|
||||
logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
|
||||
if ($value == "ON")
|
||||
{
|
||||
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
|
||||
$device->method = MANUAL;
|
||||
if ($device->method == AUTO)
|
||||
{
|
||||
setDelay($device, $this->delay, $this->timeUnit, "state_l2", "OFF", true);
|
||||
}else
|
||||
{
|
||||
$device->method = MANUAL;
|
||||
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
|
||||
}
|
||||
}elseif ($value == "OFF")
|
||||
{
|
||||
deleteEvent(searchEvent($device, "state_l2", "OFF"));
|
||||
removeEvent($device, "state_l2", "OFF");
|
||||
$device->method = null;
|
||||
}
|
||||
break;
|
||||
case "occupancy":
|
||||
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
||||
logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
|
||||
if ($value == true)
|
||||
{
|
||||
$device->method = AUTO;
|
||||
$this->send("ON");
|
||||
}
|
||||
}
|
||||
@ -48,11 +57,6 @@ class rdc_wc_eclairage extends hook
|
||||
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
$deviceObject->payload = $msg;
|
||||
$deviceObject->set(null);
|
||||
if ($deviceObject->method != MANUAL)
|
||||
{
|
||||
$deviceObject->method = AUTO;
|
||||
}
|
||||
setDelay($deviceObject, $this->delay, $this->timeUnit, "state_l2", "OFF", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user