1
0
moha/hooks/scripts/radiateurs.php
2022-06-20 10:34:55 +02:00

133 lines
3.7 KiB
PHP

<?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: ieeeAddress => property to watch
protected $devicelist = array(
RDC_CHAMBRE_BAIE => "contact",
// RDC_SALON_BAIE => "contact",
// RDC_ENTREE_PORTE => "contact",
ETAGE_PORTE_ENTREE => "contact",
ETAGE_CUISINE_FENETRE => "contact",
ETAGE_SALON_FENETRE => "contact",
ETAGE_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,
GARAGE_PORTE => RDC_SDB_RADIATEUR,
ETAGE_PORTE_ENTREE => ETAGE_SALON_RADIATEUR,
ETAGE_CUISINE_FENETRE => ETAGE_SALON_RADIATEUR,
ETAGE_SALON_FENETRE => ETAGE_SALON_RADIATEUR,
ETAGE_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;
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
if ($this->active === true)
{
$now = date("MM");
if ($now <= 5 or $now >= 11)
{
if ($value === false)
{
$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_BUREAU_FENETRE:
break;
}*/
}else
{
$this->send($indexDevices[$this->hvac[$device->ieeeAddress]], false);
}
}
}
}
function send($device, $state)
{
global $indexDevices;
$flag = false;
if ($state === false)
{
$t = getValue($device->ieeeAddress, "current_heating_setpoint");
if ($t != $this->minTemp)
{
$this->prevTemp[$device->ieeeAddress] = getValue($device->ieeeAddress, "current_heating_setpoint");
}
}else
{
$r = array_keys($this->hvac, $device->ieeeAddress);
foreach($r as $value)
{
logger(DEBUG, "Device to test for contact " . $value, __FILE__ . ":" . __LINE__);
if (getValue($device->ieeeAddress, "contact") === true)
{
$flag &= true;
break;
}
}
if ($flag === false)
{
$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("current_heating_setpoint", AUTO);
$device->properties["current_heating_setpoint"]["method"] = AUTO;
}
}
}
}
$hooks["radiateurs"] = new radiateurs();
?>