-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuienradar_Weather-30.fqa
1 lines (1 loc) · 57.6 KB
/
Buienradar_Weather-30.fqa
1
{"name":"Buienradar Weather","type":"com.fibaro.weather","apiVersion":"1.2","initialProperties":{"viewLayout":{"$jason":{"body":{"header":{"style":{"height":"0"},"title":"quickApp_device_1338"},"sections":{"items":[{"components":[{"name":"label","style":{"weight":"1.2"},"text":"Weatherinformation","type":"label","visible":true},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"}]}},"head":{"title":"quickApp_device_1338"}}},"uiCallbacks":[],"quickAppVariables":[{"name":"interval","type":"string","value":"601"},{"name":"stationID","type":"string","value":"6260"},{"name":"backupstationID","type":"string","value":"6260"},{"name":"timeout","type":"string","value":"5"},{"name":"debugLevel","type":"string","value":"1"},{"name":"setGlobalVar","value":"false"},{"name":"stationWarning","value":"true"}],"typeTemplateInitialized":true},"files":[{"name":"main","isMain":true,"isOpen":true,"content":"-- QuickApp BUIENRADAR WEATHER \n\n-- This QuickApp can be used as your Fibaro Homecenter 3 Weather Provider (Settings - 6. General - Main - Main Devices - Weather Provider)\n-- The Buienradar Weather QuickApp contains the current Dutch weather measurements, the weather forecast and the 5-day forecast \n-- The 5-days forecast is shown in the labels and the tomorrow forecast is shown in the child devices \n-- The current observations are measured by KNMI weather stations spread across The Netherlands and are updated every 10 minutes \n-- The weather report is updated several times a day by the Buienradar meteorologists \n\n-- The QuickApp has child devices for:\n -- Temperature °C \n -- Feel temperature °C \n -- Ground temperature °C \n -- Humidity % \n -- Absolute humidity g/m³\n -- Airpressure hPa\n -- Windspeed m/s \n -- Windspeed km/h\n -- Winddirectiondegrees ° (plus wind direction and arrow)\n -- Windspeed Bft\n -- Windgusts km/h\n -- Rain mm/h \n -- Rain Last 24h mm\n -- Sunpower Watt/m²\n -- Visibility km\n -- Sunset (time)\n -- Sunrise (time)\n -- Sun Chance tomorrow % \n -- Min Temp tomorrow °C\n -- Max Temp tomorrow °C\n -- Rain Chance tomorrow % \n -- Min Rain tomorrow mm/h\n -- Max Rain tomorrow mm/h\n -- Wind tomorrow m/s (plus wind direction and arrow)\n -- Wind tomorrow km/h (plus wind direction and arrow)\n \n-- This QuickApp is plug-and-play. The only thing you can do, is change the Station ID to a weatherstation nearby from the list or add some nice icons to the devices. \n\n-- Wind Chill (based on the JAG/TI-method) and is only valid for temperatures between -46 C and +10 C and is only valid for wind speed between 1.3 m/s and 49 m/s\n-- Windspeed is shown in m/s (km/3.6)\n-- Absolute humidity is the measure of water vapor (moisture) in the air, regardless of temperature. It is expressed as grams of moisture per cubic meter of air (g/m3) \n-- conditionCodes = {unavailable = 3200, clear = 32, rain = 40, snow = 43, storm = 38, cloudy = 30, fog = 20,}\n-- The time shown in the QuickApp, is the last time of the measurement from Buienradar (not the system time)\n\n-- TODO: Extra weather condition translations\n-- TODO: Multi language\n-- TODO: Change global variables to separate globals (?)\n\n\n-- Changes version 3.0 (23rd March 2022)\n-- Added 5-days forecast to the labels\n-- Addded child devices for:\n -- Feel temperature °C \n -- Ground temperature °C \n -- Windspeed km/h\n -- Windspeed Bft\n -- Windgusts km/h\n -- Rain Last 24h mm\n -- Sun Chance tomorrow % \n -- Min Temp tomorrow °C\n -- Max Temp tomorrow °C\n -- Rain Chance tomorrow % \n -- Min Rain tomorrow mm/h\n -- Max Rain tomorrow mm/h\n -- Wind tomorrow m/s (plus wind direction and arrow)\n -- Wind tomorrow km/h (plus wind direction and arrow)\n-- Changed SunPower device type to powerSensor\n-- Changed all Wind devices types to windSensor\n-- Converted date-times to more nice format\n-- Quickapp variable setGlobalVar changed to boolean\n-- Added Quickapp variable stationWarning to show a warning (once) if your station hasn't got some weather value (default is true)\n-- Optimised some code\n\n\n-- Changes version 2.1 (15th January 2021)\n-- Added Airpressure Text in log of Airpressure Child Device\n-- Added weatherdescription: \n -- \"Mix van opklaringen en hoge bewolking\" to conditioncode \"cloudy\"\n -- \"Half bewolkt\" to conditioncode \"cloudy\"\n -- \"Opklaring en lokaal nevel of mist\" to conditioncode \"fog\"\n -- \"Zwaar bewolkt met lichte sneeuwval\" to conditionCode \"snow\"\n -- \"Zwaar bewolkt met regen en winterse neerslag\" to conditioncode \"snow\"\n -- \"Afwisselend bewolkt met lichte sneeuwval\" to conditioncode \"snow\"\n -- \"Zware sneeuwval\" to conditioncode \"snow\"\n -- \"Opklaringen en kans op enkele pittige (onweers)buien\" to conditioncode \"rain\"\n -- \"Bewolkt en kans op enkele pittige (onweers)buien\" to conditioncode \"rain\"\n\n-- Changes version 2.0 (3rd January 2021)\n-- Added Child Devices for: \n -- Temperature °C (including feeltemperature and groundtemperature) \n -- Humidity % \n -- Absolute humidity g/m³\n -- Airpressure hPa\n -- Windspeed m/s (including windspeedBft and Windgust km/h)\n -- Winddirectiondegrees ° (including winddirection and arrow)\n -- Rain mm/h (including rainFallLast24Hour mm)\n -- Sunpower Watt/m²\n -- Visibility km\n -- Sunset (time)\n -- Sunrise (time)\n-- Re-arranged the labels\n-- Added backup station functionality for weather stations that don't have all the data, the data from 6260 Meetstation De Bilt is used. \n-- Improved check for missing data\n-- Added Quickapp variable for debug level (1=some, 2=few, 3=all). Recommended default value is 1.\n\n-- Changes version 1.0 (25th October 2020)\n-- Added weatherdescription \"Zwaar bewolkt met wat lichte regen\" to conditionCode \"rain\"\n\n-- Changes version 0.6 (9th September 2020)\n-- Changed conditionCodes storm = 38, snow = 43 and unknown = unavailable\n-- Added weatherdescription \"Afwisselend bewolkt met (mogelijk) wat lichte regen\" to conditionCode \"rain\" and and \"Afwisselend bewolkt met lokaal mist(banken)\" to conditionCode \"fog\"\n\n-- Changes version 0.5 (4th September 2020)\n-- Added wind direction, air pressure and feel temperature to QuickApp labels\n-- Changed stationname to regio in labels and log\n-- Changed the names of the Global Variables to meet the Fibaro standards and shortened them (please manually delete your old ones and change the names in your scenes)\n-- Added an extra check for response of Buienradar (jsonTable)\n\n-- Changes version 0.4 (23rd August 2020) \n-- Completely renewed code\n-- Several Global Variables are available for personal use\n-- Addes QuickApp variable SetGlobalVar true or false, whether you want to use the Global Variables\n-- Added QuickApp variable Timeout for finetuning waiting for response\n\n-- Changes version 0.3 (11th August 2020)\n-- Error message instead of debug message in case of an error\n-- Changed method of adding QuickApp variables, so they can be edited\n\n-- QuickApp Variables mandatory (automatically created):\n-- interval = Number in seconds to update the data (defaul = 601)\n-- timeout = Number in seconds to wait for a response (default = 5)\n-- stationID = Number of the station you want to use for weather measurements (default = 6260 Meetstation De Bilt)\n-- backupstationID = Number of the backup station for missing weather data from stations that don't have all the data (default = 6260 Meetstation De Bilt). Don't change this ID unless you know what you are doing, \n-- setGlobalVar = true or false, whether you want tu use the Global Variables (default = false)\n-- stationWarning = true or false, whether you want to receive warnings if your station hasn't got some weather value (default is true)\n-- debugLevel = Number (1=some, 2=few, 3=all) (default = 1)\n\n-- Station ID's and Stations: \n-- 6391 Meetstation Arcen / 6275 Meetstation Arnhem / 6249 Meetstation Berkhout / 6308 Meetstation Cadzand / 6260 Meetstation De Bilt / 6235 Meetstation Den Helder / 6370 Meetstation Eindhoven / 6377 Meetstation Ell / 6321 Meetstation Euro platform / 6350 Meetstation Gilze Rijen / 6323 Meetstation Goes / 6283 Meetstation Groenlo-Hupsel / 6280 Meetstation Groningen / 6315 Meetstation Hansweert / 6278 Meetstation Heino / 6356 Meetstation Herwijnen / 6330 Meetstation Hoek van Holland / 6279 Meetstation Hoogeveen / 6251 Meetstation Hoorn Terschelling / 6258 Meetstation Houtribdijk / 6285 Meetstation Huibertgat / 6209 Meetstation IJmond / 6225 Meetstation IJmuiden / 6277 Meetstation Lauwersoog / 6320 Meetstation LE Goeree / 6270 Meetstation Leeuwarden / 6269 Meetstation Lelystad / 6348 Meetstation Lopik-Cabauw / 6380 Meetstation Maastricht / 6273 Meetstation Marknesse / 6286 Meetstation Nieuw Beerta / 6312 Meetstation Oosterschelde / 6344 Meetstation Rotterdam / 6343 Meetstation Rotterdam Geulhaven / 6316 Meetstation Schaar / 6240 Meetstation Schiphol / 6324 Meetstation Stavenisse / 6267 Meetstation Stavoren / 6229 Meetstation Texelhors / 6331 Meetstation Tholen / 6290 Meetstation Twente / 6313 Meetstation Vlakte aan de Raan / 6242 Meetstation Vlieland / 6310 Meetstation Vlissingen / 6375 Meetstation Volkel / 6215 Meetstation Voorschoten / 6319 Meetstation Westdorpe / 6248 Meetstation Wijdenes / 6257 Meetstation Wijk aan Zee / 6340 Meetstation Woensdrecht / 6239 Meetstation Zeeplatform F-3 / 6252 Meetstation Zeeplatform K13\n\n-- This QuickApp can store all general and station specific weather information in global variables. These global variables you can use in your own scripts, for example to send an email every morning with the weather forecast, send notifications of weather changes, etcetera. To use these Global Variables, set the QuickApp variable \"setGlobalVar\" to true.\n\n-- Global Variables (if QuickApp variable setGlobalVar = true):\n-- brStation_[deviceID]\n-- brWeatherreport_[deviceID]\n-- brShortterm_[deviceID]\n-- brLongterm_[deviceID]\n-- brFivedayforecast_2_[deviceID]\n-- brFivedayforecast_3_[deviceID]\n-- brFivedayforecast_4_[deviceID]\n-- brFivedayforecast_5_[deviceID]\n\n-- Examples of the Global Variables:\n \n-- brStation_[deviceID] -- {\"regio\": \"Rotterdam\",\"timestamp\": \"2020-08-22T11:40:00\",\"airpressure\": 1013.1,\"lat\": 51.95,\"weatherdescription\": \"Zwaar bewolkt\",\"rainFallLast24Hour\": 0.6,\"feeltemperature\": 20.3,\"precipitation\": 0,\"stationname\": \"Meetstation Rotterdam\",\"lon\": 4.45,\"$id\": \"36\",\"temperature\": 20.3,\"graphUrl\": \"https://www.buienradar.nl/nederland/weerbericht/weergrafieken/c\",\"windgusts\": 14.4,\"sunpower\": 349,\"rainFallLastHour\": 0,\"winddirection\": \"ZW\",\"stationid\": 6344,\"groundtemperature\": 20.7,\"winddirectiondegrees\": 215,\"humidity\": 68,\"windspeedBft\": 5,\"windspeed\": 9.3,\"visibility\": 25300,\"iconurl\": \"https://www.buienradar.nl/resources/images/icons/weather/30x30/c.png\"}\n\n-- brWeatherreport_[deviceID] -- {\"published\":\"2020-08-22T10:00:00\",\"authorbio\":\"Sinds 2017 als junior Meteoroloog actief voor het weekendteam van Buienradar. Daarnaast student van de Bachelor Bodem, Water & Atmosfeer aan de Wageningen Universiteit.\",\"author\":\"Philippe Schambergen\",\"text\":\"Na de warmte van de afgelopen weken gaat het roer nu flink om. De komende tijd is het wisselvallig in Nederland met normale temperaturen en vooral op woensdag staat er veel wind.Vandaag is het wisselend bewolkt en is het in het binnenland nog geruime tijd droog. In de loop van de dag gaan er vanuit het noordwesten buien vallen met in het noorden kans op onweer. Na het middaguur trekken deze buien verder landinwaarts. Tussen de buien door blijft er echter genoeg ruimte voor de zon. Het wordt 21 of 22 graden langs de kust en nog een zomerse 25 graden in het zuidoosten. Er staat een matige en aan zee krachtige zuidwestenwind, windkracht 4 tot 6. Ook komen er in heel het land windstoten rond de 50 km\\/h voor, tijdens buien mogelijk oplopend tot 75 km\\/h. Aan het eind van de middag komt er langs de zuidwestkust mogelijk een harde zuidwestenwind te staan, windkracht 7.Vanavond klaart het op en trekken de meeste buien naar het oosten weg. Het blijft nog even stevig waaien. Vannacht neemt de wind in het binnenland iets af en verdwijnen daar de windstoten. Er gaan wel opnieuw buien ontstaan in het noorden van het land. Het koelt af naar 17 graden aan zee en 14 graden in het binnenland. Morgen is het wisselend bewolkt en trekken enkele buien over het land. Er staat wel iets minder wind dan vandaag: de westenwind waait matig tot aan zee (vrij) krachtig. In de middag wordt het nog maar 20 graden op de Wadden en 22 graden in het zuidoosten van het land, waarmee de temperatuur rond normaal komt te liggen.De dagen erna is het wisselvallig met enkele buien waarbij het vooral in het noorden soms flink kan doorregenen. Een depressie ligt woensdag boven de Noordzee en deze zorgt dan voor een flinke toename van de wind. Mogelijk wordt het zelfs even stormachtig! In de middag wordt het 19 tot 22 graden, alleen dinsdag kan het in het zuidoosten wel weer 24 graden worden.\",\"title\":\"Terug naar normaal\",\"summary\":\"Na de warmte van de afgelopen weken gaat het roer nu flink om. De komende tijd is het wisselvallig in Nederland met normale temperaturen en vooral op woensdag staat er veel wind.\",\"$id\":\"57\"}\n\n-- brShortterm_[deviceID] -- {\"startdate\":\"2020-08-23T00:00:00\",\"enddate\":\"2020-08-27T00:00:00\",\"forecast\":\"Onbestendig met geregeld regen of enkele buien.\",\"$id\":\"58\"}\n\n-- brLongterm_[deviceID] -- {\"startdate\":\"2020-08-28T00:00:00\",\"enddate\":\"2020-09-01T00:00:00\",\"forecast\":\"Aanvankelijk onbestendig met maxima iets onder het langjarig gemiddelde. Later in de periode neemt de kans op een droger en warmer weertype toe.\",\"$id\":\"59\"}\n \n-- brFivedayforecast_2_[deviceID] -- {\"iconurl\": \"https://www.buienradar.nl/resources/images/icons/weather/30x30/f.png\",\"mintemperatureMin\": 14,\"maxtemperatureMax\": 20,\"weatherdescription\": \"Afwisselend bewolkt met (mogelijk) wat lichte regen\",\"mintemperature\": \"14/15\",\"mintemperatureMax\": 15,\"mmRainMax\": 5,\"maxtemperature\": \"19/20\",\"maxtemperatureMin\": 19,\"wind\": 3,\"windDirection\": \"w\",\"mmRainMin\": 2,\"sunChance\": 30,\"day\": \"2020-08-24T00:00:00\",\"rainChance\": 70,\"$id\": \"61\"}\n\n-- brFivedayforecast_3_[deviceID] -- {\"iconurl\": \"https://www.buienradar.nl/resources/images/icons/weather/30x30/f.png\",\"mintemperatureMin\": 13,\"maxtemperatureMax\": 22,\"weatherdescription\": \"Afwisselend bewolkt met (mogelijk) wat lichte regen\",\"mintemperature\": \"13/15\",\"mintemperatureMax\": 15,\"mmRainMax\": 6,\"maxtemperature\": \"20/22\",\"maxtemperatureMin\": 20,\"wind\": 4,\"windDirection\": \"zw\",\"mmRainMin\": 2,\"sunChance\": 30,\"day\": \"2020-08-25T00:00:00\",\"rainChance\": 80,\"$id\": \"62\"}\n \n-- brFivedayforecast_4_[deviceID] -- {\"iconurl\": \"https://www.buienradar.nl/resources/images/icons/weather/30x30/f.png\",\"mintemperatureMin\": 16,\"maxtemperatureMax\": 21,\"weatherdescription\": \"Afwisselend bewolkt met (mogelijk) wat lichte regen\",\"mintemperature\": \"16/17\",\"mintemperatureMax\": 17,\"mmRainMax\": 3,\"maxtemperature\": \"19/21\",\"maxtemperatureMin\": 19,\"wind\": 5,\"windDirection\": \"w\",\"mmRainMin\": 1,\"sunChance\": 30,\"day\": \"2020-08-26T00:00:00\",\"rainChance\": 60,\"$id\": \"63\"}\n\n-- brFivedayforecast_5_[deviceID] -- {\"iconurl\": \"https://www.buienradar.nl/resources/images/icons/weather/30x30/f.png\",\"mintemperatureMin\": 13,\"maxtemperatureMax\": 20,\"weatherdescription\": \"Afwisselend bewolkt met (mogelijk) wat lichte regen\",\"mintemperature\": \"13/15\",\"mintemperatureMax\": 15,\"mmRainMax\": 3,\"maxtemperature\": \"19/20\",\"maxtemperatureMin\": 19,\"wind\": 3,\"windDirection\": \"zw\",\"mmRainMin\": 1,\"sunChance\": 40,\"day\": \"2020-08-27T00:00:00\",\"rainChance\": 70,\"$id\": \"64\"}\n\n-- JSON data copyright: (C)opyright Buienradar / RTL. All rights reserved\n-- JSON data terms: This feed may be used freely under condition of source reference buienradar.nl including a hyperlink to https://www.buienradar.nl. The feed cannot be derived from users or other persons.\n\n\n-- Below here no changes are needed\n\n\nclass 'brTemperature'(QuickAppChild)\nfunction brTemperature:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brTemperature:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.temperature))\n self:updateProperty(\"unit\", \"°C\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brFeelTemp'(QuickAppChild)\nfunction brFeelTemp:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brFeelTemp:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.feeltemperature))\n self:updateProperty(\"unit\", \"°C\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brGroundTemp'(QuickAppChild)\nfunction brGroundTemp:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brGroundTemp:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.groundtemperature))\n self:updateProperty(\"unit\", \"°C\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brHumidity'(QuickAppChild)\nfunction brHumidity:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brHumidity:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.humidity))\n self:updateProperty(\"unit\", \"%\")\nend\n\nclass 'brHumidityAbs'(QuickAppChild)\nfunction brHumidityAbs:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brHumidityAbs:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.humidityabsolute))\n self:updateProperty(\"unit\", \"g/m³\")\nend\n\nclass 'brAirpressure'(QuickAppChild)\nfunction brAirpressure:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brAirpressure:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.airpressure))\n self:updateProperty(\"unit\", \"hPa\")\n self:updateProperty(\"log\", data.airpressuretext)\nend\n\nclass 'brWindspeedMS'(QuickAppChild)\nfunction brWindspeedMS:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brWindspeedMS:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.windspeed))\n self:updateProperty(\"unit\", \"m/s\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brWindspeedKMH'(QuickAppChild)\nfunction brWindspeedKMH:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brWindspeedKMH:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.windspeed*3.6))\n self:updateProperty(\"unit\", \"km/h\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brWindspeedBFT'(QuickAppChild)\nfunction brWindspeedBFT:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brWindspeedBFT:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.windspeedBft))\n self:updateProperty(\"unit\", \"bft\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brWindgusts'(QuickAppChild)\nfunction brWindgusts:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brWindgusts:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.windgusts))\n self:updateProperty(\"unit\", \"km/h\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brWinddirection'(QuickAppChild)\nfunction brWinddirection:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brWinddirection:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.winddirectiondegrees))\n self:updateProperty(\"unit\", \"°\")\n self:updateProperty(\"log\", data.winddirection ..data.winddirectionarrow)\nend\n\nclass 'brPrecipitation'(QuickAppChild)\nfunction brPrecipitation:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brPrecipitation:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.precipitation))\n self:updateProperty(\"unit\", \"mm/h\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brLast24h'(QuickAppChild)\nfunction brLast24h:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brLast24h:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.rainFallLast24Hour))\n self:updateProperty(\"unit\", \"mm\")\n self:updateProperty(\"log\", \" \")\nend\n\nclass 'brSunpower'(QuickAppChild)\nfunction brSunpower:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brSunpower:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.sunpower))\n self:updateProperty(\"unit\", \"Watt/m²\")\nend\n\nclass 'brVisibility'(QuickAppChild)\nfunction brVisibility:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brVisibility:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.visibility)) \n self:updateProperty(\"unit\", \"km\")\nend\n\nclass 'brSunset'(QuickAppChild)\nfunction brSunset:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brSunset:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.sunset)) \n self:updateProperty(\"unit\", \"\")\nend\n\nclass 'brSunrise'(QuickAppChild)\nfunction brSunrise:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brSunrise:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.sunrise)) \n self:updateProperty(\"unit\", \"\")\nend\n\nclass 'brSunChance'(QuickAppChild)\nfunction brSunChance:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brSunChance:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.day1sunChance)) \n self:updateProperty(\"unit\", \"%\")\nend\n\nclass 'brMinMinTemp'(QuickAppChild)\nfunction brMinMinTemp:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brMinMinTemp:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.day1mintemperatureMin)) \n self:updateProperty(\"unit\", \"°C\")\nend\n\nclass 'brMaxMaxTemp'(QuickAppChild)\nfunction brMaxMaxTemp:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brMaxMaxTemp:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.day1maxtemperatureMax)) \n self:updateProperty(\"unit\", \"°C\")\nend\n\nclass 'brRainChance'(QuickAppChild)\nfunction brRainChance:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brRainChance:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.day1rainChance)) \n self:updateProperty(\"unit\", \"%\")\nend\n\nclass 'brMinRain'(QuickAppChild)\nfunction brMinRain:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brMinRain:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.day1mmRainMin)) \n self:updateProperty(\"unit\", \"mm/h\")\nend\n\nclass 'brMaxRain'(QuickAppChild)\nfunction brMaxRain:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brMaxRain:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.day1mmRainMax)) \n self:updateProperty(\"unit\", \"mm/h\")\nend\n\nclass 'brWindMS'(QuickAppChild)\nfunction brWindMS:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brWindMS:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.day1wind)) \n self:updateProperty(\"unit\", \"m/s\")\n self:updateProperty(\"log\", data.day1windDirection ..data.day1windDirectionarrow)\nend\n\nclass 'brWindKMH'(QuickAppChild)\nfunction brWindKMH:__init(dev)\n QuickAppChild.__init(self,dev)\nend\nfunction brWindKMH:updateValue(data) \n self:updateProperty(\"value\",tonumber(data.day1wind*3.6)) \n self:updateProperty(\"unit\", \"km/h\")\n self:updateProperty(\"log\", data.day1windDirection ..data.day1windDirectionarrow)\nend\n\n\nlocal function getChildVariable(child,varName)\n for _,v in ipairs(child.properties.quickAppVariables or {}) do\n if v.name==varName then return v.value end\n end\n return \"\"\nend\n\n\n-- QuickApp Functions\n\n\nfunction QuickApp:updateChildDevices() -- Update Child Devices\n for id,child in pairs(self.childDevices) do \n child:updateValue(data) \n end\nend\n\n\nfunction QuickApp:logging(level,text) -- Logging function for debug\n if tonumber(debugLevel) >= tonumber(level) then \n self:debug(text)\n end\nend\n\n\nfunction QuickApp:setGlobalVariable(tag,res) -- Fill the Buienradar Global Variable\n if setGlobalVar then \n if api.get(\"/globalVariables/\"..tag) == nil then\n local responseData, status = api.post(\"/globalVariables/\",{value=(json.encode(res)),name=tag})\n self:trace(\"Global Variable created: \" ..tag ..\" / status: \" ..status) \n else\n local responseData, status = api.put(\"/globalVariables/\"..tag,{value=(json.encode(res))})\n end\n else\n if api.get(\"/globalVariables/\"..tag) then\n self:deleteGlobalVariable(tag) -- If the Global Variable exists, delete it\n end\n end\nend\n\nfunction QuickApp:deleteGlobalVariable(tag) -- Delete the Buienradar Global Variable \n local responseData, status = api.delete(\"/globalVariables/\"..tag) \n self:trace(\"Global Variable deleted: \" ..tag ..\" / status: \" ..status)\nend\n\n\nfunction QuickApp:setPressuretext(airpressure) -- Setup text for airpressure\n press = tonumber(airpressure)\n if press < 974 then \n return \"Thunderstorms\"\n elseif press < 990 then\n return \"Stormy\"\n elseif press < 1002 then\n return \"Rain\"\n elseif press < 1010 then\n return \"Cloudy\"\n elseif press < 1022 then\n return \"Unstable\"\n elseif press < 1035 then\n return \"Stable\"\n else\n return \"Very dry\"\n end\nend\n\n\nfunction QuickApp:setWinddirectionarrow(direction) -- Setup arrow for winddirection \n if direction == \"N\" then\n return \" ↓\"\n elseif direction == \"NO\" or direction == \"ONO\" or direction == \"NNO\" then\n return \" ↙\"\n elseif direction == \"O\" then\n return \" ←\"\n elseif direction == \"OZO\" or direction ==\" ZO\" or direction == \"ZZO\" then\n return \" ↖\"\n elseif direction == \"Z\" then\n return \" ↑\"\n elseif direction == \"ZZW\" or direction == \"ZW\" or direction == \"WZW\" then\n return \" ↗\"\n elseif direction == \"W\" then\n return \" →\"\n elseif direction == \"WNW\" or direction == \"NW\" or direction == \"NNW\" then\n return \" ↘\"\n else\n return \" ⟳\"\n end\nend\n\n\nfunction QuickApp:getHumidityAbs() -- Calculate Absolute Humidity (based on Temperature, Relative Humidity and Airpressure) Source from muhmuh at Fibaro forum\n local EXP = 2.71828182845904523536028747135266249775724709369995\n local humidityAbs = 0.622 * data.humidity/100 * (1.01325 * 10^(5.426651 - 2005.1 / (data.temperature + 273.15) + 0.00013869 * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700) / (data.temperature + 273.15) * (10^(0.000000000011965 * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700) * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700)) - 1) - 0.0044 * 10^((-0.0057148 * (374.11 - data.temperature)^1.25))) + (((data.temperature + 273.15) / 647.3) - 0.422) * (0.577 - ((data.temperature + 273.15) / 647.3)) * EXP^(0.000000000011965 * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700) * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700)) * 0.00980665) / (data.airpressure/1000 - data.humidity/100 * (1.01325 * 10^(5.426651 - 2005.1 / (data.temperature + 273.15) + 0.00013869 * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700) / (data.temperature + 273.15) * (10^(0.000000000011965 * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700) * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700)) - 1) - 0.0044 * 10^((-0.0057148 * (374.11 - data.temperature)^1.25))) + (((data.temperature + 273.15) / 647.3) - 0.422) * (0.577 - ((data.temperature + 273.15) / 647.3)) * EXP^(0.000000000011965 * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700) * ((data.temperature + 273.15) * (data.temperature + 273.15) - 293700)) * 0.00980665)) * data.airpressure/1000 * 100000000 / ((data.temperature + 273.15) * 287.1)\n return string.format(\"%.2f\",humidityAbs)\nend\n\n\nfunction QuickApp:showWarningBackupData(var) -- Show warning if data from backup station is used\n if stationWarning then\n self:warning(var ..\" data from \" ..data.stationname ..\" NOT available, using data from backup station \" ..data.backupstationname)\n end\nend\n\n\nfunction QuickApp:setCondition(condition) -- Update weather condition, update properties \"ConditionCode\" and \"WeatherCondition\"\n self:logging(3,\"QuickApp:setCondition(condition)\")\n local conditionCodes = {unavailable = 3200, clear = 32, rain = 40, snow = 43, storm = 38, cloudy = 30, fog = 20,}\n local conditionCode = conditionCodes[condition]\n if conditionCode then\n self:updateProperty(\"ConditionCode\", conditionCode)\n self:updateProperty(\"WeatherCondition\", condition)\n end\nend\n\n\nfunction QuickApp:setPropertiesLabels() -- Update properties and labels \n self:logging(3,\"QuickApp:setPropertiesLabels()\")\n local labelText = data.regio ..\" (\" ..data.stationname ..\" - \" ..stationID ..\")\" ..\"\\n\" \n labelText = labelText ..data.weatherdescription ..\"\\n\" \n labelText = labelText ..\"Temperature: \" ..data.temperature ..\" °C\" ..\"\\n\"\n labelText = labelText ..\"Feel temperature: \" ..data.feeltemperature ..\" °C\" ..\"\\n\"\n labelText = labelText ..\"Ground temperature: \" ..data.groundtemperature ..\" °C\" ..\"\\n\"\n labelText = labelText ..\"Humidity: \" ..data.humidity ..\" %\" ..\"\\n\" \n labelText = labelText ..\"Absolute humidity: \" ..data.humidityabsolute ..\" g/m³\" ..\"\\n\" \n labelText = labelText ..\"Air pressure: \" ..data.airpressure ..\" hPa (\" ..data.airpressuretext ..\")\" ..\"\\n\" \n labelText = labelText ..\"Rain: \" ..data.precipitation ..\" mm/h Last 24h: \" ..data.rainFallLast24Hour ..\" mm/h\" ..\"\\n\" \n labelText = labelText ..\"Wind: \" ..data.winddirection ..\" \" ..data.windspeed ..\" m/s \" ..data.windspeed*3.6 ..\" km/h \" ..data.windspeedBft ..\" Bft \" ..\"\\n\" \n labelText = labelText ..\"Windgusts: \"..data.windgusts ..\" m/s\" ..\"\\n\" \n labelText = labelText ..\"Sun power: \" ..data.sunpower ..\" Watt/m²\" ..\"\\n\" \n labelText = labelText ..\"Visibility: \" ..data.visibility ..\" km\" ..\"\\n\" \n labelText = labelText ..\"Sunset: \" ..data.sunset ..\" - Sunrise: \" ..data.sunrise ..\"\\n\"\n labelText = labelText ..\"Measured: \" ..data.timestamp ..\"\\n\\n\"\n\n labelText = labelText ..\"5-Days Forecast: \" ..\"\\n\"\n labelText = labelText ..\"(\" ..data.day1 ..\") \" ..data.day1weatherdescription ..\"\\n\"\n labelText = labelText ..\"Sun chance: \" ..data.day1sunChance ..\" - \" ..data.day2sunChance ..\" - \"..data.day3sunChance ..\" - \" ..data.day4sunChance ..\" - \"..data.day5sunChance ..\" %\"..\"\\n\"\n labelText = labelText ..\"Min temp: \" ..data.day1mintemperatureMin ..\" - \" ..data.day2mintemperatureMin ..\" - \" ..data.day3mintemperatureMin ..\" - \" ..data.day4mintemperatureMin ..\" - \" ..data.day5mintemperatureMin ..\" °C\"..\"\\n\"\n labelText = labelText ..\"Max temp: \" ..data.day1maxtemperatureMax ..\" - \" ..data.day2maxtemperatureMax ..\" - \" ..data.day3maxtemperatureMax ..\" - \" ..data.day4maxtemperatureMax ..\" - \" ..data.day5maxtemperatureMax ..\" °C\"..\"\\n\"\n labelText = labelText ..\"Rain chance: \" ..data.day1rainChance ..\" - \" ..data.day2rainChance ..\" - \" ..data.day3rainChance ..\" - \" ..data.day4rainChance ..\" - \" ..data.day5rainChance ..\" %\" ..\"\\n\"\n labelText = labelText ..\"Rain min: \" ..data.day1mmRainMin ..\" - \" ..data.day2mmRainMin ..\" - \" ..data.day3mmRainMin ..\" - \" ..data.day4mmRainMin ..\" - \" ..data.day5mmRainMin ..\" mm/h\" ..\"\\n\" \n labelText = labelText ..\"Rain max: \" ..data.day1mmRainMax ..\" - \" ..data.day2mmRainMax ..\" - \" ..data.day3mmRainMax ..\" - \" ..data.day4mmRainMax ..\" - \" ..data.day5mmRainMax ..\" mm/h\" ..\"\\n\" \n labelText = labelText ..\"Wind: \" ..data.day1windDirection ..\" \" ..data.day1wind ..\" - \" ..data.day2windDirection ..\" \" ..data.day2wind ..\" - \" ..data.day3windDirection ..\" \" ..data.day3wind ..\" - \" ..data.day4windDirection ..\" \" ..data.day4wind ..\" - \" ..data.day5windDirection ..\" \" ..data.day5wind ..\" m/s\" ..\"\\n\"\n\n self:updateView(\"label\", \"text\", labelText)\n self:logging(2,labelText)\n\n self:updateProperty(\"log\", data.regio)\n\n -- Update Weatherstation values\n self:updateProperty(\"Temperature\", tonumber(data.temperature))\n self:updateProperty(\"Humidity\", tonumber(data.humidity))\n self:updateProperty(\"Wind\", tonumber(data.windspeed)*3.6) -- From m/s to km/h\n --self:updateProperty(\"Pressure\", tonumber(data.airpressure))\nend \n\n\nfunction QuickApp:setWeathercondition() -- Set Weathercondition\n self:logging(3,\"QuickApp:setWeathercondition()\") \n -- Update Condition (to be completed), unmapped weatherdescription are logged as warning\n if data.weatherdescription == \"Zwaar bewolkt\" or data.weatherdescription == \"Mix van opklaringen en middelbare of lage bewolking\" or data.weatherdescription == \"Mix van opklaringen en hoge bewolking\" or data.weatherdescription == \"Half bewolkt\" or data.weatherdescription == \"Opklaringen en kans op enkele pittige (onweers)buien\" or data.weatherdescription == \"Bewolkt en kans op enkele pittige (onweers)buien\" then self:setCondition(\"cloudy\")\n elseif data.weatherdescription == \"Zwaar bewolkt en regen\" or data.weatherdescription == \"Afwisselend bewolkt met (mogelijk) wat lichte regen\" or data.weatherdescription == \"Zwaar bewolkt met wat lichte regen\" then self:setCondition(\"rain\")\n elseif data.weatherdescription == \"Vrijwel onbewolkt (zonnig/helder)\" then self:setCondition(\"clear\")\n elseif data.weatherdescription == \"Sneeuw\" or data.weatherdescription == \"Zwaar bewolkt met lichte sneeuwval\" or data.weatherdescription == \"Afwisselend bewolkt met lichte sneeuwval\" or weatherdescription == \"Zware sneeuwval\" then self:setCondition(\"snow\")\n elseif data.weatherdescription == \"Storm\" then self:setCondition(\"storm\")\n elseif data.weatherdescription == \"Mistig\" or data.weatherdescription == \"Afwisselend bewolkt met lokaal mist(banken)\" or data.weatherdescription == \"Opklaring en lokaal nevel of mist\" then self:setCondition(\"fog\")\n else -- Unable to set the Condition to a known one\n self:setCondition(\"unavailable\") \n self:warning(\"Weatherdescription unavailable: \" ..data.weatherdescription)\n end \nend\n\n\nfunction QuickApp:onWeatherDataReceived(jsonTable) -- Get all weather data from json\n self:logging(3,\"QuickApp:onWeatherDataReceived(jsonTable)\")\n data.stationname = \"\"\n for i in pairs(jsonTable.actual.stationmeasurements) do -- Get the values from the stationID\n self:logging(3,jsonTable.actual.stationmeasurements[i].stationid ..\" \" ..jsonTable.actual.stationmeasurements[i].stationname)\n if stationID == jsonTable.actual.stationmeasurements[i].stationid then -- The main data values\n self:logging(3,\"Data from Station ID: \" ..backupstationID)\n data.temperature = jsonTable.actual.stationmeasurements[i].temperature or 0\n data.feeltemperature = jsonTable.actual.stationmeasurements[i].feeltemperature or 0\n data.groundtemperature = jsonTable.actual.stationmeasurements[i].groundtemperature or 0\n data.humidity = jsonTable.actual.stationmeasurements[i].humidity or 0\n data.airpressure = jsonTable.actual.stationmeasurements[i].airpressure or 0\n data.windspeed = jsonTable.actual.stationmeasurements[i].windspeed or 0\n data.winddirection = jsonTable.actual.stationmeasurements[i].winddirection or \" \"\n data.windspeedBft = jsonTable.actual.stationmeasurements[i].windspeedBft or 0\n data.windgusts = jsonTable.actual.stationmeasurements[i].windgusts or 0\n data.winddirectiondegrees = jsonTable.actual.stationmeasurements[i].winddirectiondegrees or 0\n data.precipitation = jsonTable.actual.stationmeasurements[i].precipitation or 0\n data.rainFallLast24Hour = jsonTable.actual.stationmeasurements[i].rainFallLast24Hour or 0\n data.sunpower = jsonTable.actual.stationmeasurements[i].sunpower or 0\n data.visibility = jsonTable.actual.stationmeasurements[i].visibility or 0\n data.sunrise = jsonTable.actual.sunrise or 0\n data.sunset = jsonTable.actual.sunset or 0\n\n -- The extra data values\n data.stationname = jsonTable.actual.stationmeasurements[i].stationname\n data.regio = jsonTable.actual.stationmeasurements[i].regio\n data.weatherdescription = jsonTable.actual.stationmeasurements[i].weatherdescription\n data.timestamp = jsonTable.actual.stationmeasurements[i].timestamp\n local pattern = \"(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)\" -- Convert timestamp to nice format\n local runyear, runmonth, runday, runhour, runminute, runseconds = data.timestamp:match(pattern)\n local convertedTimestamp = os.time({year = runyear, month = runmonth, day = runday, hour = runhour, min = runminute, sec = runseconds})\n data.timestamp = os.date(\"%d-%m-%Y %H:%M\", convertedTimestamp)\n\n -- Save Station specific weather values to Global Variable\n self:setGlobalVariable(\"brStation_\"..plugin.mainDeviceId,jsonTable.actual.stationmeasurements[i])\n end\n if backupstationID == jsonTable.actual.stationmeasurements[i].stationid then\n self:logging(3,\"Backup data from Station ID: \" ..backupstationID)\n data.backupstationname = jsonTable.actual.stationmeasurements[i].stationname\n data.backuptemperature = jsonTable.actual.stationmeasurements[i].temperature or 99\n data.backupfeeltemperature = jsonTable.actual.stationmeasurements[i].feeltemperature or 99\n data.backupgroundtemperature = jsonTable.actual.stationmeasurements[i].groundtemperature or 99\n data.backuphumidity = jsonTable.actual.stationmeasurements[i].humidity or 0\n data.backupairpressure = jsonTable.actual.stationmeasurements[i].airpressure or 1013\n data.backupwindspeed = jsonTable.actual.stationmeasurements[i].windspeed or 0\n data.backupwinddirection = jsonTable.actual.stationmeasurements[i].winddirection or \"?\"\n data.backupwindspeedBft = jsonTable.actual.stationmeasurements[i].windspeedBft or 0\n data.backupwindgusts = jsonTable.actual.stationmeasurements[i].windgusts or 0\n data.backupwinddirectiondegrees = jsonTable.actual.stationmeasurements[i].winddirectiondegrees or 0\n data.backupprecipitation = jsonTable.actual.stationmeasurements[i].precipitation or 0\n data.backuprainFallLast24Hour = jsonTable.actual.stationmeasurements[i].rainFallLast24Hour or 0\n data.backupsunpower = jsonTable.actual.stationmeasurements[i].sunpower or 0\n data.backupvisibility = jsonTable.actual.stationmeasurements[i].visibility or 0\n end\n end\n \n -- Get the 5-days forecast values\n data.day1weatherdescription = jsonTable.forecast.fivedayforecast[1].weatherdescription or \"\"\n data.day1mintemperatureMin = jsonTable.forecast.fivedayforecast[1].mintemperatureMin or 0\n data.day1maxtemperatureMax = jsonTable.forecast.fivedayforecast[1].maxtemperatureMax or 0\n data.day1mmRainMin = jsonTable.forecast.fivedayforecast[1].mmRainMin or 0\n data.day1mmRainMax = jsonTable.forecast.fivedayforecast[1].mmRainMax or 0\n data.day1rainChance = jsonTable.forecast.fivedayforecast[1].rainChance or 0\n data.day1sunChance = jsonTable.forecast.fivedayforecast[1].sunChance or 0\n data.day1wind = jsonTable.forecast.fivedayforecast[1].wind or 0\n data.day1windDirection = string.upper(jsonTable.forecast.fivedayforecast[1].windDirection) or \"\"\n data.day1windDirectionarrow = self:setWinddirectionarrow(data.day1windDirection) -- Setup day1WindDirection Arrow\n data.day1 = jsonTable.forecast.fivedayforecast[1].day\n local pattern = \"(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)\" -- Convert day1 to nice format\n local runyear, runmonth, runday, runhour, runminute, runseconds = data.day1:match(pattern)\n local convertedTimestamp = os.time({year = runyear, month = runmonth, day = runday, hour = runhour, min = runminute, sec = runseconds})\n data.day1 = os.date(\"%d-%m-%Y\", convertedTimestamp)\n \n data.day2mintemperatureMin = jsonTable.forecast.fivedayforecast[2].mintemperatureMin or 0\n data.day2maxtemperatureMax = jsonTable.forecast.fivedayforecast[2].maxtemperatureMax or 0\n data.day2mmRainMin = jsonTable.forecast.fivedayforecast[2].mmRainMin or 0\n data.day2mmRainMax = jsonTable.forecast.fivedayforecast[2].mmRainMax or 0\n data.day2rainChance = jsonTable.forecast.fivedayforecast[2].rainChance or 0\n data.day2sunChance = jsonTable.forecast.fivedayforecast[2].sunChance or 0\n data.day2wind = jsonTable.forecast.fivedayforecast[2].wind or 0\n data.day2windDirection = string.upper(jsonTable.forecast.fivedayforecast[2].windDirection) or \"\"\n \n data.day3mintemperatureMin = jsonTable.forecast.fivedayforecast[3].mintemperatureMin or 0\n data.day3maxtemperatureMax = jsonTable.forecast.fivedayforecast[3].maxtemperatureMax or 0\n data.day3mmRainMin = jsonTable.forecast.fivedayforecast[3].mmRainMin or 0\n data.day3mmRainMax = jsonTable.forecast.fivedayforecast[3].mmRainMax or 0\n data.day3rainChance = jsonTable.forecast.fivedayforecast[3].rainChance or 0\n data.day3sunChance = jsonTable.forecast.fivedayforecast[3].sunChance or 0\n data.day3wind = jsonTable.forecast.fivedayforecast[3].wind or 0\n data.day3windDirection = string.upper(jsonTable.forecast.fivedayforecast[3].windDirection) or \"\"\n \n data.day4mintemperatureMin = jsonTable.forecast.fivedayforecast[4].mintemperatureMin or 0\n data.day4maxtemperatureMax = jsonTable.forecast.fivedayforecast[4].maxtemperatureMax or 0\n data.day4mmRainMin = jsonTable.forecast.fivedayforecast[4].mmRainMin or 0\n data.day4mmRainMax = jsonTable.forecast.fivedayforecast[4].mmRainMax or 0\n data.day4rainChance = jsonTable.forecast.fivedayforecast[4].rainChance or 0\n data.day4sunChance = jsonTable.forecast.fivedayforecast[4].sunChance or 0\n data.day4wind = jsonTable.forecast.fivedayforecast[4].wind or 0\n data.day4windDirection = string.upper(jsonTable.forecast.fivedayforecast[4].windDirection) or \"\"\n \n data.day5mintemperatureMin = jsonTable.forecast.fivedayforecast[5].mintemperatureMin or 0\n data.day5maxtemperatureMax = jsonTable.forecast.fivedayforecast[5].maxtemperatureMax or 0\n data.day5mmRainMin = jsonTable.forecast.fivedayforecast[5].mmRainMin or 0\n data.day5mmRainMax = jsonTable.forecast.fivedayforecast[5].mmRainMax or 0\n data.day5rainChance = jsonTable.forecast.fivedayforecast[5].rainChance or 0\n data.day5sunChance = jsonTable.forecast.fivedayforecast[5].sunChance or 0\n data.day5wind = jsonTable.forecast.fivedayforecast[5].wind or 0\n data.day5windDirection = string.upper(jsonTable.forecast.fivedayforecast[5].windDirection) or \"\"\n \n -- Save generiek weather values to Global Variables\n self:setGlobalVariable(\"brWeatherreport_\"..plugin.mainDeviceId,jsonTable.forecast.weatherreport)\n self:setGlobalVariable(\"brShortterm_\"..plugin.mainDeviceId,jsonTable.forecast.shortterm)\n self:setGlobalVariable(\"brLongterm_\"..plugin.mainDeviceId,jsonTable.forecast.longterm)\n --self:setGlobalVariable(\"brFivedayforecast_1_\"..plugin.mainDeviceId,jsonTable.forecast.fivedayforecast[1])\n self:setGlobalVariable(\"brFivedayforecast_2_\"..plugin.mainDeviceId,jsonTable.forecast.fivedayforecast[2])\n self:setGlobalVariable(\"brFivedayforecast_3_\"..plugin.mainDeviceId,jsonTable.forecast.fivedayforecast[3])\n self:setGlobalVariable(\"brFivedayforecast_4_\"..plugin.mainDeviceId,jsonTable.forecast.fivedayforecast[4])\n self:setGlobalVariable(\"brFivedayforecast_5_\"..plugin.mainDeviceId,jsonTable.forecast.fivedayforecast[5])\n\n -- Check if variables have a value\n if data.stationname == \"\" or data.stationname == nil then\n self:error(\"Error: Station \" ..stationID ..\" not found!\")\n else\n if data.regio == \"\" or data.regio == nil then data.regio = \"empty\" end\n if data.weatherdescription == \"\" or data.weatherdescription == nil then data.weatherdescription = \"empty\" end\n if data.timestamp == \"\" or data.timestamp == nil then data.timestamp = \"empty\" end\n if data.temperature == \"\" or data.temperature == nil or data.temperature == 0 then data.temperature = data.backuptemperature; self:showWarningBackupData(\"temperature\"); end\n if data.feeltemperature == \"\" or data.feeltemperature == nil or data.feeltemperature == 0 then data.feeltemperature = data.backupfeeltemperature; self:showWarningBackupData(\"feeltemperature\"); end\n if data.humidity == \"\" or data.humidity == nil or data.humidity == 0 then data.humidity = data.backuphumidity; self:showWarningBackupData(\"humidity\"); end\n if data.windspeed == \"\" or data.windspeed == nil or data.windspeed == 0 then data.windspeed = data.backupwindspeed; self:showWarningBackupData(\"windspeed\"); end\n if data.windgusts == \"\" or data.windgusts == nil or data.windgusts == 0 then data.windgusts = data.backupwindgusts; self:showWarningBackupData(\"windgusts\"); end\n if data.groundtemperature == \"\" or data.groundtemperature == nil or data.groundtemperature == 0 then data.groundtemperature = data.backupgroundtemperature; self:showWarningBackupData(\"groundtemperature\"); end\n if data.airpressure == \"\" or data.airpressure == nil or data.airpressure == 0 then data.airpressure = data.backupairpressure; self:showWarningBackupData(\"airpressure\"); end\n if data.precipitation == \"\" or data.precipitation == nil or data.precipitation == 0 then data.precipitation = data.backupprecipitation; self:showWarningBackupData(\"rain\"); end\n if data.rainFallLast24Hour == \"\" or data.rainFallLast24Hour == nil or data.rainFallLast24Hour == 0 then data.rainFallLast24Hour = data.backuprainFallLast24Hour; self:showWarningBackupData(\"rainFallLast24Hour\"); end\n if data.sunpower == \"\" or data.sunpower == nil or data.sunpower == 0 then data.sunpower = data.backupsunpower; self:showWarningBackupData(\"sunpower\"); end\n if data.visibility == \"\" or data.visibility == nil or data.visibility == 0 then data.visibility = data.backupvisibility; self:showWarningBackupData(\"visibility\"); end\n if data.winddirection == \"\" or data.winddirection == nil or data.winddirection == \" \" then data.winddirection = data.backupwinddirection; self:showWarningBackupData(\"winddirection\"); end\n if data.windspeedBft == \"\" or data.windspeedBft == nil or data.windspeedBft == 0 then data.windspeedBft = data.backupwindspeedBft; self:showWarningBackupData(\"windspeedBft\"); end\n if data.windgusts == \"\" or data.windgusts == nil or data.windgusts == 0 then data.windgusts = data.backupwindgust; self:showWarningBackupData(\"windgusts\"); end\n if data.winddirectiondegrees == \"\" or data.winddirectiondegrees == nil or data.winddirectiondegrees == 0 then data.winddirectiondegrees = data.backupwinddirectiondegrees; self:showWarningBackupData(\"winddirection degrees\"); end\n stationWarning = false -- Set warnings for missing data from station false (off) to show only once\n\n -- Format the data (to prevent error with nil values from json data)\n data.temperature = tostring(data.temperature or 99)\n data.feeltemperature = tostring(data.feeltemperature or 99)\n data.groundtemperature = tostring(data.groundtemperature or 99)\n data.humidity = tostring(string.format(\"%.0f\",data.humidity or 0))\n data.airpressure = tostring(string.format(\"%.0f\",data.airpressure or 0))\n data.windspeed = tostring(string.format(\"%.1f\",(data.windspeed or 0)/3.6))\n data.winddirection = tostring(data.winddirection or \" \")\n data.windspeedBft = tostring(string.format(\"%.0f\",data.windspeedBft or 0))\n data.windgusts = tostring(data.windgusts or 0)\n data.winddirectiondegrees = tostring(data.winddirectiondegrees or 0)\n data.precipitation = tostring(data.precipitation or 0)\n data.rainFallLast24Hour = tostring(data.rainFallLast24Hour or 0)\n data.sunpower = tostring(string.format(\"%.0f\",data.sunpower or 0))\n data.visibility = tostring((data.visibility or 0)/1000)\n data.sunrise = string.gsub(string.sub(data.sunrise,-8,-4),\":\",\".\")\n data.sunset = string.gsub(string.sub(data.sunset,-8,-4),\":\",\".\")\n\n data.humidityabsolute = self:getHumidityAbs() -- Calculate Absolute Humidity\n data.winddirectionarrow = self:setWinddirectionarrow(data.winddirection) -- Setup Winddirection Arrow\n data.airpressuretext = self:setPressuretext(data.airpressure) -- Setup Airpressure Text\n\n self:updateChildDevices() -- Update the Child Devices\n self:setWeathercondition() -- Go to setup Weathercondition\n self:setPropertiesLabels() -- Go to setup Properties and Labels\n end\nend\n\n\nfunction QuickApp:getWeatherData() -- Fetch all weather data from Buienradar url\n self:logging(3,\"QuickApp:getWeatherData()\")\n local url = \"https://data.buienradar.nl/2.0/feed/json\"\n self:logging(3,\"Connecting: \" ..url)\n http:request(url, {\n options={\n method = 'GET'\n },\n success = function(response)\n self:logging(3,\"Response status:\" ..response.status ..\" Headers: \", response.headers[\"Content-Type\"])\n self:logging(3,\"Response: \" ..response.data)\n local jsonTable = json.decode(response.data)\n\n if jsonTable then \n self:onWeatherDataReceived(jsonTable) \n else\n self:warning(\"Temporarily no data from Buienradar Weather\")\n end\n end,\n error = function(error)\n self:error(\"error: \" ..json.encode(error))\n self:updateProperty(\"log\", \"error: \" ..json.encode(error))\n end\n }) \n fibaro.setTimeout(interval*1000, function() \n self:getWeatherData()\n end)\nend\n\n\nfunction QuickApp:createVariables() -- Get all Quickapp Variables or create them\n self:logging(3,\"QuickApp:createVariables()\")\n data = {}\n data.temperature = \"\"\n data.feeltemperature = \"\"\n data.groundtemperature = \"\"\n data.humidity = \"\"\n data.airpressure = \"\"\n data.windspeed = \"\"\n data.winddirection = \"\"\n data.winddirectionarrow = \"\"\n data.windspeedBft = \"\"\n data.windgusts = \"\"\n data.winddirectiondegrees = \"\"\n data.precipitation = \"\"\n data.rainFallLast24Hour = \"\"\n data.sunpower = \"\"\n data.visibility = \"\"\n data.sunrise = \"\"\n data.sunset = \"\" \n \n data.stationname = \"\"\n data.regio = \"\"\n data.weatherdescription = \"\"\n \n data.day1weatherdescription = \"\"\n data.day1mintemperatureMin = \"\"\n data.day1maxtemperatureMax = \"\"\n data.day1mmRainMin = \"\"\n data.day1mmRainMax = \"\"\n data.day1rainChance = \"\"\n data.day1sunChance = \"\"\n data.day1wind = \"\"\n data.day1windDirection = \"\"\n data.day1windDirectionarrow = \"\"\n data.day1 = \"\"\n \n data.day2mintemperatureMin = \"\"\n data.day2maxtemperatureMax = \"\"\n data.day2mmRainMin = \"\"\n data.day2mmRainMax = \"\"\n data.day2rainChance = \"\"\n data.day2sunChance = \"\"\n data.day2wind = \"\"\n data.day2windDirection = \"\"\n \n data.day3mintemperatureMin = \"\"\n data.day3maxtemperatureMax = \"\"\n data.day3mmRainMin = \"\"\n data.day3mmRainMax = \"\"\n data.day3rainChance = \"\"\n data.day3sunChance = \"\"\n data.day3wind = \"\"\n data.day3windDirection = \"\"\n \n data.day4mintemperatureMin = \"\"\n data.day4maxtemperatureMax = \"\"\n data.day4mmRainMin = \"\"\n data.day4mmRainMax = \"\"\n data.day4rainChance = \"\"\n data.day4sunChance = \"\"\n data.day4wind = \"\"\n data.day4windDirection = \"\"\n \n data.day5mintemperatureMin = \"\"\n data.day5maxtemperatureMax = \"\"\n data.day5mmRainMin = \"\"\n data.day5mmRainMax = \"\"\n data.day5rainChance = \"\"\n data.day5sunChance = \"\"\n data.day5wind = \"\"\n data.day5windDirection = \"\"\n \nend\n\n\nfunction QuickApp:getQuickAppVariables() -- Manage the QuickApp variables\n interval = tonumber(self:getVariable(\"interval\")) \n stationID = tonumber(self:getVariable(\"stationID\")) \n backupstationID = tonumber(self:getVariable(\"backupstationID\")) \n timeout = tonumber(self:getVariable(\"timeout\")) \n setGlobalVar = string.lower(self:getVariable(\"setGlobalVar\"))\n stationWarning = string.lower(self:getVariable(\"stationWarning\"))\n debugLevel = tonumber(self:getVariable(\"debugLevel\"))\n\n -- Check existence of the mandatory variables, if not, create them with default values \n if interval == \"\" or interval == nil then\n interval = \"601\" -- Default interval in seconds (Buienradar updates every 10 minues)\n self:setVariable(\"interval\",interval)\n self:trace(\"Added QuickApp variable interval\")\n interval = tonumber(interval)\n end\n if stationID == \"\" or stationID == nil then \n stationID = \"6260\" -- Default station ID is 6260 (Meetstation De Bilt)\n self:setVariable(\"stationID\",stationID)\n self:trace(\"Added QuickApp variable stationID\")\n stationID = tonumber(stationID)\n end\n if backupstationID == \"\" or backupstationID == nil then \n backupstationID = \"6260\" -- Default backup station ID is 6260 (Meetstation De Bilt)\n self:setVariable(\"backupstationID\",backupstationID)\n self:trace(\"Added QuickApp variable backupstationID\")\n backupstationID = tonumber(backupstationID)\n end\n if timeout == \"\" or timeout == nil then\n timeout = \"5\" -- Default value for timeout response in seconds\n self:setVariable(\"timeout\",timeout)\n self:trace(\"Added QuickApp variable timeout\")\n timeout = tonumber(timeout)\n end\n if debugLevel == \"\" or debugLevel == nil then\n debugLevel = \"1\" -- Default value for debugLevel response in seconds\n self:setVariable(\"debugLevel\",debugLevel)\n self:trace(\"Added QuickApp variable debugLevel\")\n debugLevel = tonumber(debugLevel)\n end\n if setGlobalVar == \"\" or setGlobalVar == nil then \n setGlobalVar = false -- Default SetGlobalVar is falso (No use of Global Variables)\n self:setVariable(\"setGlobalVar\",tostring(setGlobalVar))\n self:trace(\"Added QuickApp variable setGlobalVar\")\n end\n if setGlobalVar == \"true\" then \n setGlobalVar = true \n else\n setGlobalVar = false\n end\n if stationWarning == \"\" or stationWarning == nil then \n stationWarning = true\n self:setVariable(\"stationWarning\",tostring(stationWarning))\n self:trace(\"Added QuickApp variable stationWarning\")\n end\n if stationWarning == \"true\" then \n stationWarning = true \n else\n stationWarning = false\n end\nend \n\n\nfunction QuickApp:setupChildDevices() -- Setup Child Devices\n local cdevs = api.get(\"/devices?parentId=\"..self.id) or {} -- Pick up all Child Devices\n function self:initChildDevices() end -- Null function, else Fibaro calls it after onInit()...\n\n if #cdevs == 0 then -- If no Child Devices, create them\n local initChildData = { \n {className=\"brTemperature\", name=\"Temperature\", type=\"com.fibaro.temperatureSensor\", value=0},\n {className=\"brFeelTemp\", name=\"Feel Temperature\", type=\"com.fibaro.temperatureSensor\", value=0},\n {className=\"brGroundTemp\", name=\"Ground Temperature\", type=\"com.fibaro.temperatureSensor\", value=0},\n {className=\"brHumidity\", name=\"Humidity\", type=\"com.fibaro.humiditySensor\", value=0},\n {className=\"brHumidityAbs\", name=\"Absolute Humidity\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brAirpressure\", name=\"Airpressure\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brWindspeedMS\", name=\"Windspeed m/s\", type=\"com.fibaro.windSensor\", value=0},\n {className=\"brWindspeedKMH\", name=\"Windspeed km/h\", type=\"com.fibaro.windSensor\", value=0},\n {className=\"brWindspeedBFT\", name=\"Windspeed BFT\", type=\"com.fibaro.windSensor\", value=0},\n {className=\"brWindgusts\", name=\"Windgusts\", type=\"com.fibaro.windSensor\", value=0},\n {className=\"brWinddirection\", name=\"Winddirection\", type=\"com.fibaro.windSensor\", value=0},\n {className=\"brPrecipitation\", name=\"Rain\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brLast24h\", name=\"Rain Last 24h\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brSunpower\", name=\"Sunpower\", type=\"com.fibaro.powerMeter\", value=0},\n {className=\"brVisibility\", name=\"Visibility\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brSunset\", name=\"Sunset\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brSunrise\", name=\"Sunrise\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brSunChance\", name=\"Sun Chance +1\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brMinMinTemp\", name=\"Min Temp +1\", type=\"com.fibaro.temperatureSensor\", value=0},\n {className=\"brMaxMaxTemp\", name=\"Max Temp +1\", type=\"com.fibaro.temperatureSensor\", value=0},\n {className=\"brRainChance\", name=\"Rain Chance +1\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brMinRain\", name=\"Min Rain +1\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brMaxRain\", name=\"Max Rain +1\", type=\"com.fibaro.multilevelSensor\", value=0},\n {className=\"brWindMS\", name=\"Wind m/s +1\", type=\"com.fibaro.windSensor\", value=0},\n {className=\"brWindKMH\", name=\"Wind km/h +1\", type=\"com.fibaro.windSensor\", value=0},\n }\n for _,c in ipairs(initChildData) do\n local child = self:createChildDevice(\n {name = c.name,\n type=c.type,\n value=c.value,\n unit=c.unit,\n initialInterfaces = {},\n },\n _G[c.className] -- Fetch class constructor from class name\n )\n child:setVariable(\"className\",c.className) -- Save class name so we know when we load it next time\n end \n else \n for _,child in ipairs(cdevs) do\n local className = getChildVariable(child,\"className\") -- Fetch child class name\n local childObject = _G[className](child) -- Create child object from the constructor name\n self.childDevices[child.id]=childObject\n childObject.parent = self -- Setup parent link to device controller \n end\n end\nend\n\n\nfunction QuickApp:onInit() \n __TAG = fibaro.getName(plugin.mainDeviceId) ..\" ID:\" ..plugin.mainDeviceId\n self:debug(\"QuickApp:onInit()\") \n self:setupChildDevices()\n \n if not api.get(\"/devices/\"..self.id).enabled then\n self:warning(\"Device\", fibaro.getName(plugin.mainDeviceId), \"is disabled\")\n return\n end\n \n self:getQuickAppVariables() \n self:createVariables() \n http = net.HTTPClient({timeout=timeout})\n self:getWeatherData()\nend\n\n-- EOF "}]}