1
0
moha/hooks/scripts/radiateurs.php

129 lines
3.4 KiB
PHP
Raw Normal View History

<?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();
?>