1
0
moha/hooks/scripts/radiateurs.php

149 lines
4.0 KiB
PHP
Raw Permalink Normal View History

<?php
class radiateurs extends hook
{
public $hookName = "radiateurs";
2023-01-26 18:30:51 +01:00
public $active = true;
/* 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"
);
2023-01-26 18:30:51 +01:00
// list of actions (sensor => hvac)
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
);
2023-01-26 18:30:51 +01:00
function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
// 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)
{
2022-12-05 12:23:43 +01:00
// test mois entre mai et octobre
$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);
}
}
}
}
2022-12-05 12:23:43 +01:00
// state = true when a door or window is open
function send($device, $state)
{
global $indexDevices;
$flag = false;
2022-12-05 12:23:43 +01:00
$setTo = 0;
if ($state === true)
{
$t = getValue($device->ieeeAddress, "current_heating_setpoint");
if ($t != $this->minTemp)
{
2023-01-26 18:30:51 +01:00
$this->prevTemp[$device->ieeeAddress] = $t;
}
2022-12-05 12:23:43 +01:00
$setTo = $minTemp;
}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)
{
2022-12-05 12:23:43 +01:00
$setTo = (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19);
}
}
2022-12-05 12:23:43 +01:00
if ($setTo <> 0)
{
$msg = array("current_heating_setpoint" => $setTo );
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();
?>