ThingPulse / esp8266-weather-station

ESP8266 Weather Station library supporting OpenWeatherMap, Aeris and other sources
MIT License
1.06k stars 359 forks source link

Add High and Low Temperature for the current day #172

Closed sungkhum closed 3 years ago

sungkhum commented 4 years ago

8<------------------------ FEATURE REQUEST ------------------------------------

Missing feature

I would like to be able to display the high and low temperature for the current day.

Justification

Before I walk out the door I would like to know how hot it is going to get (do I need a warm jacket all day, or can I just brave the cold in the morning because it will be warmer?).

Workarounds

None yet. I am trying to understand what forecast data is currently being fed into the program. How is "allowedHoursCount" being used? Is all the data being loaded, or just select hours? To get the high and low I need access to all the data in the forecast api, but not sure how it is being fed right now. Do you think this is doable?

Some code from someone else doing what I would like to see: https://github.com/zagortenay333/Harmattan/blob/master/.harmattan-assets/parse_weather

8<------------------------ END FEATURE REQUEST --------------------------------

marcelstoer commented 4 years ago

It's primarily a shortcoming in the OWM API we'd have to work around: https://openweathermap.org/forecast5#min We suggested to them to improve their API but they think it "works as designed".

sungkhum commented 4 years ago

Yes, a weird decision on OWM API's part. But in the current code, does "allowedHoursCount" skip entries in the forecast json? I can't quite figure out what is going on in the code. Wondering if I would need to modify to have a new loop that grabs all the temperature for the day and stores the high and low or if I can use the current loop...

sungkhum commented 4 years ago

I wonder if it actually would be easier to change APIs to DarkSky: https://darksky.net/dev/docs

sungkhum commented 4 years ago

This code connects to DarkSky - but I can't get it to work with my ESP8266 https://github.com/Bodmer/DarkSkyWeather

marcelstoer commented 4 years ago

But in the current code, does "allowedHoursCount" skip entries in the forecast json?

Yes, the variable naming is a bit unfortunate but that's exactly what's happening.

See for example https://github.com/ThingPulse/esp8266-weather-station/blob/master/examples/WeatherStationDemo/WeatherStationDemo.ino#L249 and one of our other projects https://github.com/ThingPulse/esp8266-weather-station-color/blob/master/esp8266-weather-station-color.ino#L300

Those allowedHours arrays contain the hours (0-23) for which forecasts should be parsed rather than discarded. The number of elements in this array effectively defines how many forecast records per day you'll get. If it's just 12 the only forecast considered is the one at 12 noon. Your selection of "hours" has to be aligned with the OWM "5 day / 3 hour forecast data" of course.

In order to provide daily high/low temps you would have to tweak the below fragment. Rather than returning immediately when you found out that the forecast is for an hour you chose to ignore you always store the temp in two new fields on the data structure (OpenWeatherMapForecastData) if it's higher/lower than the existing values for the same day.

https://github.com/ThingPulse/esp8266-weather-station/blob/821c4507958b0e0788db9c9f713d9d30854513be/src/OpenWeatherMapForecast.cpp#L112-L132

marcelstoer commented 4 years ago

It goes without saying that a PR to that effect would be highly welcome 😄

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.