Sign inSign up

briis/weatherflow2mqtt

By briis

•Updated almost 3 years ago

Retrieve local weather data using UDP from a WeatherFlow Station and push to MQTT

Image
2

100K+

briis/weatherflow2mqtt repository overview

⁠WeatherFlow-2-MQTT for Home Assistant

This project monitors the UDP socket (50222) from a WeatherFlow Hub, and publishes the data to a MQTT Server. Data is formatted in a way that, it supports the MQTT Discovery⁠ format for Home Assistant, so a sensor will created for each entity that WeatherFlow sends out, if you have MQTT Discovery enabled.

Everything runs in a pre-build Docker Container, so installation is very simple, you only need Docker installed on a computer and a MQTT Server setup somewhere in your network. If you run the Supervised version of Home Assistant, you will have easy access to both.ß

There is support for both the AIR & SKY devices and the TEMPEST device.

⁠Table of Contents

  1. Installation⁠
  2. Docker Setup⁠
    1. Docker Volume⁠
    2. Docker Environment Variables⁠
  3. Available Sensors⁠
    1. Sensor Structure⁠
    2. High and Low Values⁠
  4. Creating a Home Assistant Weather Entity⁠

⁠Installation

  • Ensure Docker is setup and running
  • Ensure there is a MQTT Server available
  • Open a Terminal on the Machine you want to run the Docker container on.
  • Make a new Directory: mkdir weatherflow2mqtt (or some other name) and change to that directory.
  • If you don't want all sensors setup, copy the config_example.yaml file from this repo to that directory, and rename it to config.yaml. Then add or remove the sensors you want from the available sensors list⁠. If you don't do this, all sensors from the Available Sensors⁠ will be added.
  • Now start the Docker Container with the parameters described under docker-setup⁠

If everything is setup correctly with MQTT and Home Assistant, you should now start seeing the sensors show up in HA. NOTE, it can take up to 1 min after startup, before all sensors are populated with data.

⁠Docker Setup

The below command will pull the latest docker image and start WeatherFlow2MQTT for timezone Europe/Copenhagen and save data in the directory you are placed in when you launch the command. Ensure that you have replaced the Environment variables with your specific data. See description below.

docker run -d \
--name=weatherflow2mqtt --restart=unless-stopped \
-v $(pwd):/usr/local/config \
-p 0.0.0.0:50222:50222/udp \
-e TZ=Europe/Copenhagen \
-e TEMPEST_DEVICE=True \
-e UNIT_SYSTEM=metric \
-e LANGUAGE=en \
-e RAPID_WIND_INTERVAL=0 \
-e DEBUG=False \
-e ELEVATION=0 \
-e WF_HOST=0.0.0.0 \
-e WF_PORT=50222 \
-e MQTT_HOST=127.0.0.1 \
-e MQTT_PORT=1883 \
-e MQTT_USERNAME= \
-e MQTT_PASSWORD= \
-e MQTT_DEBUG=False \
-e ADD_FORECAST=False \
-e STATION_ID= \
-e STATION_TOKEN= \
-e FORECAST_INTERVAL=30 \
ghcr.io/briis/hass-weatherflow2mqtt:latest
⁠Docker Volume

-v YOUR_STORAGE_AREA:/usr/local/config Please replace YOUR_STORAGE_AREA with a directory where Docker will have read and write access. It is also in this directory that you must place the config.yaml file if you don't want all the sensors (See Installation⁠). Once the program runs, a SQLite Database with the name weatherflow2mqtt.db will be created in this directory. This database is used to hold some calculated values, store temporary data used for calculations and to ensure that you don't start from 0 if you have to restart Home Assistant or the container.

⁠Docker Environment Variables

A description of the Environment Variables available for this container. All of them have a default value, so you only need to add the onces where you want to change that.

  • TZ: Set your local Timezone. It is important that you use the right timezone here, or else some of the calculations done by the container will not be correct. Default Timezone is Europe/Copenhagen (Required)
  • TEMPEST_DEVICE: If you have a Tempest Weather Station set this to True. If False, the program will assume you have the older AIR and SKY units. Default is True
  • UNIT_SYSTEM: Enter imperial or metric. This will determine the unit system used when displaying the values. Default is metric
  • LANGUAGE: Use this to set the language for Wind Direction cardinals and other sensors with text strings as state value. These strings will then be displayed in HA in the selected language. See section Supported Languages⁠
  • RAPID_WIND_INTERVAL: The weather stations delivers wind speed and bearing every 2 seconds. If you don't want to update the HA sensors so often, you can set a number here (in seconds), for how often they are updated. Default is 0, which means data are updated when received from the station.
  • ELEVATION: Set the hight above sea level for where the station is placed. This is used when calculating some of the sensor values. Station elevation plus Device height above ground. The value has to be in meters (meters = feet * 0.3048). Default is 0
  • WF_HOST: Unless you have a very special IP setup or the Weatherflow hub is on a different network, you should not change this. Default is 0.0.0.0
  • WF_PORT: Weatherflow always broadcasts on port 50222/udp, so don't change this. Default is 50222
  • MQTT_HOST: The IP address of your mqtt server. Even though you have the MQTT Server on the same machine as this Container, don't use 127.0.0.1 as this will resolve to an IP Address inside your container. Use the external IP Address. Default value is 127.0.0.1 (Required)
  • MQTT_PORT: The Port for your mqtt server. Default value is 1883
  • MQTT_USERNAME: The username used to connect to the mqtt server. Leave blank to use Anonymous connection. Default value is blank
  • MQTT_PASSWORD: The password used to connect to the mqtt server. Leave blank to use Anonymous connection. Default value is blank
  • MQTT_DEBUG: Set this to True, to get some more mqtt debugging messages in the Container log file. Default value is False
  • DEBUG: Set this to True to enable more debug data in the Container Log. Default is False
  • ADD_FORECAST: Set this to True if you want to retrieve Forecast Data from WeatherFlow. If set to True, STATION_ID and STATION_TOKEN must be filled also. NOTE If this is enabled the component will access the Internet to get the Forecast data. Default value is False
  • STATION_ID: Enter your Station ID for your WeatherFlow Station. Default value is blank.
  • STATION_TOKEN: Enter your personal access Token to allow retrieval of data. If you don't have the token login with your account⁠ and create the token. NOTE You must own a WeatherFlow station to get this token. Default value is blank
  • FORECAST_INTERVAL: The interval in minutes, between updates of the Forecast data. Default value is 30 minutes.
⁠Supported Languages

Currently these languages are supported for Wind Cardinals and other Text state strings:

  • en: English
  • da: Danish

If you would like to assist in translating to a new language, do the following:

  • From the translations directory on this Github Project, download the file en.json
  • Rename the file to YourLanguageCode.json - example for Spanish rename it to es.json
  • Edit the file and translate the strings
  • Make a pull request in Github and attach the file.

⁠Available Sensors

Here is the list of sensors that the program generates. Calculated Sensor means, if No, then data comes directly from the Weather Station, if yes, it is a sensor that is derived from some of the other sensors. For a copy ready list see further below⁠

Sensor IDNameDescriptionCalculated SensorUDP Event/Index (Tempest)Default UnitsMQTT Topic
air_densityAir DensityThe Air densityYeskg/m^3
air_temperatureTemperatureOutside TemperatureNoobs_st/7C°
batteryBattery SKY or TEMPESTIf this is a TEMPEST unit this is where the Voltage is displayed. Else it will be the Voltage of the SKY unitNoobs_st/16Volts
battery_airBattery AIRThe voltage on the AIR unit (If present)NoVolts
beaufortBeaufort ScaleBeaufort scale is an empirical measure that relates wind speed to observed conditions at sea or on landYes
delta_tDelta TDifference between Air Temperature and Wet Bulb TemperatureYesC°
dewpointDew PointDewpoint in degreesYesC°
dewpoint_descriptionDewpoint Comfort LevelTextual representation of the Dewpoint valueYes
feelslikeFeels Like TemperatureThe apparent temperature, a mix of Heat Index and Wind ChillYesC°
illuminanceIlluminanceHow much the incident light illuminates the surfaceNoobs_st/9Lux
lightning_strike_countLightning Count (3 hours)Number of lightning strikes the last 3 hoursYes
lightning_strike_count_todayLightning Count (Today)Number of lightning strikes current dayYes
lightning_strike_distanceLightning DistanceDistance of the last strikeNoobs_st/14 or evt_strike/1km
lightning_strike_energyLightning EnergyEnergy of the last strikeNoevt_strike/2
lightning_strike_timeLast Lightning StrikeWhen the last lightning strike occurredYesevt_strike/0seconds
precipitation_typePrecipitation TypeCan be one of None, Rain or HailNoobs_st/130 = none, 1 = rain, 2 = hail, 3 = rain + hail (heavy rain)
rain_rateRain RateHow much is it raining right nowYesmm/h
rain_start_timeLast RainWhen was the last time it rainedNoevt_precip/0seconds
rain_todayRain TodayTotal rain for the current day. (Reset at midnight)Yesmm
rain_yesterdayRain YesterdayTotal rain for yesterday (Reset at midnight)Yesmm
rain_duration_todayRain Duration (Today)Total rain minutes for the current day. (Reset at midnight)Yesminutes
rain_duration_yesterdayRain Duration (Yesterday)Total rain minutes yesterdayYesminutes
relative_humidityHumidityRelative HumidityNoobs_st/8%
sealevel_pressureStation PressurePreasure measurement at Sea LevelYesMB
pressure_trendPressure TrendReturns Steady, Falling or Rising determined by the rate of change over the past 3 hoursYes
solar_radiationSolar RadiationElectromagnetic radiation emitted by the sunNoobs_st/11W/m^2
station_pressureStation PressurePressure measurement where the station is locatedNoobs_st/6MB
temperature_descriptionTemperature LevelTextual representation of the Outside Air Temperature valueYes
uptimeUptimeHow long has the HUB been runningNohub_status/uptime
uvUV IndexThe UV indexNoobs_st/10Index
uv_descriptionUV LevelTextual representation of the UV Index valueYes
visibilityVisibilityDistance to the horizonYeskm
wetbulbWet Bulb TemperatureTemperature of a parcel of air cooled to saturation (100% relative humidity)YesC°
wind_bearingWind BearingCurrent measured Wind bearing in degreesNorapid_wind/2Degrees
wind_bearing_avgWind Bearing AvgThe average wind bearing in degreesNoobs_st/4Degrees
wind_directionWind DirectionCurrent measured Wind bearing as compass symbolYesCardinal
wind_direction_avgWind Direction AvgThe average wind direction as a compass stringYesCardinal
wind_gustWind GustHighest wind speed for the last minuteNoobs_st/3m/s
wind_lullWind LullLowest wind for the last minuteNoobs_st/1m/s
wind_speedWind SpeedCurrent measured Wind SpeedNorapid_wind/1m/s
wind_speed_avgWind Speed AvgAverage wind speed for the last minuteNoobs_st/2m/s
weatherWeatherOnly available if Forecast option is enabled. State will be current condition, and forecast data will be in the attributes.No
⁠Sensor Structure
sensors:
  - air_density
  - air_temperature
  - battery
  - battery_air
  - beaufort
  - dewpoint
  - dewpoint_description
  - delta_t
  - feelslike
  - illuminance
  - lightning_strike_count
  - lightning_strike_count_today
  - lightning_strike_distance
  - lightning_strike_energy
  - lightning_strike_time
  - precipitation_type
  - pressure_trend
  - rain_rate
  - rain_start_time
  - rain_today
  - rain_yesterday
  - rain_duration_today
  - rain_duration_yesterday
  - relative_humidity
  - sealevel_pressure
  - solar_radiation
  - station_pressure
  - temperature_description
  - uptime
  - uv
  - uv_description
  - visibility
  - wetbulb
  - wind_bearing
  - wind_bearing_avg
  - wind_direction
  - wind_direction_avg
  - wind_gust
  - wind_lull
  - wind_speed
  - wind_speed_avg
  - weather
⁠High and Low Values

For selected sensors high and low values are calculated and published to the attributes of the sensor. Currently daily, monthly and all-time values are calculated, but future values are planned. Only the sensors where it is relevant, will get a low value calculated. See the table further down, for the available sensors and what values to expect.

Here are the current attributes, that will be applied to the selected sensor:

Attribute NameDescription
max_dayMaximum value for the current day. Reset at midnight.
max_day_timeUTC time when the max value was recorded. Reset at midnight.
min_dayMinimum value for the current day. Reset at midnight.
min_day_timeUTC time when the min value was recorded. Reset at midnight.
max_monthMaximum value for the current month. Reset when new month.
max_month_timeUTC time when the max value was recorded. Reset when new month.
min_monthMinimum value for the current month. Reset when new month.
min_month_timeUTC time when the min value was recorded. Reset when new month.
max_allMaximum value ever recorded. Updated at midnight every day.
max_all_timeUTC time when the all-time max value was recorded. Updated at midnight every day.
min_allMinimum value ever recorded. Updated at midnight every day.
min_all_timeUTC time when the all-time min value was recorded. Updated at midnight every day.

The following sensors are displaying High and Low values:

Sensor IDHigh ValueLow Value
air_temperatureYesYes
dewpointYesYes
illuminanceYesNo
lightning_strike_count_todayYesNo
lightning_strike_energyYesNo
rain_rateYesNo
rain_duration_todayYesNo
relative_humidityYesYes
sealevel_pressureYesYes
solar_radiationYesNo
uvYesNo
wind_gustYesNo
wind_lullYesNo
wind_speed_avgYesNo

⁠Creating a Home Assistant Weather Entity

If you have enabled the Forecast option, then there is a possibility to create a Weather Entity, that can be used in all the different Lovelace Cards there is for Weather. We will do this by using the Weather Template⁠. The naming of the sensors might vary based on your configuration, so check that if it does not work.

Edit configuration.yaml and insert the following:

weather:
  - platform: template
    name: My Local Weather
    condition_template: "{{ states('sensor.wf_weather') }}"
    temperature_template: "{{ states('sensor.wf_temperature') | float}}"
    humidity_template: "{{ states('sensor.wf_humidity')| int }}"
    pressure_template: "{{ states('sensor.wf_sea_level_pressure')| float }}"
    wind_speed_template: "{{ ( states('sensor.wf_wind_speed_avg') | float * 18 / 5 ) | round(2) }}"
    wind_bearing_template: "{{ states('sensor.wf_wind_bearing_avg')| int }}"
    visibility_template: "{{ states('sensor.wf_visibility')| float }}"
    forecast_template: "{{ state_attr('sensor.wf_weather', 'hourly_forecast') }}"
  • The weather entity expects km/h when having metric units, so the above example converts m/s to km/h. If you are using imperial units, the line should just be {{ states('sensor.wf_wind_speed_avg') }}
  • For the forecast_template you can either use hourly_forecast or daily_forecast to get Hourly or Day based forecast.

Tag summary

Content type

Image

Digest

sha256:f107dde06…

Size

56.8 MB

Last updated

almost 3 years ago

docker pull briis/weatherflow2mqtt