enabled) public $timer = 0; public $rafales = 0; public $luminosite = 0; public $luminosite_ext = 0; public $luminance_min = 60; public $luminance_max = 3000; protected $devicelist = array( RDC_EXTERIEUR_LUMINOSITE => array("illuminance_lux", false), // "ON"/"OFF" METEO => array("rainin", false), METEO => array("solarradiation", false), METEO => array("windspeedkmh", false), METEO => array("windgustkmh", false) ); // 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) { global $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 }*/ ?>