1
0

- changed webserver to apiserver

- added webserver
- a lot of debugging
- install shell script
This commit is contained in:
2022-04-07 01:44:17 +02:00
parent 0d35b1ff3f
commit f8fc3f63ec
28 changed files with 463 additions and 223 deletions

View File

@ -122,7 +122,7 @@ class radiateurs extends hook
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
$device->payload = $msg;
$device->set();
$device->method = AUTO;
$device->properties["current_heating_setpoint"]["method"] = AUTO;
}
}
}

View File

@ -12,7 +12,8 @@ class rdc_chambre_eclairage extends hook
RDC_CHAMBRE_AMBIANCE => "state", // "ON"/"OFF"
RDC_CHAMBRE_ECLAIRAGE => "state_l1", // "ON"/"OFF"
RDC_CHAMBRE_MVMT => "occupancy",
RDC_CHAMBRE_ARMOIRE_GAUCHE => "contact"
RDC_CHAMBRE_ARMOIRE_GAUCHE => "contact",
RDC_CHAMBRE_AMBIANCE_INTER => "action"
);
// callback fonction. Is called with these 3 parameters
@ -26,19 +27,44 @@ class rdc_chambre_eclairage extends hook
$lux = $indexDevices[RDC_CHAMBRE_LUMINOSITE]->properties["illuminance_lux"];
$targetAmbiance = $indexDevices[RDC_CHAMBRE_AMBIANCE];
$targetEclairage = $indexDevices[RDC_CHAMBRE_ECLAIRAGE];
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
if ($property == "occupancy" and $value == ON)
{
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
$this->send($targetAmbiance, "state", "ON", "OFF", AUTO);
if ($targetAmbiance->properties["state"]["method"] == MANUAL)
{
$method = false;
$delayState = false;
}else
{
$method = AUTO;
$delayState = "OFF";
}
$this->send($targetAmbiance, "state", "ON", $delayState, $method);
}elseif ($property == "contact")
{
if ($value == false)
logger(DEBUG, _("CASE: contact"), __FILE__ . ":" . __LINE__);
if ($value === false)
{
$this->send($targetEclairage, "state_l1", "ON", "OFF", AUTO);
}elseif ($value == true)
}elseif ($value === true)
{
$this->send($targetEclairage, "state_l1", "OFF", false, null);
$this->send($targetEclairage, "state_l1", "OFF", false, IDLE);
}
}elseif ($property == "state" and $value == "OFF")
{
logger(DEBUG, _("CASE: state => value = 'OFF'"), __FILE__ . ":" . __LINE__);
$targetAmbiance->properties[$property]["method"] = IDLE;
}elseif ($property == "state_l1" and $value == "OFF")
{
logger(DEBUG, _("CASE: state_l1 => value = 'OFF'"), __FILE__ . ":" . __LINE__);
$targetEclairage->properties[$property]["method"] = IDLE;
}elseif ($property == "action")
{
logger(DEBUG, _("CASE: action"), __FILE__ . ":" . __LINE__);
if ($targetAmbiance->properties[$property]["method"] == IDLE)
{
$targetAmbiance->properties[$property]["method"] == MANUAL;
}
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
@ -53,7 +79,7 @@ class rdc_chambre_eclairage extends hook
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set();
$deviceObject->method = $method;
$deviceObject->properties[$property]["method"] = $method;
///}else
/*{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);

View File

@ -49,19 +49,19 @@ class rdc_salon_eclairage extends hook
if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
{
logger(INFO, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
//$this->send($deviceTarget, "ON", "OFF", AUTO);
//setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
$this->send($deviceTarget, "OFF", false, IDLE);
}
}
break;
case "contact":
logger(INFO, _("CASE: Contact Door"), __FILE__ . ":" . __LINE__);
if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min and getValue($deviceTarget->ieeeAddress, "state") == "OFF")
if ($value == false and getValue(RDC_SALON_LUMINOSITE, "illuminance_lux") <= $this->luminance_min)
{
logger(INFO, _("Door is open and illumance < min"), __FILE__ . ":" . __LINE__);
if (getValue(RDC_SALON_MVMT, "occupancy") == ON or getValue(RDC_SALON_MVMT2, "occupancy") == ON)
if ($deviceTarget->properties["state"]["method"] !== MANUAL)
{
$this->send($deviceTarget, "ON", false, AUTO);
$this->send($deviceTarget, "ON", false);
}else
{
$this->send($deviceTarget, "ON", "OFF", AUTO);
@ -70,20 +70,20 @@ class rdc_salon_eclairage extends hook
break;
case "illuminance_lux":
logger(INFO, _("CASE : Illuminance"), __FILE__ . ":" . __LINE__);
if ($value >= $this->luminance_max)
if ($value >= $this->luminance_max and $deviceTarget->properties["state"]["value"] == "ON")
{
logger(INFO, _("illuminace is > to max"), __FILE__ . ":" . __LINE__);
//$this->send($deviceTarget, "OFF", null, AUTO);
//removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF");
if (searchEvent($deviceTarget, "state", "OFF") === false)
{
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true);
setDelay($deviceTarget, $this->delay, $this->timeUnit, "state", "OFF", true, IDLE);
}
}elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON || getValue(RDC_SALON_MVMT2,"occupancy") == ON))
}/*elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON || getValue(RDC_SALON_MVMT2,"occupancy") == ON))
{
logger(INFO, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "ON", false, AUTO);
}
}*/
break;
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $param, bool2string($value)), __FILE__ . ":" . __LINE__);
@ -99,7 +99,7 @@ class rdc_salon_eclairage extends hook
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);
$deviceTarget->payload = $msg;
$deviceTarget->set();
$deviceTarget->method = $method;
$deviceTarget->properties["state"]["method"] = $method;
/*}else
{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $deviceTarget->friendlyName), __FILE__ . ":" . __LINE__);

View File

@ -28,40 +28,47 @@ class rdc_sdb_eclairage extends hook
{
global $indexDevices;
//var_dump($value);
$deviceTarget = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
switch($property)
$deviceTarget = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
if ($deviceTarget !== null)
{
case "occupancy":
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($value == ON )
{
$this->send("ON");
$device->method = AUTO;
}
break;
case "state_l1":
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($device->method != MANUAL)
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
switch($property)
{
case "occupancy":
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($value == ON )
{
$delay = $this->delay;
$device->method = AUTO;
}else
{
$delay = $this->delayManual;
$device->method = MANUAL;
$this->send("ON");
$deviceTarget->properties["state_l1"]["method"] = AUTO;
}
setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true);
}elseif ($value == "OFF")
{
removeEvent($deviceTarget, "state_l1", "OFF");
$device->method = null;
}
break;
break;
case "state_l1":
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($deviceTarget->properties["state_l1"]["method"] != MANUAL)
{
$delay = $this->delay;
$deviceTarget->properties["state_l1"]["method"] = AUTO;
}else
{
$delay = $this->delayManual;
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
}
setDelay($deviceTarget, $delay, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}elseif ($value == "OFF")
{
removeEvent($deviceTarget, "state_l1", "OFF");
$deviceTarget->properties["state_l1"]["method"] = IDLE;
}
break;
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, ($value == 0 ? "OFF" : "ON")), __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"), $this->hookName, $device->friendlyName, $property, ($value == 0 ? "OFF" : "ON")), __FILE__ . ":" . __LINE__);
}
private function send($state)

View File

@ -35,6 +35,8 @@ class rdc_store extends hook
$rafale = 0;
$soleil = 0;
$storeDevice = $indexDevices[RDC_STORE];
$maxLevel = 100;
$r = 100;
if (array_key_exists("position", $storeDevice->properties))
{
@ -131,10 +133,10 @@ class rdc_store extends hook
break;
default:
}
if ($store2level <= $this->storeLevel)
/*if ($store2level <= $this->storeLevel)
{
$this->set($store2level);
}
}*/
}
private function set ($level)

View File

@ -9,7 +9,7 @@ class rdc_wc_eclairage extends hook
RDC_WC_MVMT => "occupancy"
);
public $delay = 3; // amount of time in $timeunit
public $delay = 5; // amount of time in $timeunit
public $delayManual = 15; // amount of time in $timeunit for manual mode
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
@ -17,7 +17,8 @@ class rdc_wc_eclairage extends hook
public function callBack(&$device, $property, $value)
{
global $indexDevices;
//var_dump($value);
$targetDevice = &$indexDevices[RDC_SDB_WC_ECLAIRAGE]; //var_dump($value);
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
switch($property)
{
@ -25,38 +26,39 @@ class rdc_wc_eclairage extends hook
logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($device->method == AUTO)
if ($targetDevice->properties["state_l1"]["method"] !== AUTO)
{
setDelay($device, $this->delay, $this->timeUnit, "state_l2", "OFF", true);
}else
{
$device->method = MANUAL;
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
$targetDevice->properties["state_l1"]["method"] = MANUAL;
//setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
}
}elseif ($value == "OFF")
{
removeEvent($device, "state_l2", "OFF");
$device->method = null;
removeEvent($device, "state_l2", "OFF", IDLE);
}
break;
case "occupancy":
logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
if ($value == true)
{
$device->method = AUTO;
$this->send("ON");
$targetDevice->properties["state_l2"]["method"] = AUTO;
//setDelay($device, $this->delay, $this->timeUnit, "state_l2", "OFF", true,IDLE);
$this->send($targetDevice, "ON");
}elseif ($targetDevice->properties["state_l2"]["method"] != MANUAL)
{
$targetDevice->properties["state_l2"]["method"] = IDLE;
$this->send($targetDevice, "OFF");
}
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
}
private function send($state)
private function send($targetDevice, $state)
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
$msg = array("state_l2" => $state);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set(null);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $targetDevice->friendlyName), __FILE__ . ":" . __LINE__);
$targetDevice->payload = $msg;
$targetDevice->set(null);
}
}