Weather Configuration
Current weather updates can be retrieved from the weather APIs.
To retrieve the latest weather updates:
-
In the controller app, go to
. -
Click Add new script. Schedule script window is displayed.
-
Enter the details, and click Save.
-
Click Editor icon in the newly created script.
-
In the space highlighted, paste the sample code provided below.
Sample Code
The following sample code demonstrates how to fetch weather data from online weather service providers. This is just an example and may work with some service providers, but script changes may be needed for others, depending on the usage of their APIs.
require('json') require("ltn12") require('ssl.https') local locationID = 'Use Location ID for Customer Address as per service provider format' local apikey = 'API Key as per service provider format' local metric = 'true' url = 'api url as per the given format from service provider’ Note: E.g: ‘url'..location..'?apikey='..apikey..'=' ..metric data, error = ssl.https.request(url) log(data) data = json.pdecode(data) if not data then alert('Weather: cannot parse data') return end log(data) --- Set Day Outlook SetUserParam(0,255, math.floor(data.DailyForecasts[1].Temperature.Minimum.Value + 0.5)) SetUserParam(0,256, math.floor(data.DailyForecasts[1].Temperature.Maximum.Value + 0.5)) --Set day or night icon for now just use 6:00 pm 6:00 am as night and all else is the day - later might make it do this using sunrise and sunset if ((tonumber(os.date('%H', os.time())) < 6 ) or (tonumber(os.date('%H', os.time())) >17)) then SetUserParam(0,257,data.DailyForecasts[1].Night.Icon) else SetUserParam(0,257,data.DailyForecasts[1].Day.Icon) end
-
To retrieve the weather data, create the user parameter objects in the Configurator tab as referred in the above sample script (0/250/255, 0/250/256, 0/250/257).
NOTE: The same objects are used in the Manager Config weather settings.