Skip to content

Add Comprehensive Weather Observation Sensors#48

Open
hmmbob wants to merge 2 commits intoPaulVanSchayck:mainfrom
hmmbob:add-observation-sensors
Open

Add Comprehensive Weather Observation Sensors#48
hmmbob wants to merge 2 commits intoPaulVanSchayck:mainfrom
hmmbob:add-observation-sensors

Conversation

@hmmbob
Copy link
Contributor

@hmmbob hmmbob commented Feb 8, 2026

Summary
This PR adds complete support for KNMI observation data by introducing ten new weather sensors with proper Home Assistant integration. It reuses data already available in the integration to expose separate sensors, and includes a smart cloud‑coverage calculation plus a 16‑point cardinal wind‑direction ENUM with translations.

New Sensors

  • Temperature - Current outside temperature with 1 decimal precision
  • Humidity - Relative humidity percentage
  • Visibility - Visibility distance in meters
  • Pressure - Atmospheric pressure in hectopascals
  • Wind Speed - Current wind speed with 1 decimal precision
  • Wind Gust - Wind gust speed with 1 decimal precision
  • Dew Point - Dew point temperature
  • Wind Azimuth - Wind direction in degrees
  • Cloud Coverage - Okta-to-percentage conversion with proper handling of fog/obscured conditions
  • Wind Direction - Cardinal direction ENUM (N, NNE, NE, etc.) with English and Dutch translations

Technical Implementation

  • All sensors use proper Home Assistant device classes and state classes
  • Generic NLObservationRangeSensor class eliminates code duplication for standard observations
  • Specialized sensors for cloud coverage (okta unit handling) and wind direction (degree-to-cardinal conversion)
  • Comprehensive error handling and debug logging
  • Station distance and station name marked as diagnostic sensors
  • Full translation support for English and Dutch
image

@hmmbob
Copy link
Contributor Author

hmmbob commented Feb 8, 2026

Not sure what to do to get ruff to pass - error isn't very clear

@vandermark1977
Copy link

Is it possible to add tomorrow temperature sensors? Both 'regular' (max) and 'low'.

@hmmbob
Copy link
Contributor Author

hmmbob commented Feb 8, 2026

Quite probably yes, but that's in another dataset so I'll have a look at that separately

@hmmbob
Copy link
Contributor Author

hmmbob commented Feb 15, 2026

Is it possible to add tomorrow temperature sensors? Both 'regular' (max) and 'low'.

That was very easy. Added to this PR in e2a0cad

image

@PaulVanSchayck
Copy link
Owner

I appreciate the effort @hmmbob! I have been making progress with a solution to issue #38. I want to get that done before adding the sensors, as that already makes breaking changes to the service/entity structure. Adding more sensors before that only makes the breaking changes larger.

Hopefully I'll have a draft pr open soon.

@hmmbob
Copy link
Contributor Author

hmmbob commented Feb 15, 2026

I appreciate the effort @hmmbob! I have been making progress with a solution to issue #38. I want to get that done before adding the sensors, as that already makes breaking changes to the service/entity structure. Adding more sensors before that only makes the breaking changes larger.

Hopefully I'll have a draft pr open soon.

Cool. But, what would the issue be then? About selecting the station?
Was just thinking about that as well. I like the auto-select as well, maybe we can have the user choose during onboarding between "auto" (current behavior) and a fixed station (that we could probably pre-filter on available data already).

Checking, 'cause the spinner showing in the observation weather entity more info section was a HA bug and was fixed on their side.

And I'll rebase after the changes, no worries.

@PaulVanSchayck
Copy link
Owner

See #38 (comment) for my current thoughts on how to handle the station selection. It's indeed along the same lines you're thinking.

@vandermark1977
Copy link

Thank you both for your work regarding this integration! I look forward to the new version(s)

@PaulVanSchayck
Copy link
Owner

I'm thinking we could actually already implement the forecast sensors right now. @hmmbob would you be willing to cherry-pick those sensors and create a new PR out of it?

@PaulVanSchayck
Copy link
Owner

I'm happy to take a look at a rebased version of this PR. It needs a bit of work after the changes made for version 0.7.0.

@hmmbob hmmbob force-pushed the add-observation-sensors branch from 7b9549b to cf8ebac Compare March 12, 2026 08:07
@hmmbob
Copy link
Contributor Author

hmmbob commented Mar 12, 2026

I think it's ready to go!

Sorry, haven't had time to test 0.7.0 before today, wasn't at home.... :-)

@hmmbob hmmbob marked this pull request as ready for review March 12, 2026 08:36
Copy link
Owner

@PaulVanSchayck PaulVanSchayck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've added some comments. Some are maybe a bit pedantic. I hope you don't mind.

While reviewing, I noticed I broke the weather condition code. See PR #80

"name": "Windsnelheid"
},
"observations_wind_gust": {
"name": "Windvlaag"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windstoten

value_fn=_get_cloud_coverage,
),
ObservationSensorDescription(
key="wind_direction",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this and all related functions and keys wind_direction_cardinal?

value_fn=lambda data: _get_observation_param(data, "td"),
),
ObservationSensorDescription(
key="wind_azimuth",
Copy link
Owner

@PaulVanSchayck PaulVanSchayck Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this wind_direction? I don't think azimuth is incorrect, but only a bit unusual to use in the context of wind direction.

temp_key: str | None = None


CARDINAL_DIRECTIONS = [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be safe to import this from VALID_CARDINAL_DIRECTIONS from components.weather.significant_change?

translation_key="observations_cloud_coverage",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
suggested_display_precision=1,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
suggested_display_precision=1,
suggested_display_precision=0,

We only got 8 different values.

value_fn=lambda data: _get_observation_param(data, "dd"),
),
ObservationSensorDescription(
key="cloud_coverage",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an icon? Maybe mdi:cloud-percent?

Comment on lines +94 to +95
- `weather.{location}_observations` for current weather observations
- `weather.{location}_forecast` for the weather forecast
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `weather.{location}_observations` for current weather observations
- `weather.{location}_forecast` for the weather forecast
- `weather.weer_{location}_observations` for current weather observations
- `weather.weer_{location}_forecast` for the weather forecast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants