Pull electricity usage readings from an Energy Bridge via MQTT and ship them to InfluxDB.
The following syntax will run energybridge_to_influxdb
, and the program will keep running until it's sent a SIGINT or SIGTERM signal.
energybridge_to_influxdb \
-energy-bridge-host 192.168.1.4 \
-energy-bridge-nametag "Energy Bridge" \
-influx-bucket "energy_usage/autogen" \
-influx-server http://192.168.1.5:8086 \
[OPTIONS ...]
Alternatively, you can run the program via Docker:
docker run --rm \
-e BRIDGE_HOST=192.168.1.4 \
-e BRIDGE_NAME_TAG="Energy Bridge" \
-e INFLUX_BUCKET="energy_usage/autogen" \
-e INFLUX_SERVER=http://192.168.1.5:8086 \
[-e ENV_VAR=VALUE ...] \
cdzombak/energybridge_to_influxdb:1
-client-id
: MQTT Client ID. Defaults to hostname.CLIENT_ID
env for Docker.-energy-bridge-host
: IP or host of the Energy Bridge, eg. '192.168.1.1'. Required.BRIDGE_HOST
env for Docker.-energy-bridge-nametag
: Value for the energy_bridge_name tag in InfluxDB. Required.BRIDGE_NAME_TAG
env for Docker.-influx-bucket
: InfluxDB bucket. Supply a string in the form 'database/retention-policy'. For the default retention policy, pass just a database name (without the slash character). Required.INFLUX_BUCKET
env for Docker.-influx-org
: InfluxDB org.INFLUX_ORG
env for Docker. Required for InfluxDB 2.x.-influx-password
: InfluxDB password.INFLUX_PASSWORD
env for Docker.-influx-server
: InfluxDB server, including protocol and port, e.g.http://192.168.1.4:8086
. Required.INFLUX_SERVER
env for Docker.-influx-token
: InfluxDB token.INFLUX_TOKEN
env for Docker. Required for InfluxDB 2.x.-influx-username
: InfluxDB username.INFLUX_USERNAME
env for Docker.-new-measurement-name
: Use the new measurement name 'instantaneous_energy_usage' instead of the legacy 'instantaneous_usage'.-distrust-message-timestamps
: Do not trust the timestamp in MQTT message; instead, use the time the message was received.-heartbeat-url
: URL to GET every 30s, if and only if the program has received an MQTT message in the last 60s.-health-port
: If set, run a healthcheck server on this port.-print-usage
: Log every energy usage message to standard error.-help
: Print help and exit.-version
: Print version and exit.
brew install cdzombak/oss/energybridge_to_influxdb
Install my Debian repository if you haven't already:
sudo apt install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://dist.cdzombak.net/deb.key | sudo gpg --dearmor -o /etc/apt/keyrings/dist-cdzombak-net.gpg
sudo chmod 0644 /etc/apt/keyrings/dist-cdzombak-net.gpg
echo -e "deb [signed-by=/etc/apt/keyrings/dist-cdzombak-net.gpg] https://dist.cdzombak.net/deb/oss any oss\n" | sudo tee -a /etc/apt/sources.list.d/dist-cdzombak-net.list > /dev/null
sudo apt update
Then install energybridge_to_influxdb
via apt
:
sudo apt install energybridge_to_influxdb
Pre-built binaries for Linux and macOS on various architectures are downloadable from each GitHub Release. Debian packages for each release are available as well.
git clone https://github.com/cdzombak/energybridge_to_influxdb.git
cd energybridge_to_influxdb
make build
cp out/energybridge_to_influxdb $INSTALL_DIR
A pre-built Docker image available that can be configured entirely via environment variables. View it on Docker Hub, or pull it via docker pull cdzombak/energybridge_to_influxdb
.
The following table lists the environment variables that can be used to configure the Docker image.
Environment Variable | Equivalent CLI Flag |
---|---|
CLIENT_ID |
-client-id |
BRIDGE_HOST |
-energy-bridge-host |
BRIDGE_NAME_TAG |
-energy-bridge-nametag |
INFLUX_BUCKET |
-influx-bucket |
INFLUX_SERVER |
-influx-server |
INFLUX_ORG |
-influx-org |
INFLUX_USERNAME |
-influx-username |
INFLUX_PASSWORD |
-influx-password |
INFLUX_TOKEN |
-influx-token |
NEW_MEASUREMENT_NAME |
-new-measurement-name |
DISTRUST_MSG_TIMESTAMPS |
-distrust-message-timestamps |
HEARTBEAT_URL |
-heartbeat-url |
After installing the binary, you can run it as a systemd service.
-
Optionally, create a user for the service to run as:
sudo useradd -r -s /usr/sbin/nologin energybridge_influx_connector
-
Install the systemd service
energybridge-to-influxdb.service
and customize that file as desired (e.g. with the correct CLI options for your deployment):
curl -sSL https://raw.githubusercontent.com/cdzombak/energybridge_to_influxdb/main/energybridge-to-influxdb.service | sudo tee /etc/systemd/system/energybridge-to-influxdb.service
sudo nano /etc/systemd/system/energybridge-to-influxdb.service
- Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable energybridge-to-influxdb
sudo systemctl start energybridge-to-influxdb
- Verify its operation:
sudo systemctl status energybridge-to-influxdb
sudo journalctl -f -u energybridge-to-influxdb.service
Note This is untested; please open an issue if it doesn't work as expected.
After installing the binary via Homebrew, you can run it as a launchd service.
- Install the systemd service
com.dzombak.energybridge-to-influxdb.plist
and customize that file as desired (e.g. with the correct CLI options for your deployment):
mkdir -p "$HOME"/Library/LaunchAgents
curl -sSL https://raw.githubusercontent.com/cdzombak/nut_influx_connector/main/com.dzombak.energybridge-to-influxdb.plist > "$HOME"/Library/LaunchAgents/com.dzombak.energybridge-to-influxdb.plist
nano "$HOME"/Library/LaunchAgents/com.dzombak.energybridge-to-influxdb.plist
To run as a daemon with Docker, you'll want a command something like:
docker run -d --rm \
-e BRIDGE_HOST=192.168.1.4 \
-e BRIDGE_NAME_TAG="Energy Bridge" \
-e INFLUX_BUCKET="energy_usage/autogen" \
-e INFLUX_SERVER=http://192.168.1.5:8086 \
[-e ENV_VAR=VALUE ...] \
cdzombak/energybridge_to_influxdb:1
You may wish to create an environment file and pass it to Docker via the --env-file
option:
docker run -d --rm \
--env-file /path/to/energybridge_to_influxdb.env \
cdzombak/energybridge_to_influxdb:1
MIT; see LICENSE
in this repository.
Chris Dzombak (GitHub @cdzombak).