1
0

Compare commits

..

No commits in common. "c283ce72e2790f70b1b1926cccb08c2020e3bde9" and "87577f6d7180d31620f754e5548a4108104794f1" have entirely different histories.

34 changed files with 564 additions and 765 deletions

4
.gitignore vendored Normal file
View File

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

View File

@ -90,16 +90,13 @@ 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__);
@ -119,8 +116,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__);
@ -158,10 +155,6 @@ 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,86 +606,22 @@ function whoIsPresent($argList)
function test()
{
global $scripts;
global $hooks;
$portes = array();
$msg = _("<b>Opened doors:</b>") . EOLH;
$msg = "";
logger(DEBUG, _("Testing doors") , __FILE__ . ":" . __LINE__);
echo "testing doors";
$portes = $scripts["test_portes"]->testPortes();
$portes = $hooks["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,9 +45,10 @@ class etage_bureau_eclairage extends hook
//{
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName));
$device->payload = $msg;
$device->set("state", $method);
//$device->properties["state"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true, IDLE);
$device->set();
$device->properties["state"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true);
//}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("state_l1", $method);
//$device->properties["state_l1"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state_l1", $delayState, true, IDLE);
$device->set();
$device->properties["state_l1"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state_l1", $delayState, true);
$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("state", $method);
//$device->properties["state"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true, IDLE);
$device->set();
$device->properties["state"]["method"] = $method;
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true);
//}else

View File

@ -111,11 +111,6 @@ 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,6 +18,10 @@ 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,16 +41,13 @@ class device
public function __construct()
{
$this->properties["availability"] = array("value" => null, "functions" => array());
$this->availability = array("value" => null, "functions" => array());
}
public function set($property, $method = null) //, $event = null)
public function set($property, $method = IDLE) //, $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,9 +1,8 @@
<?php
$notificationLevel = ALERT;
$logLevel = NOTICE | WARNING | ERROR | ALERT;
//set the apiServer activ or not
$apiServerIsActive = true;
$logLevel = DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT;
// le premier utilisateur est l'utilisateur par défaut
$defaultUser = array(
"rdc" => "Daniel",

View File

@ -9,9 +9,8 @@
$deviceTable = array(
"0x00124b0022ebac5c" => "RDC_SALON_MVMT2",
"0x588e81fffe2cf695" => "RDC_SALON_MVMT",
"0x54ef4410005fb5a9" => "RDC_SALON_PRESENCE",
"0x00158d00047bc298" => "RDC_SALON_TEMPERATURE",
"0x00158d00091cb063" => "RDC_ENTREE_PORTE",
"0xe0798dfffe4ffa2c" => "RDC_SALON_PRESENCE",
"0x00124b001f900753" => "RDC_ENTREE_PORTE",
"0x00158d0001923c21" => "RDC_CHAMBRE_RADIATEUR",
"0x04cf8cdf3c78aff0" => "RDC_SALON_LUMINOSITE",
"0x588e81fffe343e8f" => "RDC_SALON_ECLAIRAGE_PANNEAU",
@ -24,11 +23,11 @@ $deviceTable = array(
"0xbc33acfffe458c65" => "RDC_SDB_RADIATEUR",
"0x00158d000533c45e" => "RDC_SDB_TEMP_HUM",
"0xa4c1384a2b586da9" => "RDC_WC_MVMT",
"0x00158d00091cb17f" => "ENTREE_PORTE",
"0x00158d00091cac9d" => "GARAGE_PORTE",
"0x00124b001f90ee7e" => "ENTREE_PORTE",
"0x00124b002226d9a2" => "GARAGE_PORTE",
"0x00158d0006bfb1e5" => "GARAGE_PORTAIL",
"0x00158d000911d5f4" => "RDC_CHAMBRE_BAIE",
"0x00158d00091cb198" => "RDC_SALON_BAIE",
"0x00124b001f90e725" => "RDC_CHAMBRE_BAIE",
"0x00124b002226e384" => "RDC_SALON_BAIE",
"0xbc33acfffe4583f7" => "ETAGE_SALON_RADIATEUR",
// "" => "ETAGE_CHAMBRE_RADIATEUR",
// "" => "ETAGE_SDB_RADIATEUR",
@ -54,7 +53,6 @@ $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,7 +4,6 @@ $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.005,
"rainin" => 0.5,
//"dailyrainin" => null,
//"weeklyrainin" => null,
//"monthlyrainin" => null,
@ -35,7 +35,7 @@ $properties2log = array(
"UV" => null,
"indoortempc" => 0.5,
"indoorhumidity" => 0.5,
"barominmb" => 10,
"baromin" => 10,
"presence" => null,
"vibration" => null
);

View File

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

View File

@ -1,22 +0,0 @@
<?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,12 +23,5 @@ 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,7 +88,6 @@ 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"];
@ -127,7 +126,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;
}
@ -232,7 +231,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;
}
@ -266,17 +265,21 @@ function getDevicesValues($topic)
{
if ($value["access"] & 4)
{
logger(DEBUG, _("Getting values of property: " . $property), __FILE__ . ":" . __LINE__ );
$device->payload[$property] = "";
$device->get();
$flag = true;
break;
}
}
}
}else
{
//logger(DEBUG, print_r($device->payload, true), __FILE__ . ":" . __LINE__ );
if ($flag === true)
{
$device->get();
}
}else
{
logger(DEBUG, _("no properties to get for device: " . $device->friendlyName ), __FILE__ . ":" . __LINE__ );
}
}
}
}
@ -292,15 +295,6 @@ 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

@ -5,10 +5,9 @@ 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 to watch>, false));
protected $devicelist = array(<ieee address or constant defined in config/devices_constants.php> => array(<property of the device to watch>, false));
// if you need some initialisation when creating the object, uncomment the funcion init below and put your code here.
// if you need some initialisation when creating the object, uncomment andput your code here.
// If existing, This function is called by __construct
/*protected function init()
{
@ -16,22 +15,14 @@ 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)
{
if ($this->active == true)
{
// here your code
}
// 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__);
}
}

1
events.db Normal file
View File

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

View File

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

View File

@ -7,31 +7,34 @@ 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)
{
if (!key_exists("availability", $value->properties))
{
$value->properties["availability"] = "";
}
$deviceList[] = array( $ieeeAddress => "availability");
}
$this->installHooksFunction($indexDevices);
}
function installHooks(&$indexDevices)
{
$this->installHooksFunction($indexDevices);
static $indexDevicesSize;
$tmp = count($indexDevices);
if ($tmp != $indexDevicesSize)
{
$this->iterate();
$indexDevicesSize = $tmp;
}
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
@ -45,7 +48,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

@ -2,7 +2,7 @@
class radiateurs extends hook
{
public $hookName = "radiateurs";
public $active = true;
public $active = false;
/* already defined in hook class */
// public $active = true;
@ -25,7 +25,6 @@ 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,
@ -62,7 +61,6 @@ 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)
{
@ -100,22 +98,17 @@ class radiateurs extends hook
}
}
// state = true when a door or window is open
function send($device, $state)
{
global $indexDevices;
$flag = false;
$setTo = 0;
if ($state === true)
if ($state === false)
{
$t = getValue($device->ieeeAddress, "current_heating_setpoint");
if ($t != $this->minTemp)
{
$this->prevTemp[$device->ieeeAddress] = $t;
$this->prevTemp[$device->ieeeAddress] = getValue($device->ieeeAddress, "current_heating_setpoint");
}
$setTo = $minTemp;
}else
{
$r = array_keys($this->hvac, $device->ieeeAddress);
@ -130,17 +123,13 @@ class radiateurs extends hook
}
if ($flag === false)
{
$setTo = (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19);
$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;
}
}
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,22 +48,20 @@ 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)
if ($value == ON and $method == IDLE)
{
if ($method == IDLE)
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
if ($illuminance <= $this->luminance_min)
{
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");
}
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "ON", false, AUTO);
removeEvent($deviceTarget, "state", "OFF");
}
}elseif ($method == AUTO)
}else
{
logger(INFO, _("Value is OFF and method is ") . $method, __FILE__ . ":" . __LINE__);
if (testActionneurs($this->actionneurs) == 0)
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)
{
logger(INFO, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "OFF", false, IDLE);
@ -99,13 +97,10 @@ class rdc_salon_eclairage extends hook
case "state":
logger(INFO, _("CASE : State"), __FILE__ . ":" . __LINE__);
$method = $deviceTarget->properties["state"]["method"];
if($value == "ON")
if($value == "ON" and $method == IDLE)
{
if ($method == IDLE)
{
$deviceTarget->properties["state"]["method"] = MANUAL;
removeEvent($deviceTarget, "state", "OFF");
}
$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 = 2; // amount of time in $timeunit for manual mode
public $timeUnit = "hour"; // unit of time for delay, second, minute, day, week, month, year
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
// list of devices we are listening to
// devicelist[$ieeAddress][0] => property to watch
@ -38,72 +38,67 @@ class rdc_sdb_eclairage extends hook
{
global $indexDevices;
//var_dump($value);
if ($this->active)
$deviceTarget = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
if ($deviceTarget !== null)
{
if (array_key_exists(RDC_SDB_WC_ECLAIRAGE, $indexDevices))
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
switch($property)
{
$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__);
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"];
switch($property)
{
case "occupancy":
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($value === ON)
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($method == 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");
}
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;
logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__);
removeEvent($deviceTarget, "state_l1", "OFF");
logger(DEBUG, _("State_l1 is false light is off and method is ") . $method, __FILE__ . ":" . __LINE__);
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
//setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}
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__);
}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;
}
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__);
}
}
public function send($state, $method)
private function send($state, $method)
{
global $indexDevices;
$device = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
//$device->properties["state_l1"]["method"] = $method;
logger(DEBUG, "method = " . $device->properties["state_l1"]["method"], __FILE__ . ":" . __LINE__);
$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->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,6 +11,7 @@ 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",
@ -44,198 +45,200 @@ class rdc_store extends hook
$rafale = 0;
$soleil = 0;
$storeDevice = $indexDevices[RDC_STORE];
$r = 0;
$r = 100;
$moving = "STOP";
$store2level = false;
$lastVibration = 0;
if ($this->active == true)
if (array_key_exists("moving", $storeDevice->properties))
{
if (array_key_exists("vibration", $indexDevices[RDC_STORE_VIBRATION]->properties))
$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")
{
$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__);
$this->motorReversal = true;
}else
{
$this->storeLevel = 0;
$this->motorReversal = false;
}
logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties))
if (array_key_exists(METEO, $indexDevices))
{
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
{
$facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"];
$facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 10);
if ($facadeLuxMoyen == 0)
$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)
{
$facadeLuxMoyen = $facade_lux;
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
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 = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
if ($rafale == 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__);
}
// 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;
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
switch ($property)
if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties))
{
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__);
}
default:
break;
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 ($this->maxLevel < 0)
if ($vent > $rafale)
{
$this->maxLevel = 0;
$rafale = $vent;
}
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
if ($store2level !== false) //$store2level = false then no change on store position
if (array_key_exists("solarradiation", $indexDevices[METEO]->properties))
{
logger(DEBUG, "setting stor 2 store2level", __FILE__ . ":" . __LINE__);
$this->setTo($store2level, AUTO);
$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;
}
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)
{
$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 < 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");
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 )
{
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($this->maxLevel, AUTO);
}else
{
logger(DEBUG, "store2level <= maxLevel", __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 > $this->maxLevel)
if ($level <= 100)
{
$level = $this->maxLevel;
}elseif ($level <= 100)
{
logger(DEBUG, "Setting store position to:" . $level, __FILE__ . ":" . __LINE__);
logger(DEBUG, "Open store :" . $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)
@ -251,7 +254,9 @@ class rdc_store extends hook
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_STORE];
$msg = array("position" => 100 - $level);
$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;
$deviceObject->set("position", $method);

View File

@ -11,6 +11,7 @@ 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",
@ -44,190 +45,186 @@ class rdc_store extends hook
$rafale = 0;
$soleil = 0;
$storeDevice = $indexDevices[RDC_STORE];
$r = 0;
$r = 100;
$moving = "STOP";
$store2level = false;
$lastVibration = 0;
if ($this->active == true)
if (array_key_exists("moving", $storeDevice->properties))
{
if (array_key_exists("vibration", $indexDevices[RDC_store_vibration]->properties))
$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")
{
$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__);
$this->motorReversal = true;
}else
{
$this->storeLevel = 0;
$this->motorReversal = false;
}
logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__);
}
if (array_key_exists("illuminance_lux", $indexDevices[RDC_FACADE_LUMINOSITE]->properties))
if (array_key_exists(METEO, $indexDevices))
{
if (array_key_exists("rainin", $indexDevices[METEO]->properties))
{
$facade_lux = $indexDevices[RDC_FACADE_LUMINOSITE]->properties["illuminance_lux"]["value"];
$facadeLuxMoyen = $mohaDB->moyenne($indexDevices[RDC_FACADE_LUMINOSITE], "illuminance_lux", 10);
if ($facadeLuxMoyen == 0)
$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)
{
$facadeLuxMoyen = $facade_lux;
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
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 = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
if ($rafale == 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__);
}
// 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;
$rafale = $indexDevices[METEO]->properties["windgustkmh"]["value"];
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
}
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
switch ($property)
if (array_key_exists("windspeedkmh", $indexDevices[METEO]->properties))
{
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;
}
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 )
if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50)
{
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($this->maxLevel, AUTO);
}else
{
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($store2level, AUTO);
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
}
}else
$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)
{
logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__);
$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;
}
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)
{
$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");
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 )
{
logger(DEBUG, "store2level > maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($this->maxLevel, AUTO);
}else
{
logger(DEBUG, "store2level <= maxLevel", __FILE__ . ":" . __LINE__);
$this->setTo($store2level, AUTO);
}
}else
{
logger(DEBUG, _("Store is Moving ") . $moving, __FILE__ . ":" . __LINE__);
}
}
private function setTo($level, $method)
@ -257,6 +254,8 @@ 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,9 +9,7 @@ class rdc_temperature_int_ext extends hook
protected $devicelist = array(
METEO => "tempc",
//RDC_CHAMBRE_TEMPERATURE => "temperature",
//RDC_SALON_TEMPERATURE => "temperature"
METEO=> "tempc",
);
protected $portesList = array(
@ -29,7 +27,7 @@ class rdc_temperature_int_ext extends hook
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $property, $value)
{
global $indexDevices, $scripts;
global $indexDevices, $hooks;
static $time;
$portes = array();
$status = -1;
@ -43,61 +41,57 @@ class rdc_temperature_int_ext extends hook
if ((now()->format("U") - $time->format("U")) > 300)
{
if ($property == "tempc")
$indoorTemp = $device->properties["indoortempc"]["value"];
if ( $value > $indoorTemp)
{
$indoorTemp = $device->properties["indoortempc"]["value"];
if ( $value > $indoorTemp)
if( ($indoorTemp <= $this->tempSup) and empty($portes))
{
if( ($indoorTemp <= $this->tempSup) and empty($portes))
{
$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 )
$status = 1;
//logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif($indoorTemp >= $this -> tempSup and ! empty($portes))
{
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);
$status = 0;
//logger(ALERT, _("Close doors to climate"), null, $device);
}
//print_r($portes);
if ($status == 1)
}elseif ( $value < $indoorTemp )
{
if (($indoorTemp >= $this->tempSup) and empty($portes) )
{
$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
$status = 1;
//logger(ALERT, _("Open doors to climate"), null ,$device);
}elseif ($indoorTemp <= $this->tempSup)
{
$portes = $scripts["test_portes"]->testPortes($this->portesList, false, true);
if (!empty($portes))
$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)
{
$time = now();
foreach($portes as $porte)
{
$msg .= $porte . "\n";
}
logger(ALERT, _("Close doors to climate\n") . $msg, null, $device);
$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)
{
$msg .= $porte . "\n";
}
logger(ALERT, _("Close doors to climate\n") . $msg, null, $device);
}
}
}

View File

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

View File

@ -1,17 +1,14 @@
<?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;
@ -31,8 +28,6 @@ if ($testMode)
}
require $configDir . "/config.php";
require $configDir . "/liste_telephones.php";
$listProperties = array("powerSource" => "batterie");
$listPropertiesKeys = array("expose");
@ -47,8 +42,6 @@ $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
@ -65,9 +58,10 @@ $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
@ -77,10 +71,6 @@ system("sudo /usr/bin/systemctl restart presenceD.service");
bindtextdomain("moha", "./locale");
textdomain("moha");
######################################################################################################################
## Fonctions ##
######################################################################################################################
function notify($message, $device)
{
global $notificationMethods, $defaultUser;
@ -202,9 +192,10 @@ function endMoha()
logger(ERROR, _("Can not store events db" ), __FILE__ . ":" . __LINE__);
}
if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true));
configWatchStop();
// stop la surveillance
inotify_rm_watch($cwfd, $watch_descriptor);
// Destruction de l'instance inotify
fclose($cwfd);
if ($connected)
{
$mid = $client->unsubscribe("#");
@ -228,12 +219,9 @@ 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"))
@ -259,6 +247,9 @@ 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"))
@ -272,7 +263,6 @@ if (file_exists($dataPath . "events.db"))
}
}
// topics definition
listHooks("./topics_callbacks", $topicsCallbacks);
if (!empty($topicsCallbacks))
@ -300,17 +290,6 @@ 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"))
{
@ -342,6 +321,8 @@ if (file_exists($dataPath . "devices.db"))
}
}
// Program start
logger(DEBUG, _("Program start"), __FILE__ . ":" . __LINE__);
$client = new Mosquitto\Client();
@ -385,27 +366,16 @@ 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 all hooks may not be initialized
if ($oneshot === false) // execute while the first loop :WARNING hooks can to be not initialized
{
echo date("c") . " One shot";
logger(DEBUG, _("Oneshot part of loop"), __FILE__ . ":" . __LINE__, false);
pws2mqttGetList();
$oneshot = true;
}
//echo date("c") . " initialisation des hooks";
$nn = 0;
if($hooksInitialized == 0) // all hooks are not initialized
{
$i = 1;
@ -424,21 +394,18 @@ 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 may be not finished
$flagHooks = true;
}else // executed when hooks initialization finished but database init 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)
{
@ -453,12 +420,13 @@ while (true)
include $configDir . "/" . $event["name"];
}else
{
logger(DEBUG, _("configWatch : mauvaise extension, je n'inclus pas ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
logger(DEBUG, _("configWatch : mauvaise extension, n'inclus pas ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__);
}
}
}
}
//echo date("c") . " fin";
//presence();
}
endMoha();

View File

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

View File

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

View File

@ -17,14 +17,7 @@ chown domotique:domotique -R /var/log/moha.log
# GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
systemctl daemon-reload
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
systemctl enable presenceD.service
systemctl enable moha.service
#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);