1
0

added some javascript to webserver\nsome debugging

This commit is contained in:
2022-03-06 01:30:33 +01:00
parent a2d2909a23
commit 9dde1c2d53
13 changed files with 230 additions and 179 deletions

View File

@ -44,7 +44,7 @@ class rdc_chambre_eclairage extends hook
private function send($deviceObject, $property, $state, $delayState = false, $method = MANUAL)
{
global $devices, $indexDevices;
global $indexDevices;
$msg = array($property => $state);
if ($deviceObject->properties[$property]["value"] != $state)
{

View File

@ -1,20 +1,20 @@
<?php
class rdc_chambre_eclairage extends hook
class rdc_store extends hook
{
public $hookName = "rdc_store";
public $active = true; //enable/disable hook (true => enabled)
public $timer = 0;
public $rafales = 0;
public $luminosite = 0;
public $luminosite_ext = 0;
public $luminance_min = 60;
public $luminance_max = 3000;
public $storeDownTime = 20;
public $storeUpTime = 25;
protected $storeLevel;
protected $devicelist = array(
RDC_EXTERIEUR_LUMINOSITE => array("illuminance_lux", false), // "ON"/"OFF"
METEO => array("rainin", false),
METEO => array("solarradiation", false),
//METEO => array("solarradiation", false),
METEO => array("windspeedkmh", false),
METEO => array("windgustkmh", false)
);
@ -25,114 +25,102 @@ class rdc_chambre_eclairage extends hook
// $value -> value of the property
public function callBack($device, $property, $value)
{
global $devices, $indexDevices;
global $mohaDB, $devices, $indexDevices;
/*
nowf = now.month*100+now.day
if ( nowf > 501 and nowf< 1015 ) then
storeLevel = dz.devices(398).level
print("storelevel => " .. storeLevel)
if (dz.data.timer ~= 0) then
timer = dz.time.compare(dz.data.timer).mins
if ( timer > 5) then
dz.data.timer = 0
end
print ("timer =" .. timer)
end
exterieur_lux = dz.devices(113).nValue
storeId = 398
--print(inspect({dz.data}))
store = dz.devices(storeId)
pluie = dz.devices(108).rainRate
dz.data.rafales.add( tonumber(dz.devices(116).sValue) )
rafale = dz.data.rafales.avg()
luminosite_inst = dz.devices(322).nValue
dz.data.luminosite.add( luminosite_inst )
luminosite = dz.data.luminosite.avg()
soleil = dz.devices(113).nValue
rndRafale = math.floor(rafale/2)
print ("luminosité " .. luminosite)
print ("rafale = " .. rafale .." => rndrafale =" .. rndRafale)
--print ("soleil".. soleil)
if (rndRafale >6) then
maxLevel = 0
else
maxLevel = dz.data.stoLevelMax[rndRafale]
end
print( "pluie => " .. tostring(pluie))
print("maxLevel =>" .. maxLevel)
datetime = Time()
----------------- fonctions -----------------------------
open = function( storeId, level)
--print(inspect({dz.devices(storeId)}))
print (storeLevel,level)
if ( storeLevel < level ) then
dz.data.timer = Time()
dz.devices(storeId).dimTo(level)
--dz.data.storeLevel = level
print ( "store to =>" .. tostring(level) )
dz.notify("Store","Store à " .. tostring(level) .. "%")
end
end
close = function( storeId, raison )
if ( dz.devices(storeId).level ~= 0 ) then -- and not dz.devices(storeId).active
dz.devices(storeId).open()
dz.data.storeLevel = 0
print ( "store fermé " .. raison)
dz.notify("Store","Store fermé car " .. raison)
end
end
wait = function(time)
if tonumber(time) ~= nil then
os.execute("sleep "..tonumber(time))
else
os.execute("sleep "..tonumber("0.1"))
end
end
-------------------------------------- programme principal --------------------------------------
if ( datetime.matchesRule("between sunrise and sunset" ) ) then
if ( luminosite > 30000) then
if ( pluie == 0 and maxLevel ~=0 ) then
store2Level = storeLevel+15
if ( store2Level > maxLevel ) then
print( "level => " .. maxLevel)
open(storeId, maxLevel)
else --if (storeLevel ~= store2Level ) then
print( "level => " .. store2Level)
open( storeId, store2Level )
end
end
elseif ( storeLevel ~= 0 ) then
if (luminosite < 25000 and dz.data.timer == 0) then
print ("luminosité faible")
close( storeId, "luminosité faible" )
end
end
end
if (storeLevel ~= 0) then
-- pluie
if (pluie ~= 0) then
close(storeId, "il pleut")
-- rafale
elseif (rndRafale >= 7) then
close(storeId, "il y a des rafales de vent")
-- radiation solaires
elseif ( (soleil < 300 and luminosite < 30000) and dz.data.timer == 0 ) then
close(storeId , "il n'y a plus de soleil")
end
end
end
end
}*/
$storeDevice = $indexDevices[RDC_STORE];
$storeLevel = $storeDevice->properties["position"];
$exterieur_lux = $mohaDB->moyenne($indexDevices[RDC_EXTERIEUR_LUMINOSITE], "illuminance_lux", 15);
$rain = $indexDevices[METEO]->properties["rainin"];
$rafale = $mohaDB->moyenne($indexDevices[METEO], "windgustkmh", 12);
$soleil = $mohaDB->moyenne($indexDevices[METEO], "solarradiation", 12);
if ($rafale >= 6 or $rain != 0)
{
$maxLevel = 0;
}else
{
$maxLevel = 100 / $rafale;
}
switch ($property)
{
case "illuminance_lux":
if ($exterieur_lux > 3000)
{
if ($rain == 0 and $maxLevel != 0)
{
$store2level = storeLevel + 15;
if ( $store2level > $maxLevel )
{
$this->open($maxLevel);
}else
{
$this->open($max2level);
}
}
}elseif ($exterieur_lux < 25000)
{
$this->close("Luminosité faible");
}
break;
case "rainin":
$this->close("Pluie");
break;
case "windgustkmh";
case "windspeedkmh":
if($value > 50)
{
$this->close("Trop de vent");
}elseif ($value > 40 and $level > 20)
{
$this->maxLevel = 20;
$this->send(20);
}elseif ($value > 30 and $level > 40)
{
$this->maxLevel = 40;
$this->send(40);
}elseif ($value >20 and $level > 60)
{
$this->maxLevel = 60;
$this->send(60);
}elseif ($value >10 and $level > 80)
{
$this->maxLevel = 80;
$this->send(80);
}else
{
$this->maxLevel = 100;
}
$this->close("Fortes rafales de vent");
break;
}
}
private function open ($level)
{
if ($this->storeLevel < $level)
{
$this->send($level);
}
}
private function close ($reason)
{
if ($this->storeLevel != 0)
{
print ( "store fermé " . $reason);
}
}
private function send($level)
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_STORE];
$msg = array("position" => $level);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set();
$deviceObject->method = AUTO;
}
}
$hooks["rdc_store"] = new rdc_store();
?>