1
0
This commit is contained in:
Daniel Tartavel 2022-09-05 13:47:41 +02:00
parent 0c9f8f8c3f
commit 4acb2992ca
15 changed files with 82 additions and 53 deletions

View File

@ -37,6 +37,7 @@ class device
public $triggerDevice; public $triggerDevice;
public $properties = array(); public $properties = array();
public $lastSeen; public $lastSeen;
public $users2notify = array();
public function __construct() public function __construct()
{ {
@ -141,7 +142,7 @@ class watch
{ {
logger(DEBUG, _("notifyCallback")); logger(DEBUG, _("notifyCallback"));
$msg = sprintf(_("Device '%s' have property '%s' value %s %s %s"), $device->friendlyName, $property, bool2string($value), $this->condition, bool2string($this->PropertyValue) ); $msg = sprintf(_("Device '%s' have property '%s' value %s %s %s"), $device->friendlyName, $property, bool2string($value), $this->condition, bool2string($this->PropertyValue) );
notify($msg); notify($msg, $device);
} }
} }
} }

View File

@ -51,6 +51,7 @@ $deviceTable = array(
"0x04cf8cdf3c7b6056" => "RDC_CHAMBRE_LUMINOSITE", "0x04cf8cdf3c7b6056" => "RDC_CHAMBRE_LUMINOSITE",
"0x00158d0006c0447c" => "RDC_CHAMBRE_ARMOIRE_GAUCHE", "0x00158d0006c0447c" => "RDC_CHAMBRE_ARMOIRE_GAUCHE",
"0x842e14fffe9be0fc" => "RDC_STORE", "0x842e14fffe9be0fc" => "RDC_STORE",
"0xa4c138165e31c0e8" => "RDC_STORE_VIBRATION",
"0x04cf8cdf3c7b3d64" => "RDC_EXTERIEUR_LUMINOSITE", "0x04cf8cdf3c7b3d64" => "RDC_EXTERIEUR_LUMINOSITE",
"0x483fda53cbcb" => "METEO" "0x483fda53cbcb" => "METEO"
); );

View File

@ -1,9 +1,10 @@
<?php <?php
$macAddresses = array( $macAddresses = array(
"Daniel" => "E8:78:29:C2:79:22", "E8:78:29:C2:79:22" => "Daniel",
"Maryclaire" => "D0:9C:7A:DA:8E:D8", "D0:9C:7A:DA:8E:D8" => "Maryclaire",
"Terence" => "26:4D:40:5F:1E:10" "FA:61:B1:D8:3C:D4" => "Maryclaire",
"26:4D:40:5F:1E:10" => "Terence"
); );
?> ?>

View File

@ -36,6 +36,7 @@ $properties2log = array(
"indoortempc" => 0.5, "indoortempc" => 0.5,
"indoorhumidity" => 0.5, "indoorhumidity" => 0.5,
"baromin" => 10, "baromin" => 10,
"presence" => null "presence" => null,
"vibration" => null
); );

11
config/users.php Normal file
View File

@ -0,0 +1,11 @@
<?php
$users = array(
"Daniel",
"Maryclaire",
"Terence"
)
?>

View File

@ -17,7 +17,7 @@ $command = "sudo nmap -n -sP 192.168.1.*"; //need to configure /etc/sudo/sudoer
echo "presenceDaemon is starting\n"; echo "presenceDaemon is starting\n";
// init du tableau des présences à -1 // init du tableau des présences à -1
foreach($macAddresses as $nom => $mac) foreach($macAddresses as $mac => $nom)
{ {
$presence[$nom] = -1; $presence[$nom] = -1;
} }
@ -46,6 +46,7 @@ while (1)
echo $nom . " est modifié dans tableau\n"; echo $nom . " est modifié dans tableau\n";
} }
} }
$result = array();
sleep(1); sleep(1);
} }
@ -53,7 +54,7 @@ function search($string)
{ {
global $macAddresses, $presenceTemp; global $macAddresses, $presenceTemp;
//echo "searching in " . $string . EOL; //echo "searching in " . $string . EOL;
foreach ($macAddresses as $nom => $needle) foreach ($macAddresses as $needle => $nom)
{ {
//echo $nom ." => " . $needle . EOL; //echo $nom ." => " . $needle . EOL;
if (str_contains($string, $needle)) if (str_contains($string, $needle))

View File

@ -9,7 +9,7 @@ class notificationFreemobile
public $lastTry; public $lastTry;
public $lastTryTimeout = 5; public $lastTryTimeout = 5;
protected $dest = array( protected $dest = array(
"daniel" => "15480189&pass=yVpPmCWmUl2HGp", "Daniel" => "15480189&pass=yVpPmCWmUl2HGp",
); );
function __construct() function __construct()
@ -27,7 +27,7 @@ class notificationFreemobile
curl_setopt($ch, CURLOPT_URL, $this->url . $this->dest[$destinataire] . "&msg=" . urlencode(trim($message))); curl_setopt($ch, CURLOPT_URL, $this->url . $this->dest[$destinataire] . "&msg=" . urlencode(trim($message)));
// return the transfer as a string // return the transfer as a string
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $result contains the output string // $result contains the output string
if ($this->curlErr <= 5) if ($this->curlErr <= 5)
{ {

View File

@ -33,10 +33,10 @@ class alerte_intrusion extends hook
{ {
if ($value == false and isPresent() === false) if ($value == false and isPresent() === false)
{ {
logger(ALERT, sprintf(_("%s vient de s'ouvrir alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__); logger(ALERT, sprintf(_("%s vient de s'ouvrir alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__, $device);
}else }else
{ {
logger(ALERT, sprintf(_("%s vient de se fermer alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__); logger(ALERT, sprintf(_("%s vient de se fermer alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__, $device);
} }
} }
break; break;

View File

@ -11,10 +11,12 @@ class rdc_store extends hook
public $storeUpTime = 41; public $storeUpTime = 41;
public $maxLevel; public $maxLevel;
public $storeLevel; public $storeLevel;
public $motorReversal = false;
protected $propertyInitialized =array(); protected $propertyInitialized =array();
protected $devicelist = array( protected $devicelist = array(
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
RDC_SALON_LUMINOSITE => "illuminance_lux", RDC_SALON_LUMINOSITE => "illuminance_lux",
RDC_STORE_VIBRATION => "vibration",
METEO => "rainin", METEO => "rainin",
METEO => "solarradiation", METEO => "solarradiation",
METEO => "windspeedkmh", METEO => "windspeedkmh",
@ -46,7 +48,6 @@ class rdc_store extends hook
//$this->maxLevel = 100; //$this->maxLevel = 100;
$r = 100; $r = 100;
$moving = "STOP"; $moving = "STOP";
$motorReversal = false;
$store2level = false; $store2level = false;
if (array_key_exists("moving", $storeDevice->properties)) if (array_key_exists("moving", $storeDevice->properties))
@ -58,19 +59,19 @@ class rdc_store extends hook
{ {
if ($storeDevice->properties["motor_reversal"]["value"] == "ON") if ($storeDevice->properties["motor_reversal"]["value"] == "ON")
{ {
$motorReversal = true; $this->motorReversal = true;
}else }else
{ {
$motorReversal = false; $this->motorReversal = false;
} }
logger(DEBUG, "Motor reversal =" . bool2string($motorReversal), __FILE__ . ":" . __LINE__); logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__);
} }
if ($moving == "STOP") if ($moving == "STOP" or $moving == null)
{ {
if (array_key_exists("position", $storeDevice->properties)) if (array_key_exists("position", $storeDevice->properties))
{ {
if ($motorReversal) if ($this->motorReversal)
{ {
$this->storeLevel = $storeDevice->properties["position"]["value"]; $this->storeLevel = $storeDevice->properties["position"]["value"];
}else }else
@ -97,7 +98,7 @@ class rdc_store extends hook
{ {
if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50) if ($indexDevices[METEO]->properties["windgustkmh"]["value"] > 50)
{ {
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__); logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windgustkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
} }
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6); $rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 6);
if ($rafale == 0) if ($rafale == 0)
@ -110,7 +111,7 @@ class rdc_store extends hook
{ {
if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50) if ($indexDevices[METEO]->properties["windspeedkmh"]["value"] > 50)
{ {
logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__); logger(ALERT, "Vent fort :" . $indexDevices[METEO]->properties["windspeedkmh"]["value"], __FILE__ . ":" . __LINE__, $device);
} }
$vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6); $vent = $mohaDB->moyenne($indexDevices[METEO], "windspeedkmh", 6);
if ($vent == 0) if ($vent == 0)
@ -154,7 +155,7 @@ class rdc_store extends hook
logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__);
if ($this->maxLevel != 0 and $salon_lux > 100) if ($this->maxLevel != 0 and $salon_lux > 100)
{ {
$store2level = $this->storeLevel + 15; $store2level = $this->storeLevel + 20;
} }
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100) }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100)
{ {
@ -174,13 +175,7 @@ class rdc_store extends hook
//calcul du maxlevel par rapport a la vitesse des rafales //calcul du maxlevel par rapport a la vitesse des rafales
$r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10; $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10;
if ($r < 0) $r = 0; if ($r < 0) $r = 0;
if ($motorReversal)
{
$this->maxLevel = $r;
}else
{
$this->maxLevel = 100 - $r; $this->maxLevel = 100 - $r;
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
} }
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
@ -191,9 +186,15 @@ class rdc_store extends hook
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
$this->close("Pluie"); $this->close("Pluie");
break; break;
case "windgustkmh"; case "windgustkmh":
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
break; break;
case "vibration":
$tmpStore = $this->storeLevel - 20;
if ($store2level == false or $store2level > $tmpStore)
{
$this->setTo($store2level, AUTO);
}
default: default:
} }
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
@ -222,10 +223,14 @@ class rdc_store extends hook
private function setTo($level, $method) private function setTo($level, $method)
{ {
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
if (!$this->motorReversal)
{
$level = 100 - $level;
}
if ($level <= 100) if ($level <= 100)
{ {
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
$this->send(100 - $level, $method); $this->send($level, $method);
}//else }//else
/*{ /*{
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);

View File

@ -11,10 +11,12 @@ class rdc_store extends hook
public $storeUpTime = 41; public $storeUpTime = 41;
public $maxLevel; public $maxLevel;
public $storeLevel; public $storeLevel;
public $motorReversal = false;
protected $propertyInitialized =array(); protected $propertyInitialized =array();
protected $devicelist = array( protected $devicelist = array(
RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux", RDC_EXTERIEUR_LUMINOSITE => "illuminance_lux",
RDC_SALON_LUMINOSITE => "illuminance_lux", RDC_SALON_LUMINOSITE => "illuminance_lux",
RDC_STORE_VIBRATION => "vibration",
METEO => "rainin", METEO => "rainin",
METEO => "solarradiation", METEO => "solarradiation",
METEO => "windspeedkmh", METEO => "windspeedkmh",
@ -46,7 +48,6 @@ class rdc_store extends hook
//$this->maxLevel = 100; //$this->maxLevel = 100;
$r = 100; $r = 100;
$moving = "STOP"; $moving = "STOP";
$motorReversal = false;
$store2level = false; $store2level = false;
if (array_key_exists("moving", $storeDevice->properties)) if (array_key_exists("moving", $storeDevice->properties))
@ -58,19 +59,19 @@ class rdc_store extends hook
{ {
if ($storeDevice->properties["motor_reversal"]["value"] == "ON") if ($storeDevice->properties["motor_reversal"]["value"] == "ON")
{ {
$motorReversal = true; $this->motorReversal = true;
}else }else
{ {
$motorReversal = false; $this->motorReversal = false;
} }
logger(DEBUG, "Motor reversal =" . bool2string($motorReversal), __FILE__ . ":" . __LINE__); logger(DEBUG, "Motor reversal =" . bool2string($this->motorReversal), __FILE__ . ":" . __LINE__);
} }
if ($moving == "STOP") if ($moving == "STOP" or $moving == null)
{ {
if (array_key_exists("position", $storeDevice->properties)) if (array_key_exists("position", $storeDevice->properties))
{ {
if ($motorReversal) if ($this->motorReversal)
{ {
$this->storeLevel = $storeDevice->properties["position"]["value"]; $this->storeLevel = $storeDevice->properties["position"]["value"];
}else }else
@ -154,11 +155,11 @@ class rdc_store extends hook
logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__); logger(DEBUG, "exterieur_lux > 33000 or salon_lux >600", __FILE__ . ":" . __LINE__);
if ($this->maxLevel != 0 and $salon_lux > 100) if ($this->maxLevel != 0 and $salon_lux > 100)
{ {
$store2level = $this->storeLevel + 15; $store2level = $this->storeLevel + 20;
} }
}elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 100 and $soleil < 100) }elseif ($exterieurLuxMoyen < 5000 and $salon_lux < 200 and $soleil < 100)
{ {
logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 100 and soleil < 100", __FILE__ . ":" . __LINE__); logger(DEBUG, "exterieurLuxMoyen < 5000 and salon_lux < 200 and soleil < 100", __FILE__ . ":" . __LINE__);
$this->close("Luminosité faible"); $this->close("Luminosité faible");
} }
@ -174,13 +175,7 @@ class rdc_store extends hook
//calcul du maxlevel par rapport a la vitesse des rafales //calcul du maxlevel par rapport a la vitesse des rafales
$r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10; $r = round(($rafale-20)/4, 0, PHP_ROUND_HALF_UP)*10;
if ($r < 0) $r = 0; if ($r < 0) $r = 0;
if ($motorReversal)
{
$this->maxLevel = $r;
}else
{
$this->maxLevel = 100 - $r; $this->maxLevel = 100 - $r;
}
logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__); logger(DEBUG, "rafale=" . $rafale, __FILE__ . ":" . __LINE__);
} }
logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__); logger(DEBUG, "maxlevel=" . $this->maxLevel, __FILE__ . ":" . __LINE__);
@ -191,9 +186,15 @@ class rdc_store extends hook
logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: rainin:" . $value, __FILE__ . ":" . __LINE__);
$this->close("Pluie"); $this->close("Pluie");
break; break;
case "windgustkmh"; case "windgustkmh":
logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__); logger(DEBUG, "CASE: windgustkmh:" . $rafale, __FILE__ . ":" . __LINE__);
break; break;
case "vibration":
$tmpStore = $this->storeLevel - 20;
if ($store2level == false or $store2level > $tmpStore)
{
$this->setTo($store2level, AUTO);
}
default: default:
} }
logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__); logger(DEBUG, "maxLevel = " . $this->maxLevel . ' result => $r = ' . $r, __FILE__ . ":" . __LINE__);
@ -222,10 +223,14 @@ class rdc_store extends hook
private function setTo($level, $method) private function setTo($level, $method)
{ {
logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "function 'set' to level : " . $level, __FILE__ . ":" . __LINE__);
if (!$this->motorReversal)
{
$level = 100 - $level;
}
if ($level <= 100) if ($level <= 100)
{ {
logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "Open store :" . $level, __FILE__ . ":" . __LINE__);
$this->send(100 - $level, $method); $this->send($level, $method);
}//else }//else
/*{ /*{
logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__); logger(DEBUG, "store is already at level" . $this->storeLevel . " so < at " . $level, __FILE__ . ":" . __LINE__);

View File

@ -1,6 +1,6 @@
<?php <?php
foreach($macAddresses as $nom => $mac) foreach($macAddresses as $mac => $nom)
{ {
$presence[$nom] = false; $presence[$nom] = false;
} }
@ -23,7 +23,7 @@ function presence($argList)
{ {
return _("Le paramètre 'presence' est obligatoire<br>present&nom=<nom>&presence=<true/false>") . EOLH; return _("Le paramètre 'presence' est obligatoire<br>present&nom=<nom>&presence=<true/false>") . EOLH;
} }
var_dump($presence); //var_dump($presence);
if (!array_key_exists($name, $presence)) if (!array_key_exists($name, $presence))
{ {
return sprintf(_("Ce nom (%s) n'existe pas dans la base."), $name) . EOLH; return sprintf(_("Ce nom (%s) n'existe pas dans la base."), $name) . EOLH;

View File

@ -5,7 +5,9 @@ if (!array_key_exists("pws2mqtt", $devices)) $devices["pws2mqtt"] = array();
function pws2mqttCallback($topic, $message) function pws2mqttCallback($topic, $message)
{ {
global $logFh, $devices, $included, $topics; global $logFh, $devices, $included, $topics;
$topicName = $topic[0]; $topicName = $topic[0];
$topics[$topicName]->lastSeen = time();
$fn = $topic[1]; $fn = $topic[1];
logger(INFO, sprintf(_("Incoming notification of device %s => friendly name : %s"), $topicName, $fn), __FILE__ . ":" . __LINE__); logger(INFO, sprintf(_("Incoming notification of device %s => friendly name : %s"), $topicName, $fn), __FILE__ . ":" . __LINE__);
$device = & $devices[$topicName]; $device = & $devices[$topicName];
@ -30,7 +32,6 @@ function pws2mqttCallback($topic, $message)
{ {
$device = &$device[$fn]; $device = &$device[$fn];
} }
$topics[$topicName]->lastSeen = time();
unset($payloadArray["friendly_name"]); unset($payloadArray["friendly_name"]);
unset($payloadArray["ieeeAddress"]); unset($payloadArray["ieeeAddress"]);
unset($payloadArray["type"]); unset($payloadArray["type"]);

View File

@ -7,6 +7,7 @@ function zigbee2mqttCallback($topic, $message)
{ {
global $topics, $devices, $included, $logFh, $indexFriendlyNames, $devicesRequest; global $topics, $devices, $included, $logFh, $indexFriendlyNames, $devicesRequest;
logger(DEBUG, _("CallBack Zigbee2mqtt"), __FILE__ . ":" . __LINE__);
$topics[$topic[0]]->lastSeen = time(); $topics[$topic[0]]->lastSeen = time();
if ($topic[1] == "bridge") if ($topic[1] == "bridge")
{ {

View File

@ -24,12 +24,13 @@ function checkTopicsAvailability()
{ {
if ($topic->status == 1) if ($topic->status == 1)
{ {
logger(DEBUG, "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 ((time() - $topic->lastSeen > $topic->timeOut*60) and ($topic->notificationSent == false))
{ {
if (logger(ALERT, $topicName . _(" is not available"), __FILE__ . ":" . __LINE__) == false); if (logger(ALERT, $topicName . _(" is not available"), __FILE__ . ":" . __LINE__) == false);
{ {
$topic->notificationSent = true; $topic->notificationSent = true;
//system("systemctl restart ")
} }
} }
} }