home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.95k stars 31.01k forks source link

NWS shows EU METRARs falsely as „unavailable “ #123983

Open WH3080 opened 3 months ago

WH3080 commented 3 months ago

The problem

I have been using NWS to pull METRARs for EDDB (Berlin Brandenburg Airport) for many years. NOAA (NWS) also continues to provide them: https://aviationweather.gov/data/metar/?id=EDDB&hours=0&decoded=yes&include_taf=yes But the home assistant has the integration no longer pulls them. They are reported as „unavailable“, but clearly that is not true. I have tried to delete and reinstall this integration several times. No like luck. US METAR codes work like a charm.

What version of Home Assistant Core has the issue?

core-2024.8.1

What was the last working version of Home Assistant Core?

?

What type of installation are you running?

Home Assistant OS

Integration causing the issue

https://www.home-assistant.io/integrations/nws/

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Version core-2024.8.1
Installation type   Home Assistant OS
Development false
Supervisor  true
Docker  true
User    root
Virtual environment false
Python version  3.12.4
Operating system family Linux
Operating system version    6.6.31-haos-raspi
CPU architecture    aarch64
Timezone    Europe/Berlin
Configuration directory /config
Home Assistant Community Store

MANAGE
GitHub API  ok
GitHub Content  ok
GitHub Web  ok
GitHub API Calls Remaining  5000
Installed Version   1.34.0
Stage   running
Available Repositories  1387
Downloaded Repositories 9
Home Assistant Cloud

MANAGE
Logged In   false
Reach certificate server    ok
Reach authentication server ok
Reach Home Assistant Cloud  ok
Home Assistant Supervisor

Host operating system   Home Assistant OS 13.0
Update channel  stable
Supervisor version  supervisor-2024.08.0
Agent version   1.6.0
Docker version  26.1.4
Disk total  146.0 GB
Disk used   28.9 GB
Healthy true
Supported   true
host_connectivity   true
supervisor_connectivity true
ntp_synchronized    true
virtualization  
Board   rpi4-64
Supervisor API  ok
Version API ok
Installed add-ons   Mosquitto broker (6.4.1), File editor (5.8.0), motionEye (0.20.0), ESPHome (2024.7.3), rtl_433 (0.5.2), rtl_433 MQTT Auto Discovery (0.8.2), Terminal & SSH (9.14.0), VLC (0.3.0), Grafana (10.0.0), InfluxDB (5.0.0), rtlamr2mqtt (2.3.4), Matter Server (6.4.1), WireGuard (0.10.2), Whisper (2.1.2), Piper (1.5.2), openWakeWord (1.10.0)
Dashboards

MANAGE
Dashboards  5
Resources   2
Views   3
Mode    storage
Recorder

Oldest run start time   August 10, 2024 at 10:41
Current run start time  August 14, 2024 at 14:51
Estimated database size (MiB)   897.56 MiB
Database engine sqlite
Database version    3.45.3

Additional information

No response

home-assistant[bot] commented 3 months ago

Hey there @matthewflamm, @kamiyo, mind taking a look at this issue as it has been labeled with an integration (nws) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `nws` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign nws` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


nws documentation nws source (message by IssueLinks)

WH3080 commented 3 months ago

Logger: homeassistant.components.nws
Source: helpers/update_coordinator.py:367
integration: National Weather Service (NWS)(documentation, issues) 
First occurred: August 14, 2024 at 14:51:12 (18occurrences) 
Last logged: 12:38:14

{ "correlationId": "a5420fe", "title": "Data Unavailable For Requested Point", "type": "https://api.weather.gov/problems/InvalidPoint", "status": 404, "detail": "Unable to provide data for requested point 52.3625,13.5019", "instance": "https://api.weather.gov/requests/a5420fe" }

WH3080 commented 3 months ago

This API would actually give us METRAR data: https://aviationweather.gov/data/api/#/Data/dataMetars

The Lat Lon version apparently only works in the US nowadays

MatthewFlamm commented 3 months ago

The API is the NWS API. This error means that this lat/lon location is not supported by the API. EDDB is also not supported. See https://api.weather.gov/stations/EDDB

WH3080 commented 3 months ago

The API is the NWS API. This error means that this lat/lon location is not supported by the API. EDDB is also not supported. See https://api.weather.gov/stations/EDDB

Unless you want to restrict this integration to the US, which it was not before, it would make sense to switch the API to this one: https://aviationweather.gov/data/api/#/Data/dataMetars

And yes the NWS does provide METARs not just for EDDB ...

https://aviationweather.gov/api/data/metar?ids=EDDB&taf=true

... but virtually all airports in the world, i.e. accurate weather free of charge for almost any place in the world.

kamiyo commented 3 months ago

Switching to aviation weather for this integration doesn't seem like a good idea to me. For one, I don't think it gives forecasts, which imo a weather integration would need.

It is a really cool data source though, I could see it being a separate integration. Or your own rest sensor: https://www.home-assistant.io/integrations/sensor.rest/

WH3080 commented 3 months ago

Switching to aviation weather for this integration doesn't seem like a good idea to me. For one, I don't think it gives forecasts, which imo a weather integration would need.

It is a really cool data source though, I could see it being a separate integration. Or your own rest sensor: https://www.home-assistant.io/integrations/sensor.rest/

Well, you are the developers I am just an enthusiast who may know a thing or two about aviation.

METARs (Meteorological Terminal Aviation Routine Weather Report) are the most timely and accurate weather sources.

The METAR and TAF data pages provide access to raw, tabular, and decoded output that automatically refreshes every five minutes. The page is designed for quick lookups and printability.

METARs are updated at least once an hour or more frequently if anything changes (SPECI) as people's life depends on it while traveling by air. They actually include a lot more measured, not extrapolated weather detail.

And yes, they also include very accurate forecasts (TAF = Terminal Aerodrome Forecasts).

See here for METAR:

https://en.wikipedia.org/wiki/METAR

See here for TAF:

https://en.m.wikipedia.org/wiki/Terminal_aerodrome_forecast

https://www.dwd.de/EN/specialusers/aviation/download/products/metar_taf/metar_trend_taf.pdf

I see your point about separating aviation weather from the rest of NWS. However until 2023 this integration delivered both. Now there are two APIs.

kamiyo commented 3 months ago

If anything changed after 2023, it seems to me to be because of NWS. We really can't do anything about it as we only rely on api.weather.gov. You can maybe file a request/issue with them to reinstate the international stations. I think there's a link on their website: https://www.weather.gov/documentation/services-web-api

I hope I don't come across as dismissing the importance and accuracy of METAR and TAF. But this integration is focused, partially for maintainability, and partially for ease of use for a core integration, on using api.weather.gov. After researching a bit for the below solution using a custom rest sensor and weather template, it seems the TAF forecast data is not easily mapped to what homeassistant expects. Parsing the METAR and TAF would require implementation and extensive testing, it would beyond the scope of this integration, and frankly would require someone knowledgeable about the data (or an existing decoding library).

Maybe someone will see this and write a custom integration (or propose a core one) for aviation weather, which I agree has international applicability (as opposed to NWS which is US-centered). For what it's worth, there are other people on the weather-gov github discussion boards complaining about the consistency/stability of NWS compared to aviationweather.gov.

I would encourage you, if you have familiarity with python or know someone who does, to see if you can come up with an integration for the aviation weather.

In the meantime, while I'm no means an expert/power user of home assistant, I think I've come up with a sample (mostly untested) sensor that might help you get started:

rest:
  - resource: "https://aviationweather.gov/api/data/metar?ids=EDDB&format=json"
    scan_interval: 5 # update minutes
    sensor:
      - name: "EDDB METAR"
        value_template: "{{ value_json[0]['rawOb'] }}"
      - name: "EDDB Condition"
        value_template: "{{ value_json[0]['wxString'] }}" # in the case of null, use clouds[0].cover?
      - name: "EDDB Temperature"
        value_template: "{{ value_json[0]['temp'] }}"
# ... etc for all the sensors you want to create
  - resource: "https://aviationweather.gov/api/data/taf?ids=EDDB&format=json"
    scan_interval: 5
    sensor:
      - name: "EDDB Forecast"
        value_template: "{{ value_json[0]['name'] }}"
        json_attributes_path: "$.[0]"
        json_attributes:
         - fcsts
# Then you do this to create a weather template
weather:
  - platform: template
    name: "Aviation Weather"
    condition_template: "{{ states('sensor.eddb_condition') }}"
# ideally, parse code i.e. "-RA" to description "Light Rain"
    temperature_template: "{{ states('sensor.eddb_temperature') }}"
# ... etc
    forecast_hourly_template: "{{ state_attr('eddb_forecast', 'fcsts') }}"
# but need to transform data to match what the weather entity wants for forecasts.
# From what I understand, it will be a bit hard to parse the TAF to evenly-spaced time periods
# for either hourly, daily, or twice_daily forecasts.
# See https://www.home-assistant.io/integrations/weather.template/

So, the easiest way would be to use an existing METAR/TAF parsing library, and write an integration using that. But with lots of will, you can probably make it work using homeassistant's yaml.

WH3080 commented 3 months ago

That is very kind of you! I already tried to experiment with the RESTful component and NWS Aviation Weather API, but couldn't get it to work. Your template helps a great deal and once I have a possibly more interesting version I will share it. The US NWS is a fantastic resource for the entire world.

issue-triage-workflows[bot] commented 2 hours ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.