2022-01-23 09:46:06 +01:00
< ? php
class rdc_chambre_eclairage extends hook
{
public $hookName = " rdc_chambre_eclairage " ;
2022-01-29 19:58:01 +01:00
public $active = true ; //enable/disable hook (true => enabled)
2022-01-27 18:41:16 +01:00
public $delay = 5 ; // amount of time in $timeunit
public $timeUnit = " minute " ; // unit of time for delay, second, minute, hour, day, week, month, year
public $luminance_min = 60 ;
public $luminance_max = 3000 ;
protected $devicelist = array (
2022-02-02 21:18:44 +01:00
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 )
2022-01-27 18:41:16 +01:00
);
2022-01-23 09:46:06 +01:00
// callback fonction. Is called with these 3 parameters
// $device -> calling device
// $property -> property of the device (given by mqtt)
// $value -> value of the property
public function callBack ( & $device , $property , $value )
{
2022-01-27 18:41:16 +01:00
global $devices , $indexDevices ;
$lux = $indexDevices [ RDC_CHAMBRE_LUMINOSITE ] -> illuminance_lux ;
if ( $property == " occupancy " and $value == " ON " )
{
2022-01-29 19:58:01 +01:00
$this -> send ( RDC_CHAMBRE_AMBIANCE , " ON " , " OFF " , AUTO );
2022-02-02 21:18:44 +01:00
} elseif ( $property == " contact " and $value = true and getValue ( RDC_CHAMBRE_ECLAIRAGE , " state_l1 " ) == " OFF " )
2022-01-29 19:58:01 +01:00
{
$this -> send ( RDC_CHAMBRE_ECLAIRAGE , " ON " , " OFF " , AUTO );
2022-01-27 18:41:16 +01:00
}
2022-01-28 23:05:58 +01:00
logger ( INFO , sprintf ( _ ( " %s: notification received from MQTT from %s => parameter: %s value: %s " ), $this -> hookName , $device -> friendlyName , $property , $value ), __FILE__ . " : " . __LINE__ );
2022-01-27 18:41:16 +01:00
}
private function send ( $device , $state , $delayState = false , $method = MANUAL )
{
global $devices , $indexDevices ;
$device = & $indexDevices [ $device ];
$msg = array ( " state " => $state );
if ( $device -> state [ " value " ] != $state )
{
2022-01-28 23:05:58 +01:00
logger ( INFO , sprintf ( _ ( " publishing message: %s to %s " ), json_encode ( $msg ), $device -> friendlyName ), __FILE__ . " : " . __LINE__ );
2022-01-27 18:41:16 +01:00
$device -> payload = $msg ;
$device -> set ();
$device -> method = $method ;
} else
{
2022-01-28 23:05:58 +01:00
logger ( INFO , sprintf ( _ ( " not publishing message: %s to %s, already set " ), json_encode ( $msg ), $device -> friendlyName ), __FILE__ . " : " . __LINE__ );
2022-01-23 09:46:06 +01:00
2022-01-27 18:41:16 +01:00
}
//echo 'delaystate = ' . var_dump($delayState);
if ( $delayState !== false ) setDelay ( $device , $this -> delay , $this -> timeUnit , " state " , $delayState , true );
2022-01-23 09:46:06 +01:00
}
}
$hooks [ " rdc_chambre_eclairage " ] = new rdc_chambre_eclairage ();
?>