CLI tool that uploads the energy consumption and maximum power usage data from the DATADIS API to influxdb on a daily basis
- go
- influxdb v2+
- Optional:
-
Configure
datadis_exporter.json(see the configuration section below). -
Run it.
docker compose up --detach
-
Build the docker image.
docker build . --tag datadis-exporter -
Configure
datadis_exporter.json(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 ./datadis_exporter.json:/app/datadis_exporter.json:ro ghcr.io/rare-magma/datadis-exporter:latest
For convenience, you can install this exporter with the following command or follow the manual process described in the next paragraph.
make build
make install
$EDITOR $HOME/.config/datadis_exporter.json-
Build
datadis_exporterwith:go build -ldflags="-s -w" -o datadis_exporter main.go -
Copy
datadis_exporterto$HOME/.local/bin/and make it executable. -
Copy
datadis_exporter.jsonto$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 datadis-exporter.* $HOME/.config/systemd/user/
-
and run the following command to activate the timer:
systemctl --user enable --now datadis-exporter.timer
It's possible to trigger the execution by running manually:
systemctl --user start datadis-exporter.serviceThe config file has a few options:
{
"InfluxDBHost": "influxdb.example.com",
"InfluxDBApiToken": "ZXhhbXBsZXRva2VuZXhhcXdzZGFzZGptcW9kcXdvZGptcXdvZHF3b2RqbXF3ZHFhc2RhCg==",
"Org": "home",
"Bucket": "datadis",
"DatadisUsername": "username",
"DatadisPassword": "password",
"Cups": "ES0000000000000000XX0X",
"DistributorCode": "1"
}InfluxDBHostshould be the FQDN of the influxdb server.Orgshould be the name of the influxdb organization that contains the energy consumption data bucket defined below.Bucketshould be the name of the influxdb bucket that will hold the energy consumption data.InfluxDBApiTokenshould be the influxdb API token value.- This token should have write access to the
BUCKETdefined above.
- This token should have write access to the
DatadisUsernameandDATADIS_PASSWORDshould be the credentials used to access the DATADIS websiteCupsshould be the Código Unificado de Punto de Suministro (CUPS)DistributorCodeshould be one of:- 1: Viesgo,
- 2: E-distribución
- 3: E-redes
- 4: ASEME
- 5: UFD
- 6: EOSA
- 7: CIDE
- 8: IDE
Check the systemd service logs and timer info with:
journalctl --user --unit datadis-exporter.service
systemctl --user list-timersThe consumption DATADIS API call period is limited to the last 30 days by default. The power call is limited to the current year's first and last day.
- consumption: The energy consumption in kWh
- period: The period type (p1: punta, p2: llano, p3: valle)
- cups: The cups corresponding to the consumption point above
- max_power: The highest electrical power demanded in kWh
datadis_consumption,cups=ES0000000000000000XX0X,period=1 consumption=0.123 1672610400
datadis_power,cups=ES0000000000000000XX0X,period=1 max_power=0.123 1686869100In datadis-dashboard.json there is an example of the kind of dashboard that can be built with datadis-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
datadis-dashboard.jsonfile.
For convenience, you can uninstall this exporter with the following command or follow the process described in the next paragraph.
make uninstallRun the following command to deactivate the timer:
systemctl --user disable --now datadis-exporter.timerDelete the following files:
~/.local/bin/datadis_exporter
~/.config/datadis_exporter.json
~/.config/systemd/user/datadis-exporter.timer
~/.config/systemd/user/datadis-exporter.serviceThis project takes inspiration from the following:
