Sign inSign up

oitc/weather2mqtt

By oitc

Updated 3 months ago

Generic tool to get weather information and publish them to a MQTT topic.

Image
Integration & delivery
Internet of things
0

4.1K

oitc/weather2mqtt repository overview

Quick reference

This is a Hackergarden project, started during 50th Hackergarden 2025-04-01 at codecentric AG, Industriestraße 3, 70565 Stuttgart, Germany.

Maintained by: Michael Oberdorf IT-Consulting

Source code: GitHub

Container image: DockerHub

Summary

The application will make an Open Meteo free weather API call to get weather information for the configured geo coordinates. There are currently two MODES specified:

  1. current: will get the current weather
  2. tomorrow: will get the weather for tomorrow

The results will be parsed, formatted in JSON and published via MQTT.

JSON output examples
current weather
{
  "location": {
    "latitude": 48.779998779296875,
    "longitude": 8.940000534057617,
    "elevation": 409
  },
  "timezone": {
    "name": "Europe/Berlin",
    "abbreviation": "GMT+1",
    "utc_offset_seconds": 3600
  },
  "current": {
    "time": "2026-01-06T09:45:00+01:00",
    "temperature_2m": -6.849999904632568,
    "relative_humidity_2m": 89,
    "is_day": 1,
    "rain": 0,
    "showers": 0,
    "snowfall": 0,
    "weather_code": 71,
    "cloud_cover": 100,
    "surface_pressure": 967.1641845703125,
    "wind_speed_10m": 2.0364675521850586,
    "wind_direction_10m": 224.99989318847656,
    "wind_gusts_10m": 4.320000171661377,
    "weather_code_text": "Snow fall: Slight intensity"
  },
  "message_timestamp": "2026-01-06T09:59:13.119176+01:00"
}
weather forecast for tomorrow
{
  "location": {
    "latitude": 48.779998779296875,
    "longitude": 8.940000534057617,
    "elevation": 409
  },
  "timezone": {
    "name": "Europe/Berlin",
    "abbreviation": "GMT+1",
    "utc_offset_seconds": 3600
  },
  "tomorrow": {
    "date": "2026-01-07",
    "temperature_2m_mean": -5.241146087646484,
    "temperature_2m_min": -8.211000442504883,
    "temperature_2m_max": -3.510999917984009,
    "rain_sum": 0,
    "showers_sum": 0,
    "snowfall_sum": 0,
    "weather_code": 3,
    "wind_speed_10m_mean": 6.99040412902832,
    "wind_speed_10m_min": 1.9386591911315918,
    "wind_speed_10m_max": 13.10419750213623,
    "wind_direction_10m_dominant": 194.28439331054688,
    "wind_gusts_10m_mean": 13.739999771118164,
    "wind_gusts_10m_min": 5.039999961853027,
    "wind_gusts_10m_max": 25.559999465942383,
    "sunrise": 0,
    "sunset": 0,
    "daylight_duration": 30511.171875,
    "sunshine_duration": 23594.3828125,
    "surface_pressure_mean": 964.9620971679688,
    "surface_pressure_min": 961.7695922851562,
    "surface_pressure_max": 968.2794189453125,
    "relative_humidity_2m_mean": 80.78125,
    "relative_humidity_2m_min": 69,
    "relative_humidity_2m_max": 89,
    "weather_code_text": "Cloudy"
  },
  "message_timestamp": "2026-01-06T09:57:42.813048+01:00"
}

Configuration

Container configuration

The container grab some configuration via environment variables.

Environment variable nameDescriptionRequiredDefault value
MODEThe weather selection mode. Currently supported is current and tomorow.optionalcurrent
LATITUDEThe geo coordinate latitude from where we want to have the weather.optional48.72592
LONGITUDEThe geo coordinate longitude from where we want to have the weather.optional9.11446
ELEVATIONThe ground elevation from where we want to have the weather.optional
WEATHER_MODELSThe weather model(s) to use as comma separated list (see below).optional
WEATHE_CODE_LANGUAGETranslation of the numeric weather code into the defined language ('en' or 'de')optionalen
TZThe time zone to use to provide timestamps.optionalUTC
MQTT_CLIENT_IDA MQTT client identifier.optional
MQTT_PROTOCOL_VERSIONThe MQTT protocol version to use. Currently supported 3 (means 3.1.1) and 5.optional3
MQTT_TLSUse TLS encrypted connection to MQTT broker.optionalfalse
MQTT_TLS_INSECUREDisable TLS certificate and hostname verification.optionalfalse
REQUESTS_CA_BUNDLEPath to certificates of trusted certificate authorities.optional/etc/ssl/certs/ca-certificates.crt
MQTT_USERNAMEUsername to authenticate to MQTT broker.optional
MQTT_PASSWORDPassword to authenticate to MQTT broker.optional
MQTT_PASSWORD_FILEFile that contains the password to authenticate to MQTT broker.optional
MQTT_SERVERMQTT broker hostname to connect to.optionaltest.mosquitto.org
MQTT_PORTMQTT broker TCP port to connect to.optional1883
MQTT_QOSMQTT quality of service for published messages.optional0
MQTT_RETAINPublish MQTT message in retain mode fpr persistance.optionalfalse
MQTT_TOPICThe MQTT topic to publish the weather data.optionalcom/github/cybcon/docker.weather2mqtt.git/weather
CACHE_DIRDirectory used for API request caching.optional/app/cache
CACHE_EXPIRY_AFTER_SECCache expiration time in seconds.optional600
DEBUGEnable debug output log.optionalfalse
Weather models

You can manually select one or more weather models. Per default, the best suitable weather models will be combined by Open Meteo.

To select one or more weather models, you need to define them via the model ID in the environment variable WEATHER_MODELS.

Open Meteo supports, beside best_match, following 45 weather models:

Model nameModel ID
ECMWF IFS HRES 9kmecmwf_ifs
ECMWF IFS 0.25°ecmwf_ifs025
ECMWF AIFS 0.25° Singleecmwf_aifs025_single
CMA GRAPES Globalcma_grapes_global
BOM ACCESS Globalbom_access_global
DWD ICON Seamlessicon_seamless
DWD ICON Globalicon_global
DWD ICON EUicon_eu
DWD ICON D2icon_d2
MET Norway Nordic Seamless (with ECMWF)metno_seamless
MET Norway Nordicmetno_nordic
NCEP GFS Seamlessgfs_seamless
NCEP GFS Global 0.11°/0.25°gfs_global
NCEP HRRR U.S. Conusgfs_hrrr
NCEP NBM U.S. Conusncep_nbm_conus
NCEP NAM U.S. Conusncep_nam_conus
GFS GraphCastgfs_graphcast025
GEM Seamlessgem_seamless
GEM Globalgem_global
GEM Regionalgem_regional
GEM HRDPS Continentalgem_hrdps_continental
GEM HRDPS Westgem_hrdps_west
KNMI Seamless (with ECMWF)knmi_seamless
KNMI Harmonie Arome Europeknmi_harmonie_arome_europe
KNMI Harmonie Arome Netherlandsknmi_harmonie_arome_netherlands
DMI Seamless (with ECMWF)dmi_seamless
DMI Harmonie Arome Europedmi_harmonie_arome_europe
JMA Seamlessjma_seamless
JMA MSMjma_msm
JMA GSMjma_gsm
Météo-France Seamlessmeteofrance_seamless
Météo-France ARPEGE Worldmeteofrance_arpege_world
Météo-France ARPEGE Europemeteofrance_arpege_europe
Météo-France AROME Francemeteofrance_arome_france
Météo-France AROME France HDmeteofrance_arome_france_hd
UK Met Office Seamlessukmo_seamless
UK Met Office Global 10kmukmo_global_deterministic_10km
UK Met Office UK 2kmukmo_uk_deterministic_2km
KMA Seamlesskma_seamless
KMA LDPSkma_ldps
KMA GDPSkma_gdps
ItaliaMeteo ARPAE ICON 2Iitalia_meteo_arpae_icon_2i
MeteoSwiss ICON Seamlessmeteoswiss_icon_seamless
MeteoSwiss ICON CH1meteoswiss_icon_ch1
MeteoSwiss ICON CH2meteoswiss_icon_ch2
Examples

Examples on how to set one or more weather models.

Single weather model:

export WEATHER_MODELS="icon_d2"

Multiple weather models:

export WEATHER_MODELS=icon_d2,icon_eu
.envrc example

If you use direnv to load your environment automatically.

export TZ="Europe/Berlin"
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
export DEBUG="true"
export MODE="current"
export LATITUDE="48.72592"
export LONGITUDE="9.11446"
export WEATHER_MODELS="icon_d2"
export MQTT_SERVER="test.mosquitto.org"
export MQTT_PORT="8883"
export MQTT_TLS="true"
export MQTT_TLS_INSECURE="true"
export MQTT_CLIENT_ID="acd2b765-e289-49c1-9884-28826f619d2b"
export MQTT_PROTOCOL_VERSION="5"
export MQTT_TOPIC="github.com/cybcon/docker.weather2mqtt.git/weather"
export CACHE_DIR="../cache"
export CACHE_EXPIRY_AFTER_SEC="600"
export WEATHE_CODE_LANGUAGE="de"
Configuration files

The modes (current and tomorrow) are defined in configuration files. That can be found here:

ModeConfiguration file in GITLocation in the container image
current./src/app/etc/current.json/app/etc/current.json
tomorrow./src/app/etc/tomorrow.json/app/etc/tomorrow.json

The files specifies the API call request body for Open Mateo. A documentation of the free weather API can be found here: https://open-meteo.com/en/docs.

Python Unit Tests

To trigger the Python unit tests please follow following instrructions after checkout the git repository.

Requirements
pip install -r src/requirements.txt
pip install -r test/requirements.txt
Execute Unit Tests
python -m unittest
pytest
ruff check --select=E9,F63,F7,F82 --target-version=py312 .
ruff check --target-version=py312 .

Donate

I would appreciate a small donation to support the further development of my open source projects.

Donate with PayPal

License

Copyright (c) 2025-2026 Michael Oberdorf IT-Consulting

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Tag summary

Content type

Image

Digest

sha256:38f82a22e

Size

31 MB

Last updated

3 months ago

docker pull oitc/weather2mqtt