Skip to content

rare-magma/open-meteo-exporter

Repository files navigation

open-meteo-exporter

Bash script that uploads the current air quality and weather data from the Open-Meteo API to influxdb on an hourly basis

Dependencies

Relevant documentation

Installation

With Docker

docker-compose

  1. Configure open_meteo_exporter.conf (see the configuration section below).

  2. Run it.

    docker compose up --detach

docker build & run

  1. Build the docker image.

    docker build . --tag open-meteo-exporter
  2. Configure open_meteo_exporter.conf (see the configuration section below).

  3. Run it.

    docker run --rm --init --tty --interactive --volume $(pwd):/app localhost/open-meteo-exporter

With the Makefile

For convenience, you can install this exporter with the following command or follow the manual process described in the next paragraph.

make install
$EDITOR $HOME/.config/open_meteo_exporter.conf

Manually

  1. Copy open_meteo_exporter.sh to $HOME/.local/bin/ and make it executable.

  2. Copy open_meteo_exporter.conf to $HOME/.config/, configure it (see the configuration section below) and make it read only.

  3. Copy the systemd unit and timer to $HOME/.config/systemd/user/:

cp open-meteo-exporter.* $HOME/.config/systemd/user/
  1. and run the following command to activate the timer:
systemctl --user enable --now open-meteo-exporter.timer

It's possible to trigger the execution by running manually:

systemctl --user start open-meteo-exporter.service

Config file

The config file has a few options:

INFLUXDB_HOST='influxdb.example.com'
INFLUXDB_API_TOKEN='ZXhhbXBsZXRva2VuZXhhcXdzZGFzZGptcW9kcXdvZGptcXdvZHF3b2RqbXF3ZHFhc2RhCg=='
ORG='home'
BUCKET='openmeteo'
LONGITUDE='1.23456'
LATITUDE='1.23456'
  • INFLUXDB_HOST should be the FQDN of the influxdb server.
  • ORG should be the name of the influxdb organization that contains the data bucket defined below.
  • BUCKET should be the name of the influxdb bucket that will hold the data.
  • INFLUXDB_API_TOKEN should be the influxdb API token value.
    • This token should have write access to the BUCKET defined above.
  • LONGITUDE should be the longitude in numerical value of the location to collect data for.
  • LATITUDE should be the latitude in numerical value of the location to collect data for.

Troubleshooting

Run the script manually with bash set to trace:

bash -x $HOME/.local/bin/open_meteo_exporter.sh

Check the systemd service logs and timer info with:

journalctl --user --unit open-meteo-exporter.service
systemctl --user list-timers

Exported metrics for each hour (in the GMT timezone)

Air quality

  • european_aqi: EAQI
  • us_aqi: USAQI
  • pm10: μg/m³
  • pm2_5: μg/m³
  • carbon_monoxide: μg/m³
  • nitrogen_dioxide: μg/m³
  • sulphur_dioxide: μg/m³
  • ozone: μg/m³
  • aerosol_optical_depth: ratio from 0 to 1
  • dust: μg/m³
  • uv_index: number
  • uv_index_clear_sky: number

Weather conditions

  • temperature_2m: °C
  • relative_humidity_2m: %
  • apparent_temperature: °C
  • precipitation: mm
  • rain: mm
  • showers: mm
  • snowfall: cm
  • weather_code: wmo code
  • cloud_cover: %
  • pressure_msl: hPa
  • surface_pressure: hPa
  • wind_speed_10m: km/h
  • wind_direction_10m: °
  • wind_gusts_10m: km/h

Exported metrics example

open_meteo_air_quality,longitude=1.23456,latitude=1.23456 european_aqi=50,us_aqi=61,pm10=43.4,pm2_5=15.7,carbon_monoxide=145.0,nitrogen_dioxide=0.1,sulphur_dioxide=0.4,ozone=53.0,aerosol_optical_depth=0.19,dust=45.0,uv_index=0.00,uv_index_clear_sky=0.00 1702227600
open_meteo_current_weather,longitude=1.23456,latitude=1.23456 temperature_2m=28.5,relative_humidity_2m=80,apparent_temperature=32.3,precipitation=0.00,rain=0.00,showers=0.00,snowfall=0.00,weather_code=2,cloud_cover=52,pressure_msl=1011.9,surface_pressure=1011.9,wind_speed_10m=19.5,wind_direction_10m=65,wind_gusts_10m=24.5 1702233900

Example grafana dashboard

In open-meteo-dashboard.json there is an example of the kind of dashboard that can be built with open-meteo-exporter data:

example grafana dashboard screenshot

Import it by doing the following:

  1. Create a dashboard
  2. Click the dashboard's settings button on the top right.
  3. Go to JSON Model and then paste there the content of the open-meteo-dashboard.json file.

Uninstallation

With the Makefile

For convenience, you can uninstall this exporter with the following command or follow the process described in the next paragraph.

make uninstall

Manually

Run the following command to deactivate the timer:

systemctl --user disable --now open-meteo-exporter.timer

Delete the following files:

~/.local/bin/open_meteo_exporter.sh
~/.config/open_meteo_exporter.conf
~/.config/systemd/user/open-meteo-exporter.timer
~/.config/systemd/user/open-meteo-exporter.service

Credits

This project takes inspiration from the following:

About

Bash script that uploads the current air quality data from the Open-Meteo API to InfluxDB on an hourly basis

Topics

Resources

License

Stars

Watchers

Forks