DTux
/
dtux__moha
Archived
1
0
Fork 0

Compare commits

...

10 Commits

34 changed files with 762 additions and 561 deletions

4
.gitignore vendored
View File

@ -1,4 +0,0 @@
*~
*swp
*kdev4*
*.log

View File

@ -90,13 +90,16 @@ function apiServer($read)
logger(DEBUG, _("command is ") . $command, __FILE__ . ":" . __LINE__);
switch($command)
{
case "?":
case "help":
htmlSend($spawn, help($argList));
break;
case "dashboard":
apiDashboard($spawn, $argList["dashboard"]);
break;
case "browse":
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
apiBrowse($spawn, $argList);
//return true;
break;
case "get":
logger(DEBUG, _("GET reached"), __FILE__ . ":" . __LINE__);
@ -116,8 +119,8 @@ function apiServer($read)
htmlSend($spawn, apiNotify($argList));
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
break;
case "type":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
//case "type":
//logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
//htmlSend($spawn, apiDisplayByType($argList));
case "enable":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
@ -155,6 +158,10 @@ function apiServer($read)
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, test($argList));
break;
case "unavailable":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, unavailable($argList));
break;
default:
if (is_numeric(array_key_first($argList)))
{

View File

@ -606,22 +606,86 @@ function whoIsPresent($argList)
function test()
{
global $hooks;
global $scripts;
$portes = array();
$msg = "";
$msg = _("<b>Opened doors:</b>") . EOLH;
logger(DEBUG, _("Testing doors") , __FILE__ . ":" . __LINE__);
echo "testing doors";
$portes = $hooks["test_portes"]->testPortes();
$portes = $scripts["test_portes"]->testPortes();
if (!empty($portes))
{
$msg = _("Opened doors:") . EOLH;
foreach($portes as $value)
{
$msg .= $value . EOL;
}
}else
{
$msg .= _("No doors opened");
}
return $msg;
}
function unavailable()
{
global $indexDevices;
$msg = _("<b>List of unavailable devices:</b>") . EOLH;
foreach($indexDevices as $ieeeAddress => $device)
{
if (key_exists("availability", $device->properties))
{
if ($device->properties["availability"]["value"] == "offline")
{
$msg .= $device->friendlyName . EOLH;
}
}
}
return $msg;
}
function help()
{
$msg = "<table>";
$msg .= "<tr><td><b>Commands</b></td><td><b>Description and Parameters</b></td>";
$msg .= "<tr><td>browse</td><td>Browse device List<br>fn=friendlyname topic=topicname</td></tr>";
$msg .= "<tr><td>dashboard</td><td>Display dashboards<br>Name of the dashboard</td></tr>";
// $msg .= "<tr><td>deletedevice</td><td></td></tr>";
$msg .= "<tr><td>disable</td><td>Disable a hook<br>name of the hook</td></tr>";
$msg .= "<tr><td>dump</td><td>Display the content of a variable<br>variable name</td></tr>";
$msg .= "<tr><td>enable</td><td>Enable a hook<br>name of the hook</td></tr>";
$msg .= "<tr><td>friendlyname</td><td>Return friendlyname from ieeeadress<br>ieeeadress of device</td></tr>";
$msg .= "<tr><td>get</td><td>Get value of the property of a device<br>fn=friendlyname, topic=topic name, property=property name</td></tr>";
$msg .= "<tr><td>ispresent</td><td>Return the presence of a person<br>Name of the person</td></tr>";
$msg .= "<tr><td>notify</td><td>Notify when property condition and value<br>topic, fn, property, condition, value</td></tr>";
// $msg .= "<tr><td>type</td><td></td></tr>";
$msg .= "<tr><td>present</td><td>List persons present</td></tr>";
$msg .= "<tr><td>print</td><td>Dump the content of a variable<br>variable name</td></tr>";
$msg .= "<tr><td>property</td><td>Display all devices with given property<br>Property to display</td></tr>";
$msg .= "<tr><td>set</td><td>Set value of the property of a device<br>fn=friendlyname, topic=topic name, property=property name</td></tr>";
$msg .= "<tr><td>test</td><td>Return all opened doors</td></tr>";
$msg .= "<tr><td>unavailable</td><td>Displey all unavalaible devices</td></tr>";
$msg .= "<tr><td>verbose</td><td>Enable or disable log levels<br>" . htmlDisplayLoglevels() . "</td></tr>";
$msg .= "</table>";
return $msg;
}
function htmlDisplayLoglevels()
{
global $logLevels;
$text = "";
$flag = false;
foreach($logLevels as $level)
{
if ($flag === true)
{
$text .= " ,";
}else
{
$flag = true;
}
$text .= $level;
}
return $text;
}
?>

View File

@ -45,10 +45,9 @@ class etage_bureau_eclairage extends hook
//{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName));
$device->payload = $msg;
$device->set();
$device->properties["state"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true);
$device->set("state", $method);
//$device->properties["state"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true, IDLE);
//}else
//{

View File

@ -37,9 +37,9 @@ class etage_plan_travail_eclairage extends hook
//{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName));
$device->payload = $msg;
$device->set();
$device->properties["state_l1"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state_l1", $delayState, true);
$device->set("state_l1", $method);
//$device->properties["state_l1"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state_l1", $delayState, true, IDLE);
$device = & $indexDevices[ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE];
$msg = array("state" => $state);
@ -47,9 +47,9 @@ class etage_plan_travail_eclairage extends hook
//{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName));
$device->payload = $msg;
$device->set();
$device->properties["state"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true);
$device->set("state", $method);
//$device->properties["state"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true, IDLE);
//}else

View File

@ -111,6 +111,11 @@ class db extends mysqli
return $value[0];
}
}
/*function lastTime($deviceObject, $property)
{
$query = "SELECT date FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), date) < '00:" . str_pad($time, 2, "0", STR_PAD_LEFT ) . "'";
}*/
}
$mohaDB = new db();

View File

@ -18,10 +18,6 @@ class hook
{
$this->init();
}
if (method_exists($this, "iterate"))
{
$this->iterate();
}
foreach ($this->devicelist as $ieeeAddress => $property)
{
$this->propertyInitialized[$ieeeAddress][$property] = false;

View File

@ -41,13 +41,16 @@ class device
public function __construct()
{
$this->availability = array("value" => null, "functions" => array());
$this->properties["availability"] = array("value" => null, "functions" => array());
}
public function set($property, $method = IDLE) //, $event = null)
public function set($property, $method = null) //, $event = null)
{
if ($method !== null)
{
$this->properties[$property]["method"] = $method;
}
publish($this->topic . "/" . $this->friendlyName, $this->payload, "set");//, $event);
$this->properties[$property]["method"] = $method;
}
public function get()

View File

@ -1,8 +1,9 @@
<?php
$notificationLevel = ALERT;
$logLevel = DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT;
$logLevel = NOTICE | WARNING | ERROR | ALERT;
//set the apiServer activ or not
$apiServerIsActive = true;
// le premier utilisateur est l'utilisateur par défaut
$defaultUser = array(
"rdc" => "Daniel",

View File

@ -9,8 +9,9 @@
$deviceTable = array(
"0x00124b0022ebac5c" => "RDC_SALON_MVMT2",
"0x588e81fffe2cf695" => "RDC_SALON_MVMT",
"0xe0798dfffe4ffa2c" => "RDC_SALON_PRESENCE",
"0x00124b001f900753" => "RDC_ENTREE_PORTE",
"0x54ef4410005fb5a9" => "RDC_SALON_PRESENCE",
"0x00158d00047bc298" => "RDC_SALON_TEMPERATURE",
"0x00158d00091cb063" => "RDC_ENTREE_PORTE",
"0x00158d0001923c21" => "RDC_CHAMBRE_RADIATEUR",
"0x04cf8cdf3c78aff0" => "RDC_SALON_LUMINOSITE",
"0x588e81fffe343e8f" => "RDC_SALON_ECLAIRAGE_PANNEAU",
@ -23,11 +24,11 @@ $deviceTable = array(
"0xbc33acfffe458c65" => "RDC_SDB_RADIATEUR",
"0x00158d000533c45e" => "RDC_SDB_TEMP_HUM",
"0xa4c1384a2b586da9" => "RDC_WC_MVMT",
"0x00124b001f90ee7e" => "ENTREE_PORTE",
"0x00124b002226d9a2" => "GARAGE_PORTE",
"0x00158d00091cb17f" => "ENTREE_PORTE",
"0x00158d00091cac9d" => "GARAGE_PORTE",
"0x00158d0006bfb1e5" => "GARAGE_PORTAIL",
"0x00124b001f90e725" => "RDC_CHAMBRE_BAIE",
"0x00124b002226e384" => "RDC_SALON_BAIE",
"0x00158d000911d5f4" => "RDC_CHAMBRE_BAIE",
"0x00158d00091cb198" => "RDC_SALON_BAIE",
"0xbc33acfffe4583f7" => "ETAGE_SALON_RADIATEUR",
// "" => "ETAGE_CHAMBRE_RADIATEUR",
// "" => "ETAGE_SDB_RADIATEUR",
@ -53,6 +54,7 @@ $deviceTable = array(
"0x00124b00234484ad" => "RDC_CHAMBRE_MVMT",
"0x04cf8cdf3c7b6056" => "RDC_CHAMBRE_LUMINOSITE",
"0x00158d0006c0447c" => "RDC_CHAMBRE_ARMOIRE_GAUCHE",
"0x00158d0005782096" => "RDC_CHAMBRE_TEMPERATURE",
"0x842e14fffe9be0fc" => "RDC_STORE",
"0xa4c138165e31c0e8" => "RDC_STORE_VIBRATION",
"0x04cf8cdf3c7b3d64" => "RDC_EXTERIEUR_LUMINOSITE",

View File

@ -4,6 +4,7 @@ $macAddresses = array(
"E8:78:29:C2:79:22" => "Daniel",
//"84:CF:BF:8E:E6:A6" => "daniel",
"D0:9C:7A:DA:8E:D8" => "Maryclaire",
"D0:9C:7A:E4:B3:B9" => "Maryclaire",
"FA:61:B1:D8:3C:D4" => "Maryclaire",
"26:4D:40:5F:1E:10" => "Terence"
);

View File

@ -26,7 +26,7 @@ $properties2log = array(
"winddir" => 40,
"windspeedkmh" => 5,
"windgustkmh" => 5,
"rainin" => 0.5,
"rainin" => 0.005,
//"dailyrainin" => null,
//"weeklyrainin" => null,
//"monthlyrainin" => null,
@ -35,7 +35,7 @@ $properties2log = array(
"UV" => null,
"indoortempc" => 0.5,
"indoorhumidity" => 0.5,
"baromin" => 10,
"barominmb" => 10,
"presence" => null,
"vibration" => null
);

View File

@ -5,5 +5,3 @@ $users = array(
)
?>

22
configVent.php Normal file
View File

@ -0,0 +1,22 @@
<?php
$directionVent = array(
1 => array("N", "Nord", "0"),
2 => array("NNE", "NordNordEst", "22,5"),
3 => array("NE", "NordEst", "45"),
4 => array("ENE", "EstNordEst", "67,5"),
5 => array("E", "Est", "90"),
6 => array("ESE", "EstSudEst", "112,5"),
7 => array("SE", "SudEst", "135"),
8 => array("SSE", "SudSudEst", "157,5"),
9 => array("S", "Sud", "180"),
10 => array("SSO", "SudSudOuest", "202,5"),
11 => array("SO", "SudOuest", "225"),
12 => array("OSO", "OuestSudOuest", "247,5"),
13 => array("O", "Ouest", "270"),
14 => array("ONO", "OuestNordOuest", "292,5"),
15 => array("NO", "NordOuest", "315"),
16 => array("NNO", "NordNordOuest", "337,5")
)
?>

View File

@ -23,5 +23,12 @@ function configWatchInit()
}
}
function configWatchStop()
{
// stop la surveillance
inotify_rm_watch($cwfd, $watch_descriptor);
// Destruction de l'instance inotify
fclose($cwfd);
}
?>

View File

@ -51,7 +51,7 @@ while (1)
}
}
$result = array();
//ésleep(1);
//sleep(1);
}
function search($string)
@ -63,15 +63,15 @@ function search($string)
//echo "searching in " . $string . EOL;
foreach ($macAddresses as $needle => $nom)
{
echo $string . " ==> presenceD:" . $nom ." => " . $needle . EOL;
//echo $string . " ==> presenceD:" . $nom ." => " . $needle . EOL;
if (str_contains($string, $needle))
{
echo "presenceD: found " . $needle . EOL;
//echo "presenceD: found " . $needle . EOL;
$presenceTemp[$nom] = true;
$flag = true;
}
}
var_dump($presenceTemp);
//var_dump($presenceTemp);
return $presenceTemp;
}
@ -87,7 +87,7 @@ function send($msg)
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $result contains the output string
echo _("presenceDaemon: Curl sending message -") . $msg . __FILE__ . ":" . __LINE__ . EOL;
//echo _("presenceDaemon: Curl sending message -") . $msg . __FILE__ . ":" . __LINE__ . EOL;
if ($curlErr <= 5)
{

View File

@ -88,6 +88,7 @@ function addDevice($topic, $fn, $jsonDevice, $group=false )
{
$device["device"]->type = $jsonDevice["type"];
$device["device"]->ieeeAddress = $jsonDevice["ieee_address"];
$hooks["availability"]->installHook($device);
if ( !empty($jsonDevice["power_source"] ))
{
$device["device"]->powerSource = $jsonDevice["power_source"];
@ -126,7 +127,7 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
$device->properties[$string]["functions"] = array();
if(array_key_exists("access", $inputObject))
{
if ($inputObject["access"] && 2)
if ($inputObject["access"] & 2)
{
$device->properties[$string]["method"] = IDLE;
}
@ -231,7 +232,7 @@ function iterateDevice($topic, $fn, &$parentDevice, &$properties, $payloadArray,
$properties[$key]["functions"] = array();
if (array_key_exists("access", $properties[$key]))
{
if ($properties[$key]["access]"] && 2)
if ($properties[$key]["access]"] & 2)
{
$properties[$key]["method"] = IDLE;
}
@ -265,21 +266,17 @@ function getDevicesValues($topic)
{
if ($value["access"] & 4)
{
logger(DEBUG, _("Getting values of property: " . $property), __FILE__ . ":" . __LINE__ );
$device->payload[$property] = "";
$flag = true;
$device->get();
break;
}
}
}
//logger(DEBUG, print_r($device->payload, true), __FILE__ . ":" . __LINE__ );
if ($flag === true)
{
$device->get();
}
}else
{
}else
{
logger(DEBUG, _("no properties to get for device: " . $device->friendlyName ), __FILE__ . ":" . __LINE__ );
}
}
}
}
@ -295,6 +292,15 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
{
logger(INFO, sprintf(_("Logging Device property %s, %s"), $propertyTree . $key, bool2string($value)), __FILE__ . ":" . __LINE__);
$mohaDB->logProperty($parentDevice, $key, $value);
/*
if (!empty($propertiesLoggers))
{
foreach($propertiesLoggers as $logger)
{
$logger->callBack($parentDevice, $key, $value);
}
}
*/
logger(DEBUG, sprintf(_("old value was %s, new is %s" ), bool2string($property["value"]), bool2string($value)), __FILE__ . ":" . __LINE__);
}
$property["value"] = $value;

View File

@ -1 +0,0 @@
a:0:{}

View File

@ -9,7 +9,7 @@ class notificationFreemobile
public $lastTry;
public $lastTryTimeout = 5;
protected $dest = array(
"Daniel" => "15480189&pass=yVpPmCWmUl2HGp",
"Daniel" => "32886706&pass=JTGUY6l5OG73zX",
);
function __construct()

View File

@ -7,34 +7,31 @@ class availability extends hook
// by default all devices are listening for availability
protected $devicelist = array();
function init()
{
global $indexDevices;
$this->iterate();
}
protected function iterate()
{
global $indexDevices;
foreach ($indexDevices as $ieeeAddress => $value)
{
$deviceList[] = array( $ieeeAddress => "availability");
if (!key_exists("availability", $value->properties))
{
$value->properties["availability"] = "";
}
}
$this->installHooksFunction($indexDevices);
}
function installHooks(&$indexDevices)
{
static $indexDevicesSize;
$tmp = count($indexDevices);
if ($tmp != $indexDevicesSize)
{
$this->iterate();
$indexDevicesSize = $tmp;
}
$this->installHooksFunction($indexDevices);
return false;
}
function installHook(&$device)
{
global $indexDevices;
$this->devicelist = array($device["device"]->ieeeAddress => "availability");
$this->installHooksFunction($indexDevices);
}
// callback fonction. Is called with these 3 parameters
// $device -> calling device
// $property -> parameter passed by mqtt
@ -48,7 +45,7 @@ class availability extends hook
{
//echo "==========>>>>>> Availability $value" . EOL;
//if (!empty($device->availability))
//{[ Torrent911.com]
//{
$log = ALERT;
//}else
//{

View File

@ -9,7 +9,7 @@ class etage_temperature_int_ext extends hook
protected $devicelist = array(
METEO=> "tempc",
METEO => "tempc",
);
protected $portesList = array(

View File

@ -5,9 +5,10 @@ class <name_of_class> extends hook
public $hookName = <public name of the hook>;
public $active = true; //enable/disable hook (true => enabled)
protected $devicelist = array(<ieee address or constant defined in config/devices_constants.php> => array(<property of the device to watch>, false));
protected $devicelist = array(
<ieee address or constant defined in config/devices_constants.php> => array(<property to watch>, false));
// if you need some initialisation when creating the object, uncomment andput your code here.
// if you need some initialisation when creating the object, uncomment the funcion init below and put your code here.
// If existing, This function is called by __construct
/*protected function init()
{
@ -15,14 +16,22 @@ class <name_of_class> extends hook
}
*/
// you can intercept the hook installation in this function.
function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
// 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)
{
// here your code
if ($this->active == true)
{
// here your code
}
logger (INFO,sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
}
}

View File

@ -2,7 +2,7 @@
class radiateurs extends hook
{
public $hookName = "radiateurs";
public $active = false;
public $active = true;
/* already defined in hook class */
// public $active = true;
@ -25,6 +25,7 @@ class radiateurs extends hook
// ETAGE_BUREAU_FENETRE => "contact"
);
// list of actions (sensor => hvac)
protected $hvac = array(
RDC_CHAMBRE_BAIE => RDC_CHAMBRE_RADIATEUR,
RDC_SALON_BAIE => RDC_SALON_RADIATEUR,
@ -61,6 +62,7 @@ class radiateurs extends hook
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
if ($this->active === true)
{
// test mois entre mai et octobre
$now = date("MM");
if ($now <= 5 or $now >= 11)
{
@ -98,17 +100,22 @@ class radiateurs extends hook
}
}
// state = true when a door or window is open
function send($device, $state)
{
global $indexDevices;
$flag = false;
if ($state === false)
$setTo = 0;
if ($state === true)
{
$t = getValue($device->ieeeAddress, "current_heating_setpoint");
if ($t != $this->minTemp)
{
$this->prevTemp[$device->ieeeAddress] = getValue($device->ieeeAddress, "current_heating_setpoint");
$this->prevTemp[$device->ieeeAddress] = $t;
}
$setTo = $minTemp;
}else
{
$r = array_keys($this->hvac, $device->ieeeAddress);
@ -123,13 +130,17 @@ class radiateurs extends hook
}
if ($flag === false)
{
$msg = array("current_heating_setpoint" => (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19));
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;
$setTo = (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19);
}
}
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();

View File

@ -6,7 +6,7 @@ class rdc_salon_eclairage extends hook
public $active = true;
// list of devices we are listening to
protected $devicelist = array(
RDC_SALON_MVMT => "occupancy",
//RDC_SALON_MVMT => "occupancy",
RDC_SALON_MVMT2 => "occupancy",
RDC_ENTREE_PORTE => "contact",
RDC_SALON_LUMINOSITE => "illuminance_lux",
@ -14,7 +14,7 @@ class rdc_salon_eclairage extends hook
RDC_SALON_PRESENCE => "presence"
);
protected $actionneurs = array(
array(RDC_SALON_MVMT, "occupancy", 1),
//array(RDC_SALON_MVMT, "occupancy", 1),
array(RDC_SALON_MVMT2, "occupancy", 1),
array(RDC_SALON_PRESENCE, "presence", 1)
);
@ -48,20 +48,22 @@ class rdc_salon_eclairage extends hook
$method = $deviceTarget->properties["state"]["method"];
logger(INFO, sprintf (_("CASE: %s => "), $param) . bool2string($value), __FILE__ . ":" . __LINE__);
//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
if ($value == ON and $method == IDLE)
if ($value == ON)
{
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
if ($illuminance <= $this->luminance_min)
if ($method == IDLE)
{
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "ON", false, AUTO);
removeEvent($deviceTarget, "state", "OFF");
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
if ($illuminance <= $this->luminance_min)
{
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "ON", false, AUTO);
removeEvent($deviceTarget, "state", "OFF");
}
}
}else
}elseif ($method == AUTO)
{
logger(INFO, _("Value is OFF and method is ") . $method, __FILE__ . ":" . __LINE__);
if ((testActionneurs($this->actionneurs) == false) and ($method == AUTO))
//if ((getValue(RDC_SALON_MVMT, "occupancy") == OFF) and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF) and $method == AUTO)
if (testActionneurs($this->actionneurs) == 0)
{
logger(INFO, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "OFF", false, IDLE);
@ -97,10 +99,13 @@ class rdc_salon_eclairage extends hook
case "state":
logger(INFO, _("CASE : State"), __FILE__ . ":" . __LINE__);
$method = $deviceTarget->properties["state"]["method"];
if($value == "ON" and $method == IDLE)
if($value == "ON")
{
$deviceTarget->properties["state"]["method"] = MANUAL;
removeEvent($deviceTarget, "state", "OFF");
if ($method == IDLE)
{
$deviceTarget->properties["state"]["method"] = MANUAL;
removeEvent($deviceTarget, "state", "OFF");
}
}else
{
$deviceTarget->properties["state"]["method"] = IDLE;

View File

@ -9,9 +9,9 @@ class rdc_sdb_eclairage extends hook
// public $active = true;
//public $initlialized = false;
public $delay = 3; // amount of time in $timeunit
public $delayManual = 20; // amount of time in $timeunit for manual mode
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
//public $delay = 3; // amount of time in $timeunit
public $delayManual = 2; // amount of time in $timeunit for manual mode
public $timeUnit = "hour"; // unit of time for delay, second, minute, day, week, month, year
// list of devices we are listening to
// devicelist[$ieeAddress][0] => property to watch
@ -38,67 +38,72 @@ class rdc_sdb_eclairage extends hook
{
global $indexDevices;
//var_dump($value);
$deviceTarget = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
if ($deviceTarget !== null)
if ($this->active)
{
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
switch($property)
if (array_key_exists(RDC_SDB_WC_ECLAIRAGE, $indexDevices))
{
case "occupancy":
$method = $deviceTarget->properties["state_l1"]["method"];
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($value == ON)
{
if($method == IDLE)
{
logger(DEBUG, _("lighting with method auto"), __FILE__ . ":" . __LINE__);
//$deviceTarget->properties["state_l1"]["method"] = AUTO;
$this->send("ON", AUTO);
removeEvent($deviceTarget, "state", "OFF");
}
}elseif (!testActionneurs($this->actionneurs))
{
logger(DEBUG, _("Actionneurs are all false"), __FILE__ . ":" . __LINE__);
$this->send("OFF", IDLE);
}
break;
case "state_l1":
$method = $deviceTarget->properties["state_l1"]["method"];
$deviceTarget = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
$method = $deviceTarget->properties["state_l1"]["method"];
logger(DEBUG, "Method is " . $method, __FILE__ . ":" . __LINE__);
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($method == IDLE)
switch($property)
{
case "occupancy":
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($value === ON)
{
logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__);
removeEvent($deviceTarget, "state_l1", "OFF");
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
//setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
if($method === IDLE)
{
logger(DEBUG, _("lighting with method auto"), __FILE__ . ":" . __LINE__);
$this->send("ON", AUTO);
//removeEvent($deviceTarget, "state", "OFF");
}
}elseif ((testActionneurs($this->actionneurs) == 0) and ($method == AUTO))
{
logger(DEBUG, _("Actionneurs are all false"), __FILE__ . ":" . __LINE__);
$this->send("OFF", IDLE);
//removeEvent($deviceTarget, "state", "OFF");
}
}elseif ($value == "OFF")
{
$deviceTarget->properties["state_l1"]["method"] = IDLE;
removeEvent($deviceTarget, "state_l1", "OFF");
//$deviceTarget->properties["state_l1"]["method"] = IDLE;
logger(DEBUG, _("State_l1 is false light is off and method is ") . $method, __FILE__ . ":" . __LINE__);
}
break;
break;
case "state_l1":
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($method === IDLE)
{
logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__);
//removeEvent($deviceTarget, "state_l1", "OFF");
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}
}elseif ($value == "OFF")
{
$deviceTarget->properties["state_l1"]["method"] = IDLE;
removeEvent($deviceTarget, "state_l1", "OFF");
logger(DEBUG, _("State_l1 is false light is off and method is ") . $method, __FILE__ . ":" . __LINE__);
}
break;
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s method: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value), $deviceTarget->properties["state_l1"]["method"]), __FILE__ . ":" . __LINE__);
}else
{
logger (ERROR, RDC_SDB_WC_ECLAIRAGE . _(" does not exists"), __FILE__ . ":" . __LINE__);
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s method: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value), $deviceTarget->properties["state_l1"]["method"]), __FILE__ . ":" . __LINE__);
}else
{
logger (ERROR, RDC_SDB_WC_ECLAIRAGE . _(" does not exists"), __FILE__ . ":" . __LINE__);
}
}
private function send($state, $method)
public function send($state, $method)
{
global $indexDevices;
$msg = array("state_l1" => $state);
$device = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__);
//$device->properties["state_l1"]["method"] = $method;
logger(DEBUG, "method = " . $device->properties["state_l1"]["method"], __FILE__ . ":" . __LINE__);
$msg = array("state_l1" => $state);
$device->payload = $msg;
$device->set("state_l1", $method);
logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__);
}
}
$hooks["rdc_sdb_eclairage"] = new rdc_sdb_eclairage();

View File

@ -11,7 +11,6 @@ class rdc_store extends hook
public $storeUpTime = 41;
public $maxLevel;
public $storeLevel;
public $motorReversal = false;
protected $propertyInitialized =array();
protected $devicelist = array(
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
@ -45,200 +44,198 @@ class rdc_store extends hook
$rafale = 0;
$soleil = 0;
$storeDevice = $indexDevices[RDC_STORE];
$r = 100;
$r = 0;
$moving = "STOP";
$store2level = false;
$lastVibration = 0;
if (array_key_exists("moving", $storeDevice->properties))
if ($this->active == true)
{
$moving = $storeDevice->properties["moving"]["value"];
logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("motor_reversal", $storeDevice->properties))
{
if ($storeDevice->properties["motor_reversal"]["value"] == "ON")
if (array_key_exists("vibration", $indexDevices[RDC_STORE_VIBRATION]->properties))
{
$this->motorReversal = true;
$lastVibration = $mohaDB->moyenne($indexDevices[RDC_STORE_VIBRATION], "vibration", 5);
logger(DEBUG, "Last vibration inferior to 5 minutes" . bool2string($lastVibration ), __FILE__ . ":" . __LINE__);
}
if (array_key_exists("moving", $storeDevice->properties))
{
$moving = $storeDevice->properties["moving"]["value"];
logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__);
}
if (array_key_exists(METEO, $indexDevices))
{
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
{
$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"];
$rain = $rainTmp - $rainS;
$rainS = $rainTmp;
logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
{
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 10);
if ($rafale == 0)
{
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties))
{
if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50)
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
$vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6);
if ($vent == 0)
{
$vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"];
}
logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__);
}
if ($vent > $rafale)
{
$rafale = $vent;
}
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
{
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 10);
logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
}
}
if (array_key_exists("position", $storeDevice->properties))
{
$this->storeLevel = $storeDevice->properties["position"]["value"];
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
}else
{
$this->motorReversal = false;
$this->storeLevel = 0;
}
logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__);
}
if (array_key_exists(METEO, $indexDevices))
{
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties))
{
$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"];
$rain = $rainTmp - $rainS;
$rainS = $rainTmp;
logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
{
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
$facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"];
$facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 10);
if ($facadeLuxMoyen == 0)
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
$facadeLuxMoyen = $facade_lux;
}
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
if ($rafale == 0)
logger(DEBUG, "facade_lux=" . $facade_lux . " et facadeLuxMoyen=" . $facadeLuxMoyen, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
{
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
$exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 10);
if ($exterieurLuxMoyen == 0)
{
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
$exterieurLuxMoyen = $exterieur_lux;
}
logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
{
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
if ($salon_lux == 0)
{
$salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"];
}
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
}
// Calcul de la position du store
if ($exterieurLuxMoyen > 36000 or $exterieur_lux > 50000 or $salon_lux >600)
{
logger(DEBUG, "exterieurLuxMoyen > 36000 or exterieur_lux > 50000 or salon_lux >600", __FILE__ . ":" . __LINE__);
$store2level = $this->storeLevel + 20;
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100 and $facadeLuxMoyen < 10000)
{
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100 and facadeLuxMoyen < 10000", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
if ($rafale >= 70 or $rain != 0)
{
$this->maxLevel = 0;
logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
$this->close("vent trop fort ou pluie");
return 0;
}elseif ($rafale != 0)
{
//calcul du maxlevel par rapport a la vitesse des rafales
$r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10;
if ($r < 0)
{
$r = 0;
}else
{
$r = 100 - $r;
}
if ($lastVibration == 0)
{
$this->maxLevel = 100 - $r;
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties))
{
if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50)
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
$vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6);
if ($vent == 0)
{
$vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"];
}
logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__);
}
if ($vent > $rafale)
{
$rafale = $vent;
}
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
{
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 6);
logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
}
}
if (array_key_exists("position", $storeDevice->properties))
{
if ($this->motorReversal)
{
$this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
}else
{
$this->storeLevel = $storeDevice->properties["position"]["value"];
}
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
}else
{
$this->storeLevel = 0;
//return true;
}
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties))
{
$facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"];
$facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 5);
if ($facadeLuxMoyen == 0)
switch ($property)
{
$facadeLuxMoyen = $facade_lux;
}
logger(DEBUG, "facade_lux=" . $facade_lux . " et facadeLuxMoyen=" . $facadeLuxMoyen, __FILE__ . ":" . __LINE__);
}
case "rainin":
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
$this->close("Pluie");
break;
case "windgustkmh":
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
break;
case "vibration":
//$tmpStore = $this->storeLevel - 20;
/*if ($store2level == false or $store2level > $tmpStore)
{
$this->setTo($tmpStore, AUTO);
}*/
logger(DEBUG, "CASE: vibration:" . bool2string($value), __FILE__ . ":" . __LINE__);
if ($moving == "STOP")
{
$this->maxLevel -= 20;
}else
{
logger(DEBUG, "Store is moving so maxLevel not changed " . $moving, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
{
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
$exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5);
if ($exterieurLuxMoyen == 0)
{
$exterieurLuxMoyen = $exterieur_lux;
}
logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
{
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
if ($salon_lux == 0)
{
$salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"];
}
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
}
if ($exterieur_lux > 33000 or $salon_lux >600)
{
logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__);
if ($this->maxLevel != 0 and $salon_lux > 100)
{
$store2level = $this->storeLevel + 20;
}
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100 and $facadeLuxMoyen < 10000)
{
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
if ($rafale >= 70 or $rain != 0)
{
$this->maxLevel = 0;
logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
$this->close("vent trop fort ou pluie");
return 0;
}elseif ($rafale != 0)
{
//calcul du maxlevel par rapport a la vitesse des rafales
$r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10;
if ($r < 0) $r = 0;
$this->maxLevel = 100 - $r;
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
switch ($property)
{
case "rainin":
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
$this->close("Pluie");
default:
break;
case "windgustkmh":
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
break;
case "vibration":
$tmpStore = $this->storeLevel - 20;
if ($store2level == false or $store2level > $tmpStore)
{
$this->setTo($store2level, AUTO);
}
default:
break;
}
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
if ($this->storeLevel > $this->maxLevel)
{
$this->setTo($this->maxLevel, AUTO);
}elseif ($store2level !== false) //$store2level = false then no change on store position
{
if ( $store2level > $this->maxLevel )
}
if ($this->maxLevel < 0)
{
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($this->maxLevel, AUTO);
}else
$this->maxLevel = 0;
}
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
if ($store2level !== false) //$store2level = false then no change on store position
{
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
logger(DEBUG, "setting stor 2 store2level", __FILE__ . ":" . __LINE__);
$this->setTo($store2level, AUTO);
}
}else
{
logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__);
}
}
private function setTo($level, $method)
{
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
if ($level <= 100)
if ($level > $this->maxLevel)
{
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
$level = $this->maxLevel;
}elseif ($level <= 100)
{
logger(DEBUG, "Setting store position to:" . $level, __FILE__ . ":" . __LINE__);
$this->send($level, $method);
}//else
/*{
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);
}*/
}
}
private function close ($reason)
@ -254,9 +251,7 @@ class rdc_store extends hook
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_STORE];
$level = 100 - $level;
$msg = array("position" => $level);
$msg = array("position" => 100 - $level);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set("position", $method);

View File

@ -11,7 +11,6 @@ class rdc_store extends hook
public $storeUpTime = 41;
public $maxLevel;
public $storeLevel;
public $motorReversal = false;
protected $propertyInitialized =array();
protected $devicelist = array(
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
@ -45,186 +44,190 @@ class rdc_store extends hook
$rafale = 0;
$soleil = 0;
$storeDevice = $indexDevices[RDC_STORE];
$r = 100;
$r = 0;
$moving = "STOP";
$store2level = false;
$lastVibration = 0;
if (array_key_exists("moving", $storeDevice->properties))
if ($this->active == true)
{
$moving = $storeDevice->properties["moving"]["value"];
logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("motor_reversal", $storeDevice->properties))
{
if ($storeDevice->properties["motor_reversal"]["value"] == "ON")
if (array_key_exists("vibration", $indexDevices[RDC_store_vibration]->properties))
{
$this->motorReversal = true;
$lastVibration = $mohaDB->moyenne($indexDevices[RDC_store_vibration], "vibration", 5);
logger(DEBUG, "Last vibration inferior to 5 minutes" . bool2string($lastVibration ), __FILE__ . ":" . __LINE__);
}
if (array_key_exists("moving", $storeDevice->properties))
{
$moving = $storeDevice->properties["moving"]["value"];
logger(DEBUG, "Moving = " . $moving, __FILE__ . ":" . __LINE__);
}
if (array_key_exists(METEO, $indexDevices))
{
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
{
$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"];
$rain = $rainTmp - $rainS;
$rainS = $rainTmp;
logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
{
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 10);
if ($rafale == 0)
{
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties))
{
if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50)
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
$vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6);
if ($vent == 0)
{
$vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"];
}
logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__);
}
if ($vent > $rafale)
{
$rafale = $vent;
}
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
{
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 10);
logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
}
}
if (array_key_exists("position", $storeDevice->properties))
{
$this->storeLevel = $storeDevice->properties["position"]["value"];
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
}else
{
$this->motorReversal = false;
$this->storeLevel = 0;
}
logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__);
}
if (array_key_exists(METEO, $indexDevices))
{
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties))
{
$rainTmp = $indexDevices[METEO]->properties["rainin"]["value"];
$rain = $rainTmp - $rainS;
$rainS = $rainTmp;
logger(DEBUG, "rain=" . $rain, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("windgustkmh", $indexDevices[METEO]->properties))
{
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
$facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"];
$facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 10);
if ($facadeLuxMoyen == 0)
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
$facadeLuxMoyen = $facade_lux;
}
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
if ($rafale == 0)
logger(DEBUG, "facade_lux=" . $facade_lux . " et facadeLuxMoyen=" . $facadeLuxMoyen, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
{
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
$exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 10);
if ($exterieurLuxMoyen == 0)
{
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
$exterieurLuxMoyen = $exterieur_lux;
}
logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
{
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
if ($salon_lux == 0)
{
$salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"];
}
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
}
// Calcul de la position du store
if ($exterieurLuxMoyen > 36000 or $exterieur_lux > 50000 or $salon_lux >600)
{
logger(DEBUG, "exterieurLuxMoyen > 36000 or exterieur_lux > 50000 or salon_lux >600", __FILE__ . ":" . __LINE__);
$store2level = $this->storeLevel + 20;
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100 and $facadeLuxMoyen < 10000)
{
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100 and facadeLuxMoyen < 10000", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
if ($rafale >= 70 or $rain != 0)
{
$this->maxLevel = 0;
logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
$this->close("vent trop fort ou pluie");
return 0;
}elseif ($rafale != 0)
{
//calcul du maxlevel par rapport a la vitesse des rafales
$r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10;
if ($r < 0)
{
$r = 0;
}else
{
$r = 100 - $r;
}
if ($lastVibration == 0)
{
$this->maxLevel = 100 - $r;
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties))
{
if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50)
{
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
$vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6);
if ($vent == 0)
{
$vent = $indexDevices[METEO]->properties["windspeedkmh"]["value"];
}
logger(DEBUG, "vitesse du vent =" . $vent, __FILE__ . ":" . __LINE__);
}
if ($vent > $rafale)
{
$rafale = $vent;
}
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
{
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 6);
logger(DEBUG, "soleil=" . $soleil, __FILE__ . ":" . __LINE__);
}
}
if (array_key_exists("position", $storeDevice->properties))
{
if ($this->motorReversal)
{
$this->storeLevel = 100 - $storeDevice->properties["position"]["value"];
}else
{
$this->storeLevel = $storeDevice->properties["position"]["value"];
}
logger(DEBUG, "storeLevel=" . $this->storeLevel, __FILE__ . ":" . __LINE__);
}else
{
$this->storeLevel = 0;
//return true;
}
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties))
{
$facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"];
$facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 5);
if ($facadeLuxMoyen == 0)
switch ($property)
{
$facadeLuxMoyen = $facade_lux;
}
logger(DEBUG, "facade_lux=" . $facade_lux . " et facadeLuxMoyen=" . $facadeLuxMoyen, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties))
{
$exterieur_lux = $indexDevices[RDC_EXTERIEUR_LUMINOSITE]->properties["illuminance_lux"]["value"];
$exterieurLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 5);
if ($exterieurLuxMoyen == 0)
{
$exterieurLuxMoyen = $exterieur_lux;
}
logger(DEBUG, "exterieur_lux=" . $exterieur_lux . " et exterieurLuxMoyen=" . $exterieurLuxMoyen, __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_SALON_LUMINOSITE]->properties))
{
$salon_lux = $mohaDB->moyenne($indexDevices[RDC_SALON_LUMINOSITE], "illuminance_lux", 10);
if ($salon_lux == 0)
{
$salon_lux = $indexDevices[RDC_SALON_LUMINOSITE]->properties["illuminance_lux"]["value"];
}
logger(DEBUG, "salon_lux=" . $salon_lux, __FILE__ . ":" . __LINE__);
}
if ($exterieur_lux > 33000 or $salon_lux >600)
{
logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__);
if ($this->maxLevel != 0 and $salon_lux > 100)
{
$store2level = $this->storeLevel + 20;
}
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100 and $facadeLuxMoyen < 5000)
{
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible");
}
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
if ($rafale >= 70 or $rain != 0)
{
$this->maxLevel = 0;
logger(DEBUG, sprintf("rafale = %s and rain = %s",$rafale, $rain), __FILE__ . ":" . __LINE__);
$this->close("vent trop fort ou pluie");
return 0;
}elseif ($rafale != 0)
{
//calcul du maxlevel par rapport a la vitesse des rafales
$r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10;
if ($r < 0) $r = 0;
$this->maxLevel = 100 - $r;
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
switch ($property)
{
case "rainin":
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
$this->close("Pluie");
case "rainin":
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
$this->close("Pluie");
break;
case "windgustkmh":
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
break;
case "vibration":
//$tmpStore = $this->storeLevel - 20;
/*if ($store2level == false or $store2level > $tmpStore)
{
$this->setTo($tmpStore, AUTO);
}*/
$this->maxLevel -= 20;
default:
break;
case "windgustkmh":
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
break;
case "vibration":
$tmpStore = $this->storeLevel - 20;
if ($store2level == false or $store2level > $tmpStore)
}
if ($this->maxLevel < 0)
{
$this->maxLevel = 0;
}
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
if ($this->storeLevel > $this->maxLevel)
{
$this->setTo($this->maxLevel, AUTO);
}elseif ($store2level !== false) //$store2level = false then no change on store position
{
if ( $store2level > $this->maxLevel )
{
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($this->maxLevel, AUTO);
}else
{
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($store2level, AUTO);
}
default:
break;
}
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
if ($this->storeLevel > $this->maxLevel)
{
$this->setTo($this->maxLevel, AUTO);
}elseif ($store2level !== false) //$store2level = false then no change on store position
{
if ( $store2level > $this->maxLevel )
{
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($this->maxLevel, AUTO);
}else
{
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($store2level, AUTO);
logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__);
}
}else
{
logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__);
}
}
private function setTo($level, $method)
@ -254,8 +257,6 @@ class rdc_store extends hook
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_STORE];
$level = 100 - $level;
$msg = array("position" => $level);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;

View File

@ -9,7 +9,9 @@ class rdc_temperature_int_ext extends hook
protected $devicelist = array(
METEO=> "tempc",
METEO => "tempc",
//RDC_CHAMBRE_TEMPERATURE => "temperature",
//RDC_SALON_TEMPERATURE => "temperature"
);
protected $portesList = array(
@ -27,7 +29,7 @@ class rdc_temperature_int_ext extends hook
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $property, $value)
{
global $indexDevices, $hooks;
global $indexDevices, $scripts;
static $time;
$portes = array();
$status = -1;
@ -41,57 +43,61 @@ class rdc_temperature_int_ext extends hook
if ((now()->format("U") - $time->format("U")) > 300)
{
$indoorTemp = $device->properties["indoortempc"]["value"];
if ($property == "tempc")
{
$indoorTemp = $device->properties["indoortempc"]["value"];
if ( $value > $indoorTemp)
{
if( ($indoorTemp <= $this->tempSup) and empty($portes))
if ( $value > $indoorTemp)
{
$status = 1;
//logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif($indoorTemp >= $this -> tempSup and ! empty($portes))
{
$status = 0;
//logger(ALERT, _("Close doors to climate"), null, $device);
}
}elseif ( $value < $indoorTemp )
{
if (($indoorTemp >= $this->tempSup) and empty($portes) )
{
$status = 1;
//logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif ($indoorTemp <= $this->tempSup)
{
$status = 0;
//logger(ALERT, _("Close doors to climate"), null, $device);
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__, $device);
}
print_r($portes);
if ($status == 1)
{
$portes = $hooks["test_portes"]->testPortes($this->portesList, false, false);
if (empty($portes))
{
$time = now();
foreach($portes as $porte)
if( ($indoorTemp <= $this->tempSup) and empty($portes))
{
$msg .= $porte . "\n";
}
logger(ALERT, _("Open doors to climate") . $msg, null, $device);
}
}else
{
$portes = $hooks["test_portes"]->testPortes($this->portesList, false, true);
if (!empty($portes))
{
$time = now();
foreach($portes as $porte)
$status = 1;
//logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif($indoorTemp >= $this -> tempSup and ! empty($portes))
{
$msg .= $porte . "\n";
$status = 0;
//logger(ALERT, _("Close doors to climate"), null, $device);
}
}elseif ( $value < $indoorTemp )
{
if (($indoorTemp >= $this->tempSup) and empty($portes) )
{
$status = 1;
//logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif ($indoorTemp <= $this->tempSup)
{
$status = 0;
//logger(ALERT, _("Close doors to climate"), null, $device);
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__, $device);
}
//print_r($portes);
if ($status == 1)
{
$portes = $scripts["test_portes"]->testPortes($this->portesList, false, false);
if (empty($portes))
{
$time = now();
foreach($portes as $porte)
{
$msg .= $porte . "\n";
}
logger(ALERT, _("Open doors to climate") . $msg, null, $device);
}
}else
{
$portes = $scripts["test_portes"]->testPortes($this->portesList, false, true);
if (!empty($portes))
{
$time = now();
foreach($portes as $porte)
{
$msg .= $porte . "\n";
}
logger(ALERT, _("Close doors to climate\n") . $msg, null, $device);
}
logger(ALERT, _("Close doors to climate\n") . $msg, null, $device);
}
}
}

View File

@ -1,14 +1,17 @@
<?php
$title = "moha";
cli_set_process_title($title);
file_put_contents("/proc/".getmypid()."/comm",$title);
declare(ticks = 1);
$testMode = false;
$apiServerIsActive = true;
require "constants.php";
//Test mode is executing moha from its directory
//no test mode, moha is system wide
if ($testMode)
{
$logLevel = ALL; // INFO | NOTICE | WARNING | ERROR | ALERT; //ALL;
@ -28,6 +31,8 @@ if ($testMode)
}
require $configDir . "/config.php";
require $configDir . "/liste_telephones.php";
$listProperties = array("powerSource" => "batterie");
$listPropertiesKeys = array("expose");
@ -42,6 +47,8 @@ $indexTypes = array();
$indexProperties = array(); // index of properties
$hooksList = array(); // list of hooks to be included
$hooks = array(); // array of hooks
$scripts = array(); // array of user's script
$propertiesLoggers = array(); // array of loggers's callbacks
$topicsCallbacks = array(); // array of topics's callbacks
$notificationMethods = array(); // array of notification methods objects
$events = array(); // list of event objects
@ -58,10 +65,9 @@ $hooksInitialized = 0; // are all hooks initialized ? false/true
$flagHooks = false;
$devicesRequest = false; // set to true when publishing device request to zigbee2mqtt
$presence = array(); // name and status of presence
$timeLoop = new datetime("now");
// initalisation
if (!init()) exit(1);
// (re)démarre le démon de présence
@ -71,6 +77,10 @@ system("sudo /usr/bin/systemctl restart presenceD.service");
bindtextdomain("moha", "./locale");
textdomain("moha");
######################################################################################################################
## Fonctions ##
######################################################################################################################
function notify($message, $device)
{
global $notificationMethods, $defaultUser;
@ -192,10 +202,9 @@ function endMoha()
logger(ERROR, _("Can not store events db" ), __FILE__ . ":" . __LINE__);
}
if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true));
// stop la surveillance
inotify_rm_watch($cwfd, $watch_descriptor);
// Destruction de l'instance inotify
fclose($cwfd);
configWatchStop();
if ($connected)
{
$mid = $client->unsubscribe("#");
@ -219,9 +228,12 @@ function connect2mqttServer()
global $client;
$client->onConnect('connectResponse');
}
######################################################################################################################
## Main program ##
######################################################################################################################
logger(ALERT, _("starting moha"), __FILE__ . ":" . __LINE__);
logger(DEBUG, _("requiring config files -> devices_constants.php"), __FILE__ . ":" . __LINE__);
//include predefined file witch define constants for devices
if (is_readable($configDir . "/devices_constants.php"))
@ -247,9 +259,6 @@ require "config/liste_telephones.php";
require "presence.php";
require "apiserver/apiserver.php";
require "configWatch.php";
require $configDir . "/liste_telephones.php";
logger(DEBUG, _("Loading stored events datas from ") . $dataPath . "events.db", __FILE__ . ":" . __LINE__);
if (file_exists($dataPath . "events.db"))
@ -263,6 +272,7 @@ if (file_exists($dataPath . "events.db"))
}
}
// topics definition
listHooks("./topics_callbacks", $topicsCallbacks);
if (!empty($topicsCallbacks))
@ -290,6 +300,17 @@ if (!empty($hooksList)) // hooks to include if hooklist is not empty
$included = true;
}
//making list of scripts to include
listHooks("./scripts", $scriptsList);
if (!empty($scriptsList))
{
foreach ($scriptsList as $script)
{
logger(INFO, _("Including ") . $script, __FILE__ . ":" . __LINE__);
include $script;
}
}
logger(DEBUG, _("Loading stored topics datas from ") . $dataPath . "topics.db", __FILE__ . ":" . __LINE__);
if (file_exists($dataPath . "topics.db"))
{
@ -321,8 +342,6 @@ if (file_exists($dataPath . "devices.db"))
}
}
// Program start
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__);
$client = new Mosquitto\Client();
@ -366,16 +385,27 @@ configWatchInit();
while (true)
{
// test if looping is more then 5 second and send and alert
// echo date("c") . " début";
$now = new datetime("now");
$testTime = clone $now;
$testTime->modify("-5 second");
if ($timeLoop < $testTime)
{
logger(ALERT, _("MOHA Looping is > to 5 seconds"), __FILE__ . ":" . __LINE__);
}
$timeLoop = $now;
$client->loop(); // mqtt server loop()
if ($oneshot === false) // execute while the first loop :WARNING hooks can to be not initialized
if ($oneshot === false) // execute while the first loop :WARNING all hooks may not be initialized
{
echo date("c") . " One shot";
logger(DEBUG, _("Oneshot part of loop"), __FILE__ . ":" . __LINE__, false);
pws2mqttGetList();
$oneshot = true;
}
$nn = 0;
//echo date("c") . " initialisation des hooks";
if($hooksInitialized == 0) // all hooks are not initialized
{
$i = 1;
@ -394,18 +424,21 @@ while (true)
}
}
$hooksInitialized = $i;
}elseif($flagHooks === false)
/*}elseif($flagHooks === false)
{
logger(DEBUG, _("All hooks initialized"), __FILE__ . ":" . __LINE__);
$flagHooks = true;
}else // executed when hooks initialization finished but database init not finished
$flagHooks = true;*/
}else // executed when hooks initialization finished but database init may be not finished
{
//logger(DEBUG, _("looping"), __FILE__ . ":" . __LINE__);
}
// echo date("c") . " chech events";
checkEvents();
// echo date("c") . " topics availabiblity";
checkTopicsAvailability();
//echo date("c") . " apiserver";
if ($apiServerIsActive) apiServer($read);
//echo date("c") . " surveillance Configuration";
// surveillance du dossier de configuration
if ($cwfd !== false)
{
@ -420,13 +453,12 @@ while (true)
include $configDir . "/" . $event["name"];
}else
{
logger(DEBUG, _("configWatch : mauvaise extension, n'inclus pas ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
logger(DEBUG, _("configWatch : mauvaise extension, je n'inclus pas ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
}
}
}
}
//presence();
//echo date("c") . " fin";
}
endMoha();

View File

@ -1,4 +1,6 @@
<?php
// mosquitto-php related functions
logger(DEBUG,"Including mqtt_functions.php");
function messageReceived($message)
@ -98,7 +100,7 @@ function disconnectResponse($r)
{
$str = _('Cleanly ');
}
logger(ERROR, $str . _("disconnected from server"));
logger(ALERT, $str . _("disconnected from server"));
$connected = false;
}

View File

@ -2,27 +2,51 @@
require_once "events.php";
class test_portes extends hook
class test_portes
{
public $hookName = "test_portes";
public $active = true;
protected $devicelist = array(
public $deviceList = array(
RDC_ENTREE_PORTE => "contact",
GARAGE_PORTAIL => "contact",
GARAGE_PORTE => "contact",
ETAGE_PORTE_FENETRE => "contact",
ETAGE_CUISINE_FENETRE => "contact",
ETAGE_SALON_FENETRE => "contact",
RDC_CHAMBRE_BAIE => "contact",
RDC_SALON_BAIE => "contact",
);
function installHooks(&$indexDevices)
/*function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
return 1;
}*/
public function testPortes($deviceList=false, $send=true, $opened=true) :array
{
global $indexDevices;
global $indexDevices, $hooks;
$portes = array();
logger(DEBUG, _("Function testPorte"), __FILE__ . ":" . __LINE__);
if ($deviceList === false) $deviceList = $hooks["rdc_portes_ouvertes"]->devicelist;
if ($deviceList === false)
{
if (key_exists("rdc_portes_ouvertes", $hooks))
{
if (property_exists($hooks["rdc_portes_ouvertes"], devicelist))
{
$deviceList = $hooks["rdc_portes_ouvertes"]->devicelist;
}else
{
$deviceList = $this->deviceList;
}
}else
{
$deviceList = $this->deviceList;
}
}
$msg = "";
foreach ($deviceList as $device => $property)
{
@ -55,8 +79,8 @@ class test_portes extends hook
return $portes;
}
}
$hooks["test_portes"] = new test_portes();
logger(DEBUG, _("Initializing event"), __FILE__ . ":" . __LINE__);
$function = array($hooks["test_portes"], "testPortes");
$scripts["test_portes"] = new test_portes();
logger(DEBUG, _("Initializing test_portes"), __FILE__ . ":" . __LINE__);
$function = array($scripts["test_portes"], "testPortes");
//setRecurrentEvent("test_portes", $function, "", "", 0, -1, "", "", false, 21);
?>

View File

@ -13,7 +13,8 @@ StandardOutput=inherit
StandardError=inherit
Restart=always
User=domotique
roup=domotique
Group=domotique
Nice=15
[Install]
WantedBy=multi-user.target

View File

@ -17,7 +17,14 @@ chown domotique:domotique -R /var/log/moha.log
# GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
systemctl daemon-reload
systemctl enable presenceD.service
systemctl enable moha.service
R=`systemctl is-enabled presenceD.service`
if [ $R != "enabled" ];then
echo "enabling presenceD.service"
systemctl enable presenceD.service
fi
R=`systemctl is-enabled moha.service`
if [ $R != "enabled" ];then
echo "enabling moha.service"
systemctl enable moha.service
fi
#must enable service

View File

@ -24,7 +24,7 @@ function checkTopicsAvailability()
{
if ($topic->status == 1)
{
logger(DEBUG, "Topic is :" . $topicName . " and time is " . time() . " lastSeen is " . $topic->lastSeen, __FILE__ . ":" . __LINE__ );
//logger(DEBUG, "Topic is :" . $topicName . " and time is " . time() . " lastSeen is " . $topic->lastSeen, __FILE__ . ":" . __LINE__ );
if ((time() - $topic->lastSeen > $topic->timeOut*60) and ($topic->notificationSent == false))
{
if (logger(ALERT, $topicName . _(" is not available"), __FILE__ . ":" . __LINE__) == false);