Bash script that uploads the last 24h weather conditions from the AEMET OpenData API to influxdb on a hourly basis
-
Configure
aemet_exporter.conf
(see the configuration section below). -
Run it.
docker compose up --detach
-
Build the docker image.
docker build . --tag aemet-exporter
-
Configure
aemet_exporter.conf
(see the configuration section below). -
Run it.
docker run --rm --init --tty --interactive --read-only --cap-drop ALL --security-opt no-new-privileges:true --cpus 2 -m 64m --pids-limit 16 --volume ./aemet_exporter.conf:/app/aemet_exporter.conf:ro ghcr.io/rare-magma/aemet-exporter:latest
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/aemet_exporter.conf
-
Copy
aemet_exporter.sh
to$HOME/.local/bin/
and make it executable. -
Copy
aemet_exporter.conf
to$HOME/.config/
, configure it (see the configuration section below) and make it read only. -
Copy the systemd unit and timer to
$HOME/.config/systemd/user/
:
cp aemet-exporter.* $HOME/.config/systemd/user/
- and run the following command to activate the timer:
systemctl --user enable --now aemet-exporter.timer
It's possible to trigger the execution by running manually:
systemctl --user start aemet-exporter.service
The config file has a few options:
INFLUXDB_HOST='influxdb.example.com'
INFLUXDB_API_TOKEN='ZXhhbXBsZXRva2VuZXhhcXdzZGFzZGptcW9kcXdvZGptcXdvZHF3b2RqbXF3ZHFhc2RhCg=='
ORG='home'
BUCKET='aemet'
AEMET_API_KEY='ZXhhbXBsZXRva2VuZXhhcXdzZGFzZGptcW9kcXdvZGptcXdvZHF3b2RqbXF3ZHFhc2RhCg=='
AEMET_WEATHER_STATION_CODE='1234Y'
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.
- This token should have write access to the
AEMET_API_KEY
should be the AEMET API key requested in the AEMET OpenData's websiteAEMET_WEATHER_STATION_CODE
should be the alphanumeric code assigned to the weather station. Can be found in AEMET OpenData's website "Seleccione una estación" dropdown.
Run the script manually with bash set to trace:
bash -x $HOME/.local/bin/aemet_exporter.sh
Check the systemd service logs and timer info with:
journalctl --user --unit aemet-exporter.service
systemctl --user list-timers
Weather stations might have a different set of sensors so not all metrics below might be populated.
- temperature:
°C
- humidity:
%
- pressure:
hPa
- windspeed:
km/h
- windgust:
km/h
- winddirection:
°
- precipitation:
mm
- dewpoint:
°C
- visibility:
km
- insolation:
hours
- snow:
cm
aemet_weather_conditions,station=3195 temperature=11.1,humidity=99.0,pressure=949.7,windspeed=0.9,winddirection=271.0,windgust=2.9,precipitation=0.0,dewpoint=11.0,visibility=1.0,insolation=1.0,snow=0.0 1702206000
In aemet-dashboard.json
there is an example of the kind of dashboard that can be built with aemet-exporter
data:
Import it by doing the following:
- Create a dashboard
- Click the dashboard's settings button on the top right.
- Go to JSON Model and then paste there the content of the
aemet-dashboard.json
file.
For convenience, you can uninstall this exporter with the following command or follow the process described in the next paragraph.
make uninstall
Run the following command to deactivate the timer:
systemctl --user disable --now aemet-exporter.timer
Delete the following files:
~/.local/bin/aemet_exporter.sh
~/.config/aemet_exporter.conf
~/.config/systemd/user/aemet-exporter.timer
~/.config/systemd/user/aemet-exporter.service
Información elaborada por la Agencia Estatal de Meteorología © AEMET
This project takes inspiration from the following: