1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| --[[ %% autostart %% properties 110 value %% weather WeatherCondition %% events %% globals --]]
local sourceTrigger = fibaro:getSourceTrigger();
local graceTime = 4*60*60; -- Do not execute to often, wait this time in seconds before triggering again local temperatureLimit = 24 -- Temperature limit as lowest local maxOpening = 50 -- Max opening in percent local minOpening = 10 -- Min opened in percent local rollershutterId = 404 -- ID of roller blinds unit local temeratureSensorId = 405 -- ID of temerature sensor
-- Loop function function tempFunc() local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); local lastMovedTime = fibaro:getGlobal("AutoBlindsLastPos"); local diff = os.difftime(os.time(), lastMovedTime); --fibaro:debug("Diff since last position was set: " .. diff); --fibaro:debug("Temperature: " .. tonumber(fibaro:getValue(110, "value"))); --fibaro:debug("Weather: " .. api.get('/weather')['WeatherCondition'] ); if ( ( diff > graceTime ) and ( api.get('/weather')['WeatherCondition'] == "clear" ) and ( tonumber(fibaro:getValue(temeratureSensorId, "value")) >= temperatureLimit ) and ( (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "13", "00")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "21", "00"))) and (math.floor(os.time()/60)-math.floor(1565521200/60))%5 == 0 ) ) then local rndValue = math.random(minOpening,maxOpening); fibaro:debug(rndValue); fibaro:call(rollershutterId, "setValue", rndValue); fibaro:setGlobal("AutoBlindsLastPos", os.time()) end
setTimeout(tempFunc, 60*1000) end
if (sourceTrigger["type"] == "autostart") then tempFunc() else fibaro:debug("Running manually"); local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); if ( ( api.get('/weather')['WeatherCondition'] == "clear" or api.get('/weather')['WeatherCondition'] == "cloudy" ) and ( tonumber(fibaro:getValue(temeratureSensorId, "value")) >= temperatureLimit ) and ( (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "13", "00")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "21", "00"))) ) or startSource["type"] == "other" ) then local rndValue = math.random(minOpening,maxOpening); fibaro:debug(rndValue); fibaro:call(rollershutterId, "setValue", rndValue); fibaro:setGlobal("AutoBlindsLastPos", os.time()) end
end
|