FL550 / dwd_weather

Deutscher Wetterdienst integration for Home-Assistant
MIT License
194 stars 12 forks source link

Add support for custom weather stations #13

Closed csoltenborn closed 3 years ago

csoltenborn commented 3 years ago

Is your feature request related to a problem? Please describe. In the city I live in (Paderborn, Germany), the DWD does not have any weather stations for some reason. The next station is around 15km away from me. In contrast, there is a weather station in the city which makes its measurements publicly available and allows people to use it. Of course, this station does not provide forecasts.

Describe the solution you'd like I'd like to be able to receive the data of the current weather conditions from another freely available data source. This includes the following data:

Describe alternatives you've considered I have not considered any alternatives :-)

Additional context In an ideal world ;-), the dwd_weather integration would support adapters for publicly available weather station, and would make existing adapters available to all its users via the UI. An adapter could e.g. consist of a python class inheriting from a base adapter class (provided by the integration), and implementing the following:

The integration would then receive the data using the URL whenever appropriate, ask the adapter to parse it afterwards, and then make use of the parsed data.

Here's some example code - note that the adapter should probably provide more information, e.g. location of weather station, human readable name etc.

import sys
from abc import ABC, abstractmethod

# to be provided by the integration
class WeatherData:
    def __init__(self):
        # temperature in degrees Celsius
        self.temperature: float = sys.minfloat
        # air pressure in hectopascal
        self.air_pressure: float = sys.minfloat
        # humidity in percent
        self.humidity: int = sys.minint
        # wind speed in kilometers per hour
        self.wind_speed: float = sys.minfloat
        # visibility in km
        self.visibility: float = sys.minfloat

# to be provided by the integration
class WeatherAdapter(ABC):
    @abstractmethod
    def get_weather_station_url(self) -> str:
        pass

    @abstractmethod
    def parse_weather_station_data(self, raw_data: str, weather_data: WeatherData):
        pass

# to be provided by the community
class UniPaderbornWeatherAdapter(WeatherAdapter):
    def get_weather_station_url(self):
        return "http://wetter.upb.de/images/downld02.txt"

    def parse_weather_station_data(self, raw_data: str, weather_data: WeatherData):
        # parse data...
        weather_data.temperature = 42
        weather_data.humidity = 23
FL550 commented 3 years ago

This looks as a really nice idea! However, as stated in the developer docs from HA, all integrations doing network requests should do this in a separate python module which is hosted on pypi. So maybe a module dwd_weather_adapters which is optional, where we can put all relevant download and parsing code.l, is a good way to do this.

m-kloeckner commented 3 years ago

I guess the new Template Weather Provider (https://www.home-assistant.io/integrations/weather.template/) is exactly what you are looking for. It was introducted in Home Assistant 2021.03. At least it allows setting temperature, humdity, pressure and wind speed with values from custom sensors.

FL550 commented 3 years ago

Ok, this is the easiest solution. Thank you for your hint. I'll close this for now.

csoltenborn commented 3 years ago

I totally agree - using it already with my custom weather station's current data and DWD's forecast :-)