Hello X10 world, hope all is well. I’ve noticed some inaccuracies with the forecasts for my Weather Widget from OpenWeatherSource lately and finally had a chance to dig into it.
I’ve been delving into the world of API calls at work so I thought it was a good chance to play around with some of the API calls that HomeGenie was using for the weather.
Essentially, the calls to OopenWeatherMap are done as follows:
- Current Conditions:
“https://api.openweathermap.org/data/2.5/weather?q=” + location + “&lang=” + language + “&units=metric&appid=” + apikey
so:
https://api.openweathermap.org/data/2.5/weather?q=Charlton, US&lang=EN&units=metric&appid=
That returns:
{“coord”:{“lon”:-71.97,“lat”:42.14},“weather”:[{“id”:804,“main”:“Clouds”,“description”:“overcast clouds”,“icon”:“04d”}],“base”:“stations”,“main”:{“temp”:8.9,“feels_like”:0.48,“temp_min”:8,“temp_max”:11.11,“pressure”:1001,“humidity”:65},“visibility”:16093,“wind”:{“speed”:9.8,“deg”:180,“gust”:16.5},“clouds”:{“all”:90},“dt”:1587484856,“sys”:{“type”:1,“id”:5231,“country”:“US”,“sunrise”:1587463015,“sunset”:1587512138},“timezone”:-14400,“id”:4932823,“name”:“Charlton”,“cod”:200}
Then another call is made for the forecast:
“https://api.openweathermap.org/data/2.5/forecast?q=” + location + “&lang=”+language+"&units=metric&appid=" + apikey
so:
https://api.openweathermap.org/data/2.5/forecast?q=Charlton, US&lang=EN&units=metric&appid=
that returns a bunch of stuff - and if you look at the data and specifically this field:
“dt_txt”:“2020-04-22 06:00:00”
you can see that it appears to be a forecast in increments of 3 hours
In the Program code for OpenWeatherMap, there is this:
var nextDay = DateTime.UtcNow.AddDays(1); nextDay = nextDay.Date + new TimeSpan(12, 0, 0);
I believe that is setting the time portion for the date/time stamp to be noon? Or is it 12 hours from the current time ?
The code then appears to try and find the matching date/time entry for the next 3 days, matching the date and time. I’m not 100% certain but I am wondering if the way this is trying to match may be off or not. I would assume the forecast would just be at a set time every day for the next 3 days ?