{"name":"testVD","type":"virtual_device","properties":{"deviceIcon":239,"currentIcon":"0","log":"","logTemp":"","mainLoop":"vRun = 1 -- Set to 0 to disable VD\nsleepTime = 2*1000 -- 2 seconds sleep time\n\n-- START ALARMING OF MISSING WHEATHER SENSORS UPDATES\nfunction triggerUpdateFailed(duration)\n\tyourMobile = 356\n\tfibaro:setGlobal(\"pushoverBody\", \"wheather trigger missing for:\" ..duration ..\" min;;1;cosmic;WEATHER VD\")\n\tfibaro:call(yourMobile, \"sendPush\", 'wheather trigger missing for:' ..duration ..' min');\nend\n-- END ALARMING OF MISSING WHEATHER SENSORS UPDATES\n\n-- START PARAMETER CONVERSION, DEFINE HERE NEW TRANSLATION RULES\nfunction convertUnit(vConversion,vValue)\n\tlocal newValue\n\tif vConversion == \"c2f\" then\n\t\tnewValue = string.format(\"%.1f\",vValue * 9 / 5 + 32)\n\telseif vConversion == \"ms2mph\" then\n\t\tnewValue = string.format(\"%.1f\",vValue * 2.2369362920544)\n\telseif vConversion == \"ms2kmh\" then\n\t\tnewValue = string.format(\"%.1f\",vValue * 3.6)\n\telseif vConversion == \"hpa2inch\" then\n\t\tnewValue = string.format(\"%.4f\",(vValue/ math.pow((1-(0.0065*myConfig.Altitude)/(273.15+15)),5.255)) / 33.863886666667 )\n\telseif vConversion == \"mm2inch\" then\n\t\tnewValue = string.format(\"%.4f\",vValue * 0.0393701)\n\telseif vConversion == \"2dir\" then\n\t\tnewValue = string.format(\"%.1f\",vValue * 3.6)\n\telseif vConversion == \"2alt\" then\n\t\tnewValue = string.format(\"%.1f\",vValue / math.pow((1-(0.0065*myConfig.Altitude)/(273.15+15)),5.255))\n\telseif vConversion == \"2direction\" then\n\t\tif(tonumber(vValue) < 11.25/3.6) then newValue=\"Nord\"\n\t\t\telseif(tonumber(vValue) < 33.75/3.6) then newValue=\"Nordnordost\"\n\t\t\telseif(tonumber(vValue) < 56.25/3.6) then newValue=\"Nordost\"\n\t\t\telseif(tonumber(vValue) < 78.75/3.6) then newValue=\"Ostnordost\"\n\t\t\telseif(tonumber(vValue) < 101.25/3.6) then newValue=\"Ost\"\n\t\t\telseif(tonumber(vValue) < 123.75/3.6) then newValue=\"Ostsüdost\"\n\t\t\telseif(tonumber(vValue) < 146.25/3.6) then newValue=\"Südost\"\n\t\t\telseif(tonumber(vValue) < 168.75/3.6) then newValue=\"Südsüdost\"\n\t\t\telseif(tonumber(vValue) < 191.25/3.6) then newValue=\"Süd\"\n\t\t\telseif(tonumber(vValue) < 213.75/3.6) then newValue=\"Südsüdwest\"\n\t\t\telseif(tonumber(vValue) < 236.25/3.6) then newValue=\"Südwest\"\n\t\t\telseif(tonumber(vValue) < 258.75/3.6) then newValue=\"Westsüdwest\"\n\t\t\telseif(tonumber(vValue) < 281.25/3.6) then newValue=\"West\"\n\t\t\telseif(tonumber(vValue) < 303.75/3.6) then newValue=\"Westnordwest\"\n\t\t\telseif(tonumber(vValue) < 326.25/3.6) then newValue=\"Nordwest\"\n\t\t\telseif(tonumber(vValue) < 348.75/3.6) then newValue=\"Nordnordwest\"\n\t\t\telse\n\t\t\t\tnewValue=\"Nord\"\n\t\tend\n\telse \n\t newValue = string.format(\"%.1f\",vValue)\n\tend\nreturn newValue\nend\n-- END PARAMETER CONVERSION, DEFINE HERE NEW TRANSLATION RULES\n\n-- START ENDLESS LOOP, RUN every 20 seconds\nxID = fibaro:getSelfId()\nfibaro:debug('RUN')\n\nwhile vRun == 1 do\n if fibaro:getGlobal('WetterConfig_Test') ~= nil then\n \tif fibaro:getGlobalModificationTime('WetterConfig_Test') ~= lastUpdate then\n\t\t\t--START LOADING NEW CONFIGURATION\n \t\tlastUpdate = fibaro:getGlobalModificationTime('WetterConfig_Test')\n var= fibaro:getGlobal('WetterConfig_Test')\n myConfig = json.decode(var)\n\t\t\tvarSensor=fibaro:getGlobal('WetterSensors_Test')\n\t\t\tmySensors =json.decode(varSensor)\n\t\t\tvarReccords=fibaro:getGlobal('WetterRecords_Test')\n\t\t\tmyRecords =json.decode(varReccords)\t\t\t\n if myConfig.VD_ID ~= xID then\n myConfig.VD_ID = tonumber(xID)\n fibaro:debug('VD_ID stored in configuration')\n\t\t\t\txy=json.encode(myConfig)\n fibaro:setGlobal('WetterConfig_Test',xy)\n end \n \t\tif myConfig.Trigger_ID > 0 then\n lastTrigger = fibaro:getGlobalModificationTime(myConfig.Trigger_ID)\n lastCount = fibaro:getValue(tonumber(myConfig.Trigger_ID), 'value')\n currentCount = 0\n else\n lastTrigger = os.time()\n end\n cycleCounter = 0\n cycleUpdate = 0\n cycleAlarm = 0\n\t\t\tfor IndexS, Value in pairs( mySensors.WebService_Name) do\t\n\t\t\t\tmyConfig.WebService_Url[IndexS] =string.gsub(myConfig.WebService_Url[IndexS],'WebService_ID', myConfig.WebService_ID[IndexS])\n\t\t\t\tmyConfig.WebService_Url[IndexS] =string.gsub(myConfig.WebService_Url[IndexS],'WebService_Key', myConfig.WebService_Key[IndexS])\n\t\t\t\tmyConfig.WebService_UrlSuffix[IndexS] =string.gsub(myConfig.WebService_UrlSuffix[IndexS],'WebService_ID', myConfig.WebService_ID[IndexS])\n\t\t\t\tmyConfig.WebService_UrlSuffix[IndexS] =string.gsub(myConfig.WebService_UrlSuffix[IndexS],'WebService_Key', myConfig.WebService_Key[IndexS])\n\t\t\t\tmyConfig.WebService_UrlPrefix[IndexS] =string.gsub(myConfig.WebService_UrlPrefix[IndexS],'WebService_ID', myConfig.WebService_ID[IndexS])\n\t\t\t\tmyConfig.WebService_UrlPrefix[IndexS] =string.gsub(myConfig.WebService_UrlPrefix[IndexS],'WebService_Key', myConfig.WebService_Key[IndexS])\t\t\n\t\t\tend\n\t\t\t-- END LOADING NEW CONFIGURATION\t\n\t\t\t\n\t\t\t-- START CONFIGURATION VD LABELS\n if myConfig.Update == 1 then\n var= fibaro:getGlobal('WetterSensors')\n mySensors = json.decode(var)\n HC2 = Net.FHttp(\"localhost\", 80); \n HC2:setBasicAuthentication(myConfig.USER, myConfig.PWD);\n response, status, errorCode = HC2:GET(\"/api/virtualDevices/\" ..xID); \n jsonTable = json.decode(response)\n for i in pairs (jsonTable.properties.rows) do \n max = i \n \t\t\tif i > 2 then\n \tjsonTable.properties.rows[i].elements[1].caption = ''\n \t\tend\n end \n for i in pairs (mySensors.VD_Name) do\n if mySensors.VD_LBL[i] ~= nil then\n x = tonumber(mySensors.VD_LBL[i]) +2\n if x >0 and x < (max+1) then\n jsonTable.properties.rows[x].elements[1].caption = mySensors.VD_Name[i]\n end\n end\n end\n jsonTable.properties.rows[1].elements[1].caption = 'Update'\n myConfig.Update = 0\n xy=json.encode(myConfig)\n fibaro:setGlobal('WetterConfig_Test',xy)\n fibaro:debug('Disable VD label configuration for next run')\n fibaro:debug('VD_Labels update prepared')\n fibaro:debug('Reboot VD in 9 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 8 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 7 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 6 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 5 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 4 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 3 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 2 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 1 seconds')\t\t\n fibaro:sleep(1000) \n fibaro:debug('Reboot VD in 0 seconds')\t\t\n jsonBack = json.encode(jsonTable)\n response, status, errorCode = HC2:PUT(\"/api/virtualDevices/\" ..xID, jsonBack); \n end \n\t\t\t--START UPDATING VD CONFIGURATION\t\n\t\t\t\n fibaro:debug('Configuration up to date')\n\t end\n\t\t\t\t\t--START UPDATING CYCLE COUNTER WITH TIME OR DEVICE TRIGGER\t\n\t\t\t\t\tcycleUpdate=0\n\t\t\t\t\tif myConfig.Trigger_ID > 0 then\n\t\t\t\t\t\tif lastTrigger ~= fibaro:getGlobalModificationTime(myConfig.Trigger_ID) then\n\t\t\t\t\t\t\tcurrentCount = fibaro:getValue(tonumber(myConfig.Trigger_ID), 'value')\n\t\t\t\t\t\t\tif currentCount < lastCount then\n\t\t\t\t\t\t\t\tcycleCounter = cycleCounter + (currentCount + myConfig.Trigger_maxCount +1)-lastCount\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tcycleCounter = cycleCounter + currentCount -lastCount\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\tlastCount = currentCount\n\t\t\t\t\t\t\tlastTrigger = fibaro:getGlobalModificationTime(myConfig.Trigger_ID)\n\t\t\t\t\t\t\tcycleUpdate=1\n\t\t\t\t\t\tend\n\t\t\t\t\telse\n\t\t\t\t\t\t\tif os.time() >= lastTrigger + 60 then\n\t\t\t\t\t\t\t\tcycleCounter = cycleCounter + 1\n\t\t\t\t\t\t\t\tlastTrigger = lastTrigger + 60\t\n\t\t\t\t\t\t\t\tcycleUpdate=1\n\t\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\t\t--END UPDATING CYCLE COUNTER WITH TIME OR DEVICE TRIGGER\n\t\t\t\t\t\n\t\t\t\t\t-- START CHECK TRIGGER MISSING FOR TOO LONG\n\t\t\t\t\tif os.time() >=(lastTrigger + myConfig.Trigger_UpdateFailedAfter*60) and cycleAlarm == 0 then\n\t\t\t\t\t\tcycleAlarm = 1\t\n\t\t\t\t\t\ttriggerUpdateFailed(os.time() -(lastTrigger + myConfig.Trigger_UpdateFailedAfter*60))\n\t\t\t\t\tend\n\t\t\t\t\t-- END CHECK TRIGGER MISSING FOR TOO LONG\n\t\t\t\t\t\n\t\t\t\t\t--START UPDATE OF VD'S AND WEB SERVICES\t\t\t\n\t\t\t\t\tif cycleUpdate == 1 then\n \t\t\t\t\t\tcycleAlarm = 0\n\t\t\t\t\t\t\tlocal textService = {}\n\t\t\t\t\t\t\tlocal ParameterPrefix = {}\n\t\t\t\t\t\t\tlocal text_1min = ''\n\t\t\t\t\t\t\tlocal value = 0\n\t\t\t\t\t\t\tlocal Tag = tonumber(os.date(\"%d\"))\n\t\t\t\t\t\t\tlocal Monat = tonumber(os.date(\"%m\"))\n\t\t\t\t\t\t\tlocal Jahr = tonumber(os.date(\"%Y\"))\n for IndexS, Value in pairs( mySensors.WebService_Name) do\t\n \ttextService[IndexS] = ''\n \tParameterPrefix[IndexS] = ''\n end\n\n\t\t\t\t\t\t\t-- CHANGE OF DAY\n\t\t\t\t\t\t\tif myRecords.TODAY ~= Tag then\n\t\t\t\t\t\t\t for IndexR, Value in pairs( mySensors.ID ) do\n \t\t\t\t\t\t\tmyRecords.MAX[IndexR] = nil\n\t\t\t\t\t\t\t\t \tmyRecords.MIN[IndexR] = nil\n\t\t\t\t\t\t\t\tif mySensors.RainCounterReset[IndexR] == 'D' then\n\t\t\t\t\t\t\t\t fibaro:debug('Record_Setting')\n\t\t\t\t\t\t\t\t myRecords.COUNT[IndexR] = fibaro:getValue(mySensors.ID[IndexR], 'value')\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t myRecords.COUNT[IndexR] = 0\n\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t end\n\t\t\t\t\t\t\t myRecords.TODAY = Tag\n\t\t\t\t\t\t\t fibaro:debug ('TAG NEU')\n\t\t\t\t\t\t\tend\n\n\t\t\t\t\t\t\tif myRecords.THISMONTH ~= Monat then\n\t\t\t\t\t\t\t for IndexR, Value in pairs( mySensors.ID ) do\n\t\t\t\t\t\t\t\tif mySensors.RainCounterReset[IndexR] == 'M' then\n\t\t\t\t\t\t\t\t myRecords.COUNT[IndexR] = fibaro:getValue(mySensors.ID[IndexR], 'value')\n\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t end\n\t\t\t\t\t\t\t myRecords.THISMONTH = Monat\n\t\t\t\t\t\t\t fibaro:debug ('MONAT NEU')\n\t\t\t\t\t\t\tend\n\n\t\t\t\t\t\t\tif myRecords.THISYEAR ~= Jahr then\n\t\t\t\t\t\t\t for IndexR, Value in pairs( mySensors.ID ) do\n\t\t\t\t\t\t\t\tif mySensors.RainCounterReset[IndexR] == 'Y' then\n\t\t\t\t\t\t\t\t myRecords.COUNT[IndexR] = fibaro:getValue(mySensors.ID[IndexR], 'value')\n\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t end\n\t\t\t\t\t\t\t myRecords.THISYEAR = Jahr\n\t\t\t\t\t\t\t fibaro:debug ('JAHR NEU')\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t-- CHANGE OF DAY\n\n\t\t\t\t\t\t\t-- START LOOPING THROUGH ALL SENSORS\n for Index, Value in pairs( mySensors.ID ) do\n\t\t\t\t\t\t\t\t\tif mySensors.ID[Index] ~= 0 then \n\t\t\t\t\t\t\t\t\t\tlocal checker = mySensors.ID[Index]\n\t\t\t\t\t\t\t\t\t\t\tif tonumber(checker) then\n\t\t\t\t\t\t\t\t\t\t\t\t-- START GET VALUE OF DEVICE\n\t\t\t\t\t\t\t\t\t\t\t\t value = fibaro:getValue(mySensors.ID[Index], 'value')\n\t\t\t\t\t\t\t\t\t\t\t\tif mySensors.RainCounterReset[Index] ~= '' then\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue = tostring(tonumber(value)-tonumber(myRecords.COUNT[Index]) )\n\t\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\t\t\t-- END GET VALUE OF DEVICE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t-- START DEW POINT CALCULATION\n\t\t\t\t\t\t\t\t\t\t\telseif string.find(mySensors.ID[Index], \"DP\") then\n\t\t\t\t\t\t\t\t\t\t\t\tlocal DP ={}\n\t\t\t\t\t\t\t\t\t\t\t\tfor match in string.gmatch(mySensors.ID[Index], '[^,]+') do\n\t\t\t\t\t\t\t\t\t\t\t\t table.insert(DP, (match))\n\t\t\t\t\t\t\t\t\t\t\t\tend \n\t\t\t\t\t\t\t\t\t\t\t\tvTEMP = fibaro:getValue(mySensors.ID[tonumber(DP[2])], 'value')\n\t\t\t\t\t\t\t\t\t\t\t\tvHUM = fibaro:getValue(mySensors.ID[tonumber(DP[3])], 'value')\n\t\t\t\t\t\t\t\t\t\t\t\tvalue = 234.175*math.log((vHUM/100*(6.1078*math.exp(17.08085*vTEMP/(234.175+vTEMP))))/6.1078)/(17.08085-math.log((vHUM/100*(6.1078*math.exp(17.08085*vTEMP/(234.175+vTEMP))))/6.1078))\n\t\t\t\t\t\t\t\t\t\t\t-- END DEW POINT CALCULATION\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t-- START ABSOLUTE HUMITITY CALCULATION\n\t\t\t\t\t\t\t\t\t\t\telseif string.find(mySensors.ID[Index], \"AH\") then\n\t\t\t\t\t\t\t\t\t\t\t\tlocal AH ={}\n\t\t\t\t\t\t\t\t\t\t\t\tfor match in string.gmatch(mySensors.ID[Index], '[^,]+') do\n\t\t\t\t\t\t\t\t\t\t\t\t table.insert(AH, (match))\n\t\t\t\t\t\t\t\t\t\t\t\tend \n\t\t\t\t\t\t\t\t\t\t\t\tvTEMP = fibaro:getValue(mySensors.ID[tonumber(AH[2])], 'value')\n\t\t\t\t\t\t\t\t\t\t\t\tvHUM = fibaro:getValue(mySensors.ID[tonumber(AH[3])], 'value')\n\t\t\t\t\t\t\t\t\t\t\t\tvPRESS = fibaro:getValue(mySensors.ID[tonumber(AH[4])], 'value')\n\t\t\t\t\t\t\t\t\t\t\t\tvalue = 0.622 * vHUM/100 * (1.01325 * 10^(5.426651 - 2005.1 / (vTEMP + 273.15) + 0.00013869 * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700) / (vTEMP + 273.15) * (10^(0.000000000011965 * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700) * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700)) - 1) - 0.0044 * 10^((-0.0057148 * (374.11 - vTEMP)^1.25))) + (((vTEMP + 273.15) / 647.3) - 0.422) * (0.577 - ((vTEMP + 273.15) / 647.3)) * EXP^(0.000000000011965 * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700) * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700)) * 0.00980665) / (vPRESS/1000 - vHUM/100 * (1.01325 * 10^(5.426651 - 2005.1 / (vTEMP + 273.15) + 0.00013869 * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700) / (vTEMP + 273.15) * (10^(0.000000000011965 * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700) * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700)) - 1) - 0.0044 * 10^((-0.0057148 * (374.11 - vTEMP)^1.25))) + (((vTEMP + 273.15) / 647.3) - 0.422) * (0.577 - ((vTEMP + 273.15) / 647.3)) * EXP^(0.000000000011965 * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700) * ((vTEMP + 273.15) * (vTEMP + 273.15) - 293700)) * 0.00980665)) * vPRESS/1000 * 100000000 / ((vTEMP + 273.15) * 287.1)\n\t\t\t\t\t\t\t\t\t\t\tend \n\t\t\t\t\t\t\t\t\t\t\t-- END ABSOLUTE HUMITITY CALCULATION\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t-- START UPDATE WEB SERVICE QUERY AND PARTIAL UPLOADS\n\t\t\t\t\t\t\t\tfor IndexS, Value in pairs( mySensors.WebService_Name) do\t\n\t\t\t\t\t\t\t\t\tlocal nameService = mySensors.WebService_Name[IndexS][Index]\n\t\t\t\t\t\t\t\t\tlocal valueService = convertUnit(mySensors.WebService_Convert[IndexS][Index],value)\n\t\t\t\t\t\t\t\t\tif nameService ~= '' then\n\t\t\t\t\t\t\t\t\t\tif myConfig.WebService_OneShotUpdate[IndexS] == 1 then\n\t\t\t\t\t\t\t\t\t\t\ttextService[IndexS] = textService[IndexS] ..ParameterPrefix[IndexS] ..nameService ..myConfig.WebService_Parameter_seperator[IndexS] ..valueService\n\t\t\t\t\t\t\t\t\t\t\tParameterPrefix[IndexS] = myConfig.WebService_Parameter_prefix[IndexS]\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\ttextService[IndexS] = ParameterPrefix[IndexS] ..nameService ..myConfig.WebService_Parameter_seperator[IndexS] ..valueService\n\t\t\t\t\t\t\t\t\t\t\tif cycleCounter % myConfig.WebService_UpdateAfterCycles[IndexS] == 0 then\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t WEB = Net.FHttp(myConfig.WebService_Url[IndexS]) \n\t\t\t\t\t\t\t\t\t\t\t\t\t response = WEB:GET(myConfig.WebService_UrlPrefix[IndexS] ..textService[IndexS] ..myConfig.WebService_UrlSuffix[IndexS]) \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfibaro:debug(response ..':' ..myConfig.WebService_Url[IndexS] ..myConfig.WebService_UrlPrefix[IndexS] ..textService[IndexS] ..myConfig.WebService_UrlSuffix[IndexS] )\n\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t-- END UPDATE WEB SERVICE QUERY AND PARTIAL UPLOADS\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t-- START VIRTUAL DEVICE UPDATE\n\t\t\t\t\t\t\t\tlocal valueVD = convertUnit(mySensors.VD_Convert[Index],value)\n\t\t\t\t\t\t\t\tlocal labelVD = mySensors.VD_LBL[Index]\n\t\t\t\t\t\t\t\tlocal unitVD = \" \" ..mySensors.VD_Unit[Index]\n\t\t\t\t\t\t\t\tif labelVD ~= 0 then\n\t\t\t\t\t\t\t\t-- START UDATE RAW MIN MAX IN RECORDS\n\t\t\t\t\t\t\t\t\tif myRecords.MIN[Index] == nil then myRecords.MIN[Index] = valueVD end\n\t\t\t\t\t\t\t\t\tif myRecords.MAX[Index] == nil then myRecords.MAX[Index] = valueVD end\n\t\t\t\t\t\t\t\t\tif tonumber(myRecords.MIN[Index]) ~= nil and tonumber(valueVD) ~= nil then\n\t\t\t\t\t\t\t\t\t\tif tonumber(myRecords.MIN[Index]) > tonumber(valueVD) then myRecords.MIN[Index] = valueVD end\n\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\tif tonumber(myRecords.MAX[Index]) ~= nil and tonumber(valueVD) ~= nil then\n\t\t\t\t\t\t\t\t\t\tif tonumber(myRecords.MAX[Index]) < tonumber(valueVD) then myRecords.MAX[Index] = valueVD end\n\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\tmyRecords.NOW[Index] = valueVD\n\t\t\t\t\t\t\t\t-- END UDATE RAW MIN MAX IN RECORDS\t\n\t\t\t\t\t\t\t\tfibaro:call(myConfig.VD_ID, \"setProperty\",\"ui.Label\" ..tostring(labelVD) ..\".value\",valueVD ..unitVD)\n\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t-- END VIRTUAL DEVICE UPDATE\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t-- START UPDATE NOTIFICATION VARIABLES\n\t\t\t\t\t\t\t\tif myRecords.NOTIFY_Variable[Index] ~= '' then\n\t\t\t\t\t\t\t\t\tvarNotify=fibaro:getGlobal(myRecords.NOTIFY_Variable[Index])\n\t\t\t\t\t\t\t\t\tmyMeasurement =json.decode(varNotify)\n\t\t\t\t\t\t\t\t\tlocal lastModified = fibaro:getGlobalModificationTime(myRecords.NOTIFY_Variable[Index])\n\t\t\t\t\t\t\t\t\tif ((os.time()-lastModified) >= myMeasurement.updateAfter) then\n\t\t\t\t\t\t\t\t\t\t\tif tonumber(myMeasurement.minTrigger) > tonumber(valueVD) then\n\t\t\t\t\t\t\t\t\t\t\t\tmyMeasurement.minValue = valueVD\n\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\t\tif tonumber(myMeasurement.maxTrigger) < tonumber(valueVD) then\n\t\t\t\t\t\t\t\t\t\t\t\tmyMeasurement.maxValue = valueVD\n\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\t\tif myMeasurement.report == \"Y\" then\n\t\t\t\t\t\t\t\t\t\t\t\tfibaro:setGlobal(json.encode(myRecords.NOTIFY_Variable[Index],myMeasurement))\n\t\t\t\t\t\t\t\t\t\t\tend \n\t\t\t\t\t\t\t\t\tend \n\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t-- END UPDATE NOTIFICATION VARIABLES\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tend\n\t\t\t\t\t\tend\n\t\t\t\t\t\t\t-- END LOOPING THROUGH ALL SENSORS\n \t\t\t\t\t\tfibaro:call(myConfig.VD_ID, \"setProperty\", \"ui.Label0.value\", os.date('%H:%M'))\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t-- START ONE SHOT UPDATE\t\t\n\t\t\t\t\t\t\tfor IndexS, Value in pairs( mySensors.WebService_Name) do\t\n\t\t\t\t\t\t\t\t\t\tif myConfig.WebService_OneShotUpdate[IndexS] == 1 then\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tif cycleCounter % myConfig.WebService_UpdateAfterCycles[IndexS] == 0 then\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t WEB = Net.FHttp(myConfig.WebService_Url[IndexS]) \n\t\t\t\t\t\t\t\t\t\t\t\t\t response = WEB:GET(myConfig.WebService_UrlPrefix[IndexS] ..textService[IndexS] ..myConfig.WebService_UrlSuffix[IndexS]) \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfibaro:debug(response ..':' ..myConfig.WebService_Url[IndexS] ..myConfig.WebService_UrlPrefix[IndexS] ..textService[IndexS] ..myConfig.WebService_UrlSuffix[IndexS] )\n\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\tend\t\t\t\n\t\t\t\t\t\t\t-- END ONE SHOT UPDATE\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t-- START RECORDS UPDATE\n\t\t\t\t\t\t\tif cycleCounter % 60 == 0 then\n\t\t\t\t\t\t\t\tfibaro:setGlobal('WetterRecords_Test',json.encode(myRecords)) \n\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t-- END RECORDS UPDATE\n\t\t\t\t\t end\n\t\t\t\t\t --END UPDATE OF VD'S AND WEB SERVICES\t\n\t else\n\t\t fibaro:debug('WetterConfig missing, run configuration LUA script first')\n\t end\n \n fibaro:sleep(sleepTime) \n\tl0value = fibaro:get(xID, 'ui.Label0.value')\n\n if l0value ~= nil then\n\tif l0value =='1' or l0value =='2' or l0value =='0' then\n\t\tfor Index, Value in pairs( mySensors.ID ) do\n\t\t\tvalue = myRecords.NOW[Index]\n\t\t\tif value == nil then value = 0 end\n \tMIN = myRecords.MIN[Index]\n \tMAX = myRecords.MAX[Index]\n if MIN == nil then MIN = 0 end\n if MAX == nil then MAX = 0 end\n\n\t\t\tlocal labelVD = mySensors.VD_LBL[Index]\n\t\t\tlocal unitVD = \" \" ..mySensors.VD_Unit[Index]\n\t\t\tif labelVD ~= 0 then\n\t\t\t\tif l0value =='1' then\n\t\t\t\t\tfibaro:call(myConfig.VD_ID, \"setProperty\",\"ui.Label\" ..tostring(labelVD) ..\".value\",MIN ..unitVD)\n\t\t\t\t\tfibaro:call(myConfig.VD_ID, \"setProperty\", \"ui.Label0.value\", 'MIN')\n\t\t\t\telseif l0value =='2' then\n\t\t\t\t\tfibaro:call(myConfig.VD_ID, \"setProperty\",\"ui.Label\" ..tostring(labelVD) ..\".value\",MAX ..unitVD)\n\t\t\t\t\tfibaro:call(myConfig.VD_ID, \"setProperty\", \"ui.Label0.value\", 'MAX')\n\t\t\t\telseif l0value =='0' then\n\t\t\t\t\tfibaro:call(myConfig.VD_ID, \"setProperty\",\"ui.Label\" ..tostring(labelVD) ..\".value\",value ..unitVD)\n\t\t\t\t\tfibaro:call(myConfig.VD_ID, \"setProperty\", \"ui.Label0.value\", 'NOW')\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\t\t\n end\nend\n-- START ENDLESS LOOP, RUN every 20 seconds\nfibaro:debug('Application not running')\nfibaro:sleep(1000*120) -- 2 minutes sleep\n","ui.Label0.value":"NOW","ui.Label1.value":"12.2 °C","ui.Label10.value":"1019.0 hpa","ui.Label11.value":"11.7 °C","ui.Label12.value":"","ui.Label13.value":"23.8 °C","ui.Label14.value":"52.6 %","ui.Label15.value":"13.5 °C","ui.Label16.value":"58.0 Lx","ui.Label17.value":"","ui.Label18.value":"","ui.Label19.value":"","ui.Label2.value":"96.9 %","ui.Label20.value":"","ui.Label3.value":"","ui.Label4.value":"0.0 km/h","ui.Label5.value":"1.8 km/h","ui.Label6.value":"Nord ","ui.Label7.value":"","ui.Label8.value":"0.0 mm","ui.Label9.value":"0.0 mm","visible":"true","rows":[{"type":"label","elements":[{"id":1,"lua":false,"waitForResponse":false,"caption":"Update","name":"Label0","favourite":false,"main":false}]},{"type":"button","elements":[{"id":2,"lua":true,"waitForResponse":false,"caption":"MIN","name":"Button11","empty":false,"msg":"DID = fibaro:getSelfId()\nfibaro:call(DID, \"setProperty\", \"ui.Label0.value\", 1)","buttonIcon":238,"favourite":false,"main":false},{"id":3,"lua":true,"waitForResponse":false,"caption":"NOW","name":"Button12","empty":false,"msg":"DID = fibaro:getSelfId()\nfibaro:call(DID, \"setProperty\", \"ui.Label0.value\", 0)","buttonIcon":0,"favourite":false,"main":true},{"id":4,"lua":true,"waitForResponse":false,"caption":"MAX","name":"Button13","empty":false,"msg":"DID = fibaro:getSelfId()\nfibaro:call(DID, \"setProperty\", \"ui.Label0.value\", 2)","buttonIcon":239,"favourite":false,"main":false}]},{"type":"label","elements":[{"id":5,"lua":false,"waitForResponse":false,"caption":"Temperature","name":"Label1","favourite":false,"main":false}]},{"type":"label","elements":[{"id":6,"lua":false,"waitForResponse":false,"caption":"Humitidy","name":"Label2","favourite":false,"main":false}]},{"type":"label","elements":[{"id":7,"lua":false,"waitForResponse":false,"caption":"","name":"Label3","favourite":false,"main":false}]},{"type":"label","elements":[{"id":8,"lua":false,"waitForResponse":false,"caption":"Wind","name":"Label4","favourite":false,"main":false}]},{"type":"label","elements":[{"id":9,"lua":false,"waitForResponse":false,"caption":"Gust","name":"Label5","favourite":false,"main":false}]},{"type":"label","elements":[{"id":10,"lua":false,"waitForResponse":false,"caption":"Direction","name":"Label6","favourite":false,"main":false}]},{"type":"label","elements":[{"id":11,"lua":false,"waitForResponse":false,"caption":"","name":"Label7","favourite":false,"main":false}]},{"type":"label","elements":[{"id":12,"lua":false,"waitForResponse":false,"caption":"Rain Rate","name":"Label8","favourite":false,"main":false}]},{"type":"label","elements":[{"id":13,"lua":false,"waitForResponse":false,"caption":"Daily Rain","name":"Label9","favourite":false,"main":false}]},{"type":"label","elements":[{"id":14,"lua":false,"waitForResponse":false,"caption":"Barometer","name":"Label10","favourite":false,"main":false}]},{"type":"label","elements":[{"id":15,"lua":false,"waitForResponse":false,"caption":"Dew Point","name":"Label11","favourite":false,"main":false}]},{"type":"label","elements":[{"id":16,"lua":false,"waitForResponse":false,"caption":"","name":"Label12","favourite":false,"main":false}]},{"type":"label","elements":[{"id":17,"lua":false,"waitForResponse":false,"caption":"Innen TEMP","name":"Label13","favourite":false,"main":false}]},{"type":"label","elements":[{"id":18,"lua":false,"waitForResponse":false,"caption":"Innen HUM","name":"Label14","favourite":false,"main":false}]},{"type":"label","elements":[{"id":19,"lua":false,"waitForResponse":false,"caption":"Innen TP","name":"Label15","favourite":false,"main":false}]},{"type":"label","elements":[{"id":20,"lua":false,"waitForResponse":false,"caption":"LUX","name":"Label16","favourite":false,"main":false}]},{"type":"label","elements":[{"id":21,"lua":false,"waitForResponse":false,"caption":"","name":"Label17","favourite":false,"main":false}]},{"type":"label","elements":[{"id":22,"lua":false,"waitForResponse":false,"caption":"","name":"Label18","favourite":false,"main":false}]},{"type":"label","elements":[{"id":23,"lua":false,"waitForResponse":false,"caption":"","name":"Label19","favourite":false,"main":false}]},{"type":"label","elements":[{"id":24,"lua":false,"waitForResponse":false,"caption":"","name":"Label20","favourite":false,"main":false}]}]},"actions":{"pressButton":1,"setSlider":2,"setProperty":2}}