a lot of bugs corrected\nrdc_wc_eclairage
This commit is contained in:
@ -15,7 +15,7 @@ class availability
|
||||
private function iterate()
|
||||
{
|
||||
global $indexDevices;
|
||||
foreach ($indexDevices as $value)
|
||||
foreach ($indexDevices as &$value)
|
||||
{
|
||||
$value->properties["availability"]["functions"][] = array($this,"callback");
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ class etage_plan_travail_eclairage extends hook
|
||||
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 => array("state", false));
|
||||
protected $devicelist = array(ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE => "state");
|
||||
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
// $device -> calling device
|
||||
@ -14,6 +14,7 @@ class etage_plan_travail_eclairage extends hook
|
||||
// $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
|
||||
{
|
||||
|
128
hooks/scripts/radiateurs.php
Normal file
128
hooks/scripts/radiateurs.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
class radiateurs extends hook
|
||||
{
|
||||
public $hookName = "radiateurs";
|
||||
public $active = false;
|
||||
|
||||
/* already defined in hook class */
|
||||
// public $active = true;
|
||||
//public $initlialized = false;
|
||||
public $minTemp = 5;
|
||||
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
|
||||
protected $devicelist = array(
|
||||
RDC_CHAMBRE_BAIE => "contact",
|
||||
RDC_SALON_BAIE => "contact",
|
||||
RDC_ENTREE_PORTE => "contact",
|
||||
ETAGE_ENTREE_PORTE => "contact",
|
||||
ETAGE_CUISINE_FENETRE => "contact",
|
||||
ETAGE_SALON_FENETRE => "contact",
|
||||
ETAGE_SALON_PORTE_FENETRE => "contact",
|
||||
ETAGE_CHAMBRE_FENETRE => "contact",
|
||||
ETAGE_BUREAU_FENETRE => "contact"
|
||||
);
|
||||
|
||||
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,
|
||||
ETAGE_CUISINE_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||
ETAGE_SALON_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||
ETAGE_SALON_PORTE_FENETRE => ETAGE_SALON_RADIATEUR,
|
||||
// ETAGE_CHAMBRE_FENETRE => ETAGE_CHAMBRE_RADIATEUR,
|
||||
ETAGE_BUREAU_FENETRE => ETAGE_BUREAU_RADIATEUR,
|
||||
// ETAGE_SDB_FENETRE => ETAGE_SDB_RADIATEUR
|
||||
);
|
||||
|
||||
protected $prevTemp = array(
|
||||
RDC_CHAMBRE_RADIATEUR => 0,
|
||||
RDC_SALON_RADIATEUR => 0,
|
||||
RDC_SDB_RADIATEUR => 0,
|
||||
ETAGE_SALON_RADIATEUR => 0,
|
||||
ETAGE_BUREAU_RADIATEUR => 0
|
||||
// ETAGE_SDB_RADIATEUR => 0,
|
||||
// ETAGE_CHAMBRE_RADIATEUR => 0
|
||||
);
|
||||
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
public function callBack(&$device, $property, $value)
|
||||
{
|
||||
global $indexDevices;
|
||||
$now = date("MM");
|
||||
if ($now <= 5 or $now >= 11)
|
||||
{
|
||||
if ($value === false)
|
||||
{
|
||||
send($indexDevices[$hvac[$device->ieeeAddress]], true);
|
||||
/* switch ($device->$ieeeAdress)
|
||||
{
|
||||
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_BUREAU_FENETRE:
|
||||
|
||||
break;
|
||||
}*/
|
||||
}else
|
||||
{
|
||||
send($indexDevices[$hvac[$device->ieeeAddress]], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function send($device, $state)
|
||||
{
|
||||
global $indexDevices;
|
||||
if ($state === false)
|
||||
{
|
||||
$t = getValue($device, "current_heating_setpoint");
|
||||
if ($t != $minTemp)
|
||||
{
|
||||
$prevTemp[$device] = getValue($device, "current_heating_setpoint");
|
||||
}
|
||||
}else
|
||||
{
|
||||
$r = array_keys($hvac, $device->ieeeAddress);
|
||||
foreach($r as $value)
|
||||
{
|
||||
if (getValue($indexDevices[$value], "contact") === 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$hooks["radiateurs"] = new radiateurs();
|
||||
|
||||
?>
|
@ -9,10 +9,10 @@ class rdc_chambre_eclairage extends hook
|
||||
public $luminance_min = 60;
|
||||
public $luminance_max = 3000;
|
||||
protected $devicelist = array(
|
||||
RDC_CHAMBRE_AMBIANCE => array("state", false), // "ON"/"OFF"
|
||||
RDC_CHAMBRE_ECLAIRAGE => array("state_l1", false), // "ON"/"OFF"
|
||||
RDC_CHAMBRE_MVMT => array("occupancy", false),
|
||||
RDC_CHAMBRE_ARMOIRE_GAUCHE => array("contact", false)
|
||||
RDC_CHAMBRE_AMBIANCE => "state", // "ON"/"OFF"
|
||||
RDC_CHAMBRE_ECLAIRAGE => "state_l1", // "ON"/"OFF"
|
||||
RDC_CHAMBRE_MVMT => "occupancy",
|
||||
RDC_CHAMBRE_ARMOIRE_GAUCHE => "contact"
|
||||
);
|
||||
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
@ -25,9 +25,10 @@ class rdc_chambre_eclairage extends hook
|
||||
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
|
||||
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
|
||||
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
|
||||
|
||||
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
|
||||
if ($property == "occupancy" and $value == ON)
|
||||
{
|
||||
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
||||
$this->send($targetAmbiance, "state", "ON", "OFF", AUTO);
|
||||
}elseif ($property == "contact")
|
||||
{
|
||||
@ -42,7 +43,7 @@ class rdc_chambre_eclairage extends hook
|
||||
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($deviceObject, $property, $state, $delayState = false, $method = MANUAL)
|
||||
private function send(&$deviceObject, $property, $state, $delayState = false, $method = MANUAL)
|
||||
{
|
||||
global $indexDevices;
|
||||
$msg = array($property => $state);
|
||||
|
@ -5,26 +5,28 @@ class alerte_intrusion extends hook
|
||||
public $active = true;
|
||||
|
||||
protected $devicelist = array(
|
||||
ENTREE_PORTE => array("contact", false),
|
||||
GARAGE_PORTE => array("contact", false),
|
||||
RDC_CHAMBRE_BAIE => array("contact", false),
|
||||
RDC_SALON_BAIE => array("contact", false));
|
||||
ENTREE_PORTE => "contact",
|
||||
GARAGE_PORTE => "contact",
|
||||
RDC_CHAMBRE_BAIE => "contact",
|
||||
RDC_SALON_BAIE => "contact"
|
||||
);
|
||||
|
||||
public $delay = 3; // 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, $param, $value)
|
||||
public function callBack($device, $property, $value)
|
||||
{
|
||||
switch($param)
|
||||
|
||||
switch($property)
|
||||
{
|
||||
case "contact":
|
||||
if ($value == false)
|
||||
{
|
||||
logger(ALERT, sprintf(_("%s est ouverte alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ class rdc_salon_eclairage extends hook
|
||||
public $active = true;
|
||||
// list of devices we are listening to
|
||||
protected $devicelist = array(
|
||||
RDC_SALON_MVMT => array("occupancy", false),
|
||||
RDC_SALON_MVMT2 => array("occupancy", false),
|
||||
RDC_ENTREE_PORTE => array("contact", false),
|
||||
RDC_SALON_LUMINOSITE => array("illuminance_lux", false)
|
||||
RDC_SALON_MVMT => "occupancy",
|
||||
RDC_SALON_MVMT2 => "occupancy",
|
||||
RDC_ENTREE_PORTE => "contact",
|
||||
RDC_SALON_LUMINOSITE => "illuminance_lux"
|
||||
);
|
||||
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
@ -18,7 +18,7 @@ class rdc_salon_eclairage extends hook
|
||||
public $luminance_max = 100;
|
||||
|
||||
// callback fonction. Is called with these 4 parameters
|
||||
public function callBack(&$device, $param, $value)
|
||||
public function callBack($device, $param, $value)
|
||||
{
|
||||
global $indexDevices;
|
||||
logger(INFO, _("hook : rdc_salon_eclairage"), __FILE__ . ":" . __LINE__);
|
||||
@ -33,12 +33,17 @@ class rdc_salon_eclairage extends hook
|
||||
case "occupancy":
|
||||
logger(INFO, _("CASE: Occupancy => ") . bool2string($value), __FILE__ . ":" . __LINE__);
|
||||
//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
|
||||
if ($value == ON and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min)
|
||||
if ($value == ON)
|
||||
{
|
||||
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
|
||||
$this->send($deviceTarget, "ON", null, AUTO);
|
||||
removeEvent($deviceTarget, "state", "OFF");
|
||||
}elseif ($value == OFF)
|
||||
$illuminance = getValue(RDC_SALON_LUMINOSITE, "illuminance_lux");
|
||||
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
|
||||
if ($illuminance <= $this->luminance_min)
|
||||
{
|
||||
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
|
||||
$this->send($deviceTarget, "ON", null, AUTO);
|
||||
removeEvent($deviceTarget, "state", "OFF");
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(INFO, _("Value is OFF"), __FILE__ . ":" . __LINE__);
|
||||
if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
|
||||
@ -74,7 +79,7 @@ class rdc_salon_eclairage extends hook
|
||||
{
|
||||
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
|
||||
}
|
||||
}elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON OR getValue(RDC_SALON_MVMT2,"occupancy") == ON))
|
||||
}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);
|
||||
|
@ -17,10 +17,10 @@ class rdc_sdb_eclairage extends hook
|
||||
// devicelist[$ieeAddress][0] => property to watch
|
||||
// devicelist[$ieeAddress][1] => initialized = true
|
||||
protected $devicelist = array(
|
||||
//RDC_SDB_DOUCHE_MVMT => array("occupancy", false),
|
||||
RDC_SDB_PLAFOND_MVMT => array("occupancy", false),
|
||||
RDC_SDB_MVMT => array("occupancy", false),
|
||||
RDC_SDB_WC_ECLAIRAGE => array("state_l1", false)
|
||||
RDC_SDB_DOUCHE_MVMT => "occupancy",
|
||||
RDC_SDB_PLAFOND_MVMT => "occupancy",
|
||||
RDC_SDB_MVMT => "occupancy",
|
||||
RDC_SDB_WC_ECLAIRAGE => "state_l1"
|
||||
);
|
||||
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
@ -29,10 +29,11 @@ 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__);
|
||||
switch($property)
|
||||
{
|
||||
case "occupancy":
|
||||
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
||||
if ($value == ON)
|
||||
{
|
||||
if (getValue($deviceTarget->ieeeAddress, "state_l1") != "ON")
|
||||
@ -44,6 +45,7 @@ class rdc_sdb_eclairage extends hook
|
||||
}
|
||||
break;
|
||||
case "state_l1":
|
||||
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
|
||||
if ($value == "ON")
|
||||
{
|
||||
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state_l1", "OFF", true);
|
||||
|
@ -7,16 +7,16 @@ class rdc_store extends hook
|
||||
public $timer = 0;
|
||||
public $luminance_min = 60;
|
||||
public $luminance_max = 3000;
|
||||
public $storeDownTime = 20;
|
||||
public $storeUpTime = 25;
|
||||
public $storeDownTime = 38;
|
||||
public $storeUpTime = 41;
|
||||
protected $storeLevel;
|
||||
|
||||
protected $propertyInitialized =array();
|
||||
protected $devicelist = array(
|
||||
RDC_EXTERIEUR_LUMINOSITE => array("illuminance_lux", false), // "ON"/"OFF"
|
||||
METEO => array("rainin", false),
|
||||
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", // "ON"/"OFF"
|
||||
METEO => "rainin",
|
||||
//METEO => array("solarradiation", false),
|
||||
METEO => array("windspeedkmh", false),
|
||||
METEO => array("windgustkmh", false)
|
||||
METEO => "windspeedkmh",
|
||||
METEO => "windgustkmh"
|
||||
);
|
||||
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
@ -27,22 +27,50 @@ class rdc_store extends hook
|
||||
{
|
||||
global $mohaDB, $devices, $indexDevices;
|
||||
|
||||
logger(DEBUG, "Callback : RDC_STORE", __FILE__ . ":" . __LINE__);
|
||||
$rain = 0;
|
||||
$exterieur_lux = 0;
|
||||
$rafale = 0;
|
||||
$soleil = 0;
|
||||
$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 (array_key_exists("position", $storeDevice->properties))
|
||||
{
|
||||
$storeLevel = $storeDevice->properties["position"];
|
||||
}else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
|
||||
{
|
||||
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
|
||||
}
|
||||
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$rain = $indexDevices[METEO]->properties["rainin"];
|
||||
}
|
||||
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
|
||||
{
|
||||
$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
|
||||
{
|
||||
$maxLevel = 100 / $rafale;
|
||||
if ($rafale != 0)
|
||||
{
|
||||
$maxLevel = 100 / $rafale;
|
||||
}
|
||||
}
|
||||
switch ($property)
|
||||
{
|
||||
case "illuminance_lux":
|
||||
logger(DEBUG, "CASE: illuminance_lux:" . $value, __FILE__ . ":" . __LINE__);
|
||||
if ($exterieur_lux > 3000)
|
||||
{
|
||||
if ($rain == 0 and $maxLevel != 0)
|
||||
@ -62,26 +90,29 @@ class rdc_store extends hook
|
||||
}
|
||||
break;
|
||||
case "rainin":
|
||||
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
|
||||
$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)
|
||||
{
|
||||
$this->close("Trop de vent");
|
||||
}elseif ($value > 40 and $level > 20)
|
||||
}elseif ($value > 40 and $this->storeLevel > 20)
|
||||
{
|
||||
$this->maxLevel = 20;
|
||||
$this->send(20);
|
||||
}elseif ($value > 30 and $level > 40)
|
||||
}elseif ($value > 30 and $this->storeLevel > 40)
|
||||
{
|
||||
$this->maxLevel = 40;
|
||||
$this->send(40);
|
||||
}elseif ($value >20 and $level > 60)
|
||||
}elseif ($value >20 and $this->storeLevel > 60)
|
||||
{
|
||||
$this->maxLevel = 60;
|
||||
$this->send(60);
|
||||
}elseif ($value >10 and $level > 80)
|
||||
}elseif ($value >10 and $this->storeLevel > 80)
|
||||
{
|
||||
$this->maxLevel = 80;
|
||||
$this->send(80);
|
||||
@ -91,6 +122,8 @@ class rdc_store extends hook
|
||||
}
|
||||
$this->close("Fortes rafales de vent");
|
||||
break;
|
||||
default:
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +131,8 @@ class rdc_store extends hook
|
||||
{
|
||||
if ($this->storeLevel < $level)
|
||||
{
|
||||
$this->send($level);
|
||||
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
|
||||
$this->send(100 - $level);
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,7 +140,9 @@ class rdc_store extends hook
|
||||
{
|
||||
if ($this->storeLevel != 0)
|
||||
{
|
||||
logger(DEBUG, "Close store :" . $level, __FILE__ . ":" . __LINE__);
|
||||
print ( "store fermé " . $reason);
|
||||
$this->send(100);
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,8 +153,7 @@ class rdc_store extends hook
|
||||
$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;
|
||||
$deviceObject->set(AUTO);
|
||||
}
|
||||
}
|
||||
|
@ -4,20 +4,24 @@ class rdc_wc_eclairage extends hook
|
||||
{
|
||||
public $hookName = "rdc_wc_eclairage";
|
||||
|
||||
protected $devicelist = array(RDC_SDB_WC_ECLAIRAGE => array("state_l2", false));
|
||||
protected $devicelist = array(
|
||||
RDC_SDB_WC_ECLAIRAGE => "state_l2",
|
||||
RDC_WC_MVMT => "occupancy"
|
||||
);
|
||||
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $delayManual = 8; // 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)
|
||||
public function callBack(&$device, $property, $value)
|
||||
{
|
||||
global $indexDevices;
|
||||
//var_dump($value);
|
||||
switch($property)
|
||||
{
|
||||
case "state_l2":
|
||||
logger(DEBUG, _("CASE: state_l2"), __FILE__ . ":" . __LINE__);
|
||||
if ($value == "ON")
|
||||
{
|
||||
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
|
||||
@ -27,9 +31,29 @@ class rdc_wc_eclairage extends hook
|
||||
deleteEvent(searchEvent($device, "state_l2", "OFF"));
|
||||
}
|
||||
break;
|
||||
case "occupancy":
|
||||
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
|
||||
if ($value == true)
|
||||
{
|
||||
$this->send("ON");
|
||||
}
|
||||
}
|
||||
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($state)
|
||||
{
|
||||
global $indexDevices;
|
||||
$deviceObject = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
|
||||
$msg = array("state_l2" => $state);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
$hooks["rdc_wc_eclairage"] = new rdc_wc_eclairage();
|
||||
|
Reference in New Issue
Block a user