1
0
moha/hooks/scripts/panneau_salon.php

57 lines
1.6 KiB
PHP
Raw Normal View History

<?php
class panneau_salon
{
private $devicelist = array("0x00124b0022ebac5c", "0x588e81fffe2cf695", "0x00124b001f900753", "0x04cf8cdf3c78aff0");
public $delay = 3;
public $timeUnit = "min";
function __construct()
{
global $indexDevices;
foreach ($this->devicelist as $ieeeAddress)
{
$indexDevices[$ieeeAddress]->functions[] = array($this,"callback");
//print_r($indexDevices[$ieeeAddress]);
}
}
public function callBack($topic, $fn, $param, $value)
{
global $devices, $indexDevices;
switch($param)
{
case "occupancy":
if ($value == 1) $this->send();
break;
case "contact":
if ($value == false) $this->send();
break;
}
echo _("notification received from MQTT") . EOL;
//echo $param . "=> " . $value . EOL;
}
private function send()
{
global $devices, $indexDevices;
if ($indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= 76)
{
$msg = array("state" => "ON");
$device = & $indexDevices["0x588e81fffe343e8f"];
$device->payload = $msg;
$device->set(null);
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
}
}
}
$panneau_salon = new panneau_salon();
//assignation of the function to the sensors devices
//$indexDevices["0x00124b0022ebac5c"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt2
//$indexDevices["0x588e81fffe2cf695"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt
//$indexDevices["0x00124b001f900753"]->functions[] = array($panneau_salon,"getCallback"); // rdc-porte-entree
//$indexDevices["0x04cf8cdf3c78aff0"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-luminosite
?>