Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Weerlive API v2 #120

Merged
merged 14 commits into from
Feb 25, 2024
Merged

Update to Weerlive API v2 #120

merged 14 commits into from
Feb 25, 2024

Conversation

golles
Copy link
Owner

@golles golles commented Feb 17, 2024

If you are willing to test out this update, I would really appreciate your feedback!

See the draft release notes in my comment below, and the updated README.md as there are some breaking changes.
Please answer the following questions:

  1. What do you think about entity and attribute naming?
    see en.json and nl.json, please comment in the pull request files section to keep it organized
  2. Are there sensors that are disabled by default that should be enabled by default?
  3. How painful is the breaking change where entity names and id's are changed?
  4. Anything else on your mind?

Tasks list:

  • Weather
    • Implement 5-day daily forecast
    • Implement 24-hour hourly forecast
  • Binary sensors and sensors
    • Add more sensors
    • Improve SensorDescription with value_fn and attr_fn instead of subclassing = less code
    • A better way to get values from the API and handling of time values
  • Work out a migration path (Note: Done but not perfect as old entities are removed...)
  • Update readme
    • General content
    • Explain timestamp
    • Explain how to enable sensors
    • Screenshots
  • Testing
    • More test cases, each sensor state/attributes
    • Write a detailed test for async_migrate_entry
    • Run in my production HA
    • Ask for feedback

Known bugs:

  • Warning sensor, next warning attribute isn't working properly yet date (wrsch_g) and timestamp (wrsch_gts) format from the API are inconsistent, if wrsch_gts becomes an int, no action is requited.

@golles
Copy link
Owner Author

golles commented Feb 17, 2024

Release Notes (Draft)

Before proceeding with the update, please review the comprehensive release notes, as there are breaking changes.

Version 2.0.0

Exciting news! Version 2.0.0 is here, featuring a collaboration with Weerlive, unleashing a new API with enhanced capabilities for all users. Thank you, Martijn!

New features:

  • Extended daily forecast: The weather entity now provides a 5-day daily forecast, up from the previous 3 days.
  • Hourly forecast: The weather entity is extended with hourly forecast for the upcoming 24 hours.
  • Entity names, attribute names and some states are now translated into English and Dutch and this can easily be extended into other languages.

Breaking changes:

To align with the latest developments:

  • Python Version: The component now utilizes Python 3.12, in line with HA 2024.2 release.
  • Deprecated forecast attribute: The deprecated forecast attribute in the weather entity has now been removed, as it won't be supported after 2024.3.
  • All the previous entities will be removed during the upgrade and new ones are being created, Entity name (and unique_id) and attributes are renamed so you need to update your dashboards, automations and scripts (I'm really really sorry about this!). Better unique id's are now created to prevent this in the future.

New entities:

In response to user feedback and the deprecation of the forecast attributes in HA, several new entities have been introduced. Most of these sensors are not enabled by default, allowing you to choose the ones you find valuable. The amount of sensors enabled doesn't impact the API limits.

Binary sensors

Name (EN) Name (NL) Attributes Notes
Sun Zon Sunrise, Sunset, Sun chance today, tomorrow and day after tomorrow Times of today, in UTC, frontend will convert this into your local time
Warning Waarschuwing Title, Description, Code, Next code, Next warning Code has its own entity, see Weather code below

Sensors

Normal sensors:

Name (EN) Name (NL) Attributes Notes
Dew point Dauwpunt Unit configurable
Solar irradiance Globale stralingsintensiteit
Wind chill Gevoelstemperatuur Unit configurable
Air pressure Luchtdruk Unit configurable
Humidity Luchtvochtigheid
Max temperature today Max temperatuur vandaag Unit configurable
Max temperature tomorrow Max temperatuur morgen Unit configurable
Min temperature today Min temperatuur vandaag Unit configurable
Min temperature tomorrow Min temperatuur morgen Unit configurable
Precipitation today Neerslag vandaag
Precipitation tomorrow Neerslag morgen
Description Omschrijving State is in Dutch
Temperature Temperatuur Unit configurable
Weather forecast Weersverwachting State is in Dutch
Wind speed Windsnelheid Bearing, Degree, Beaufort and Knots Unit configurable
Weather code Weercode Raw state is in Dutch
Visibility Zicht Unit configurable

Diagnostic sensors:

Name (EN) Name (NL) Notes
Location Plaats
Remaining API requests Resterende API verzoeken
Latest update Laatste update Server side update time

Weather

The weather entity contains all the weather information, ideal for displaying a comprehensive overview in the Home Assistant frontend. It includes both a daily forecast spanning up to 5 days and an hourly forecast covering up to 24 hours.

Daily forecast attributes:

Attribute Notes
datetime Times in UTC, frontend will convert this into your local time
condition
templow
temperature
precipitation_probability in a percentage
wind_bearing
wind_speed
wind_speed_bft Not officially supported, but nice addition
sun_chance Not officially supported, but nice addition

Hourly forecast attributes:

Attribute Notes
datetime Times in UTC, frontend will convert this into your local time
condition
temperature
precipitation_probability in millimeters
wind_bearing
wind_speed
wind_speed_bft Not officially supported, but nice addition
solar_irradiance Not officially supported, but nice addition

Thank you for your continued support and feedback!

Copy link

codecov bot commented Feb 17, 2024

Codecov Report

Attention: Patch coverage is 99.24242% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 96.32%. Comparing base (30748e8) to head (ec9d04f).

Files Patch % Lines
custom_components/knmi/api.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #120      +/-   ##
==========================================
+ Coverage   95.58%   96.32%   +0.74%     
==========================================
  Files           9        9              
  Lines         362      354       -8     
==========================================
- Hits          346      341       -5     
+ Misses         16       13       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

README.md Outdated Show resolved Hide resolved
@golles
Copy link
Owner Author

golles commented Feb 17, 2024

Scherm­afbeelding 2024-02-17 om 19 08 11

API is returning old data, I could consider a workaround for daily and hourly forecasts that items in the past shouldn't be added. Will inform the supplier as well (As this shouldn't happen, this isn't required for v2 release, can still do this later when needed)

@martijnrusschen
Copy link

This is really interesting thanks for taking the effort to migrate the APIs. Would it be possible to make a pre-release out of this? That makes it easier to test the changes using HACS.

@golles
Copy link
Owner Author

golles commented Feb 22, 2024

This is really interesting thanks for taking the effort to migrate the APIs. Would it be possible to make a pre-release out of this? That makes it easier to test the changes using HACS.

Thanks, yes will make a pre-release later today

@hmmbob
Copy link
Contributor

hmmbob commented Feb 24, 2024

Works fine so far, and thanks for the seperate sensors - it simplifies my code big time.

Q: did sensor.knmi_korte_dagverwachting get dropped? I used it in my morning briefing :)
Of course there is sensor.knmi_omschrijving, but that tends to be more verbose.

@martijnrusschen
Copy link

Working as expected here for the past few days. I like the additional sensors and forecasts.

q: Is there a way to get wind direction forecast? I was able to extract a separate sensor for the current wind direction, but would be great to get more wind direction details if possible.

@golles
Copy link
Owner Author

golles commented Feb 24, 2024

Works fine so far, and thanks for the seperate sensors - it simplifies my code big time.

Q: did sensor.knmi_korte_dagverwachting get dropped? I used it in my morning briefing :) Of course there is sensor.knmi_omschrijving, but that tends to be more verbose.

This value is now in the sensor with the name Weather forecast/Weersverwachting

@golles
Copy link
Owner Author

golles commented Feb 25, 2024

q: Is there a way to get wind direction forecast? I was able to extract a separate sensor for the current wind direction, but would be great to get more wind direction details if possible.

I think this is too specific, for this, I would suggest to use the weather.get_forecasts service with either hourly or daily as a type

Copy link

sonarcloud bot commented Feb 25, 2024

@golles golles merged commit dd08339 into main Feb 25, 2024
8 checks passed
@golles golles deleted the api-v2 branch February 25, 2024 18:53
Repository owner locked as resolved and limited conversation to collaborators Feb 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants