2022-08-05 17:24:11 +02:00
< ? php
// script to prevent when exterior temperature become inferior or superior to interior one
class rdc_temperature_int_ext extends hook
{
public $hookName = " rdc_wc_eclairage " ;
public $active = true ; //enable/disable hook (true => enabled)
2022-08-12 10:41:55 +02:00
public $wantedTemp = 24 ;
2022-08-05 17:24:11 +02:00
protected $devicelist = array (
METEO => " tempc " ,
);
2022-08-12 10:41:55 +02:00
function installHooks ( & $indexDevices )
{
return $this -> installHooksFunction ( $indexDevices );
}
2022-08-05 17:24:11 +02:00
// callback fonction. Is called with these 4 parameters
public function callBack ( & $device , $property , $value )
{
global $indexDevices ;
2022-08-12 10:41:55 +02:00
static $status = - 1 ;
$indoorTemp = $device -> properties [ " indoortempc " ][ " value " ];
if ( (( $value > $this -> wantedTemp and $indoorTemp < $this -> wantedTemp ) or ( $value < $this -> wantedTemp and $indoorTemp >= $this -> wantedTemp )) and $status === 1 )
2022-08-05 17:24:11 +02:00
{
2022-08-05 17:34:23 +02:00
$status = 0 ;
2022-08-12 10:41:55 +02:00
logger ( ALERT , _ ( " Open doors to climate " ), null , $device );
} elseif ( (( $value > $this -> wantedTemp and $indoorTemp >= $this -> wantedTemp ) or ( $value < $this -> wantedTemp and $indoorTemp <= $this -> wantedTemp )) and $status === 0 )
2022-08-05 17:24:11 +02:00
{
2022-08-05 17:34:23 +02:00
$status = 1 ;
2022-08-12 10:41:55 +02:00
logger ( ALERT , _ ( " Close doors to climate " ), null , $device );
2022-08-05 17:24:11 +02:00
}
2022-08-12 10:41:55 +02:00
logger ( INFO , sprintf ( _ ( " %s: notification received from MQTT from %s => parameter: %s value: %s " ), $this -> hookName , $device -> friendlyName , $property , bool2string ( $value )), __FILE__ . " : " . __LINE__ , $device );
2022-08-05 17:24:11 +02:00
}
}
$hooks [ " rdc_temperature_int_ext " ] = new rdc_temperature_int_ext ();
?>