2021-12-31 23:09:58 +01:00
< ? php
2022-01-17 00:18:50 +01:00
class rdc_salon_eclairage extends hook
2021-12-31 23:09:58 +01:00
{
2022-01-03 21:11:52 +01:00
public $hookName = " rdc_salon_eclairage " ;
2022-01-19 00:22:34 +01:00
public $active = true ;
2022-01-17 21:01:11 +01:00
// list of devices we are listening to
2022-01-17 00:18:50 +01:00
protected $devicelist = array (
RDC_SALON_MVMT => array ( " occupancy " , false ),
RDC_SALON_MVMT2 => array ( " occupancy " , false ),
RDC_ENTREE_PORTE => array ( " contact " , false ),
RDC_SALON_LUMINOSITE => array ( " illuminance_lux " , false )
2022-01-05 00:01:41 +01:00
);
2022-01-27 18:41:16 +01:00
public $delay = 3 ; // amount of time in $timeunit
2022-01-23 09:46:06 +01:00
public $timeUnit = " minute " ; // unit of time for delay, second, minute, hour, day, week, month, year
2022-01-06 13:03:26 +01:00
public $luminance_min = 60 ;
2022-01-02 12:14:30 +01:00
public $luminance_max = 3000 ;
2021-12-31 23:09:58 +01:00
2022-01-01 06:26:02 +01:00
// callback fonction. Is called with these 4 parameters
2022-01-02 18:14:13 +01:00
public function callBack ( & $device , $param , $value )
2021-12-31 23:09:58 +01:00
{
global $devices , $indexDevices ;
2022-01-17 21:01:11 +01:00
logger ( INFO , _ ( " hook : rdc_salon_eclairage " ));
2021-12-31 23:09:58 +01:00
switch ( $param )
{
case " occupancy " :
2022-01-17 21:01:11 +01:00
//print_r($indexDevices[RDC_SALON_LUMINOSITE]);
2022-01-20 00:26:57 +01:00
if ( $value == ON and $indexDevices [ RDC_SALON_LUMINOSITE ] -> illuminance_lux [ " value " ] <= $this -> luminance_min )
2022-01-02 18:14:13 +01:00
{
2022-01-27 18:41:16 +01:00
$this -> send ( " ON " , null , AUTO );
removeEvent ( $indexDevices [ RDC_SALON_ECLAIRAGE_PANNEAU ], " state " , " OFF " );
}
if ( $value == OFF )
{
if ( $indexDevices ( RDC_SALON_MVMT ) -> occupancy == OFF and $indexDevices ( RDC_SALON_MVMT2 ) -> occupancy == OFF )
{
setDelay ( $indexDevices [ RDC_SALON_ECLAIRAGE_PANNEAU ], $this -> delay , $this -> timeUnit , " state " , " OFF " , true );
//$this->send("ON", "OFF", AUTO);
}
2022-01-02 18:14:13 +01:00
}
2021-12-31 23:09:58 +01:00
break ;
case " contact " :
2022-01-05 00:01:41 +01:00
if ( $value == false and $indexDevices [ RDC_SALON_LUMINOSITE ] -> illuminance_lux [ " value " ] <= $this -> luminance_min )
2022-01-02 18:14:13 +01:00
{
2022-01-27 18:41:16 +01:00
//$this->send("ON", "OFF", AUTO);
2022-01-02 18:14:13 +01:00
}
2021-12-31 23:09:58 +01:00
break ;
2022-01-02 12:14:30 +01:00
case " illuminance_lux " :
2022-01-17 21:01:11 +01:00
if ( $value >= $this -> luminance_max )
{
2022-01-27 18:41:16 +01:00
//$this->send("OFF", null, AUTO);
removeEvent ( $indexDevices [ RDC_SALON_ECLAIRAGE_PANNEAU ], " state " , " OFF " );
2022-01-17 21:01:11 +01:00
}
2022-01-03 21:11:52 +01:00
break ;
2021-12-31 23:09:58 +01:00
}
2022-01-19 00:22:34 +01:00
logger ( INFO , sprintf ( _ ( " %s: notification received from MQTT from %s => parameter: %s value: %s " ), $this -> hookName , $device -> friendlyName , $param , bool2string ( $value )));
2021-12-31 23:09:58 +01:00
}
2022-01-20 00:26:57 +01:00
private function send ( $state , $delayState = false , $method = MANUAL )
2021-12-31 23:09:58 +01:00
{
global $devices , $indexDevices ;
2022-01-05 00:01:41 +01:00
$device = & $indexDevices [ RDC_SALON_ECLAIRAGE_PANNEAU ];
2022-01-19 00:22:34 +01:00
$msg = array ( " state " => $state );
2022-01-17 00:18:50 +01:00
if ( $device -> state [ " value " ] != $state )
2022-01-06 13:03:26 +01:00
{
logger ( INFO , sprintf ( _ ( " publishing message: %s to %s " ), json_encode ( $msg ), $device -> friendlyName ));
$device -> payload = $msg ;
2022-01-19 00:22:34 +01:00
$device -> set ();
2022-01-20 00:26:57 +01:00
$device -> method = $method ;
2022-01-06 13:03:26 +01:00
} else
{
logger ( INFO , sprintf ( _ ( " not publishing message: %s to %s, already set " ), json_encode ( $msg ), $device -> friendlyName ));
2022-01-20 00:26:57 +01:00
}
//echo 'delaystate = ' . var_dump($delayState);
if ( $delayState !== false ) setDelay ( $device , $this -> delay , $this -> timeUnit , " state " , $delayState , true );
2021-12-31 23:09:58 +01:00
}
}
2022-01-03 21:11:52 +01:00
$hooks [ " rdc_salon_eclairage " ] = new rdc_salon_eclairage ();
2021-12-31 23:09:58 +01:00
?>