Git Product home page Git Product logo

energybridge_to_influxdb's Introduction

energybridge_to_influxdb

Pull electricity usage readings from an Energy Bridge via MQTT and ship them to InfluxDB.

Usage

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

Options

  • -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.
  • -print-usage: Log every energy usage message to standard error.
  • -help: Print help and exit.
  • -version: Print version and exit.

Installation

macOS via Homebrew

brew install cdzombak/oss/energybridge_to_influxdb

Debian via Apt repository

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

Manual installation from build artifacts

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.

Build and install locally

git clone https://github.com/cdzombak/energybridge_to_influxdb.git
cd energybridge_to_influxdb
make build

cp out/energybridge_to_influxdb $INSTALL_DIR

Docker

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.

Docker environment variables

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

Running on Linux with Systemd

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

Running on macOS with Launchd

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

Running with Docker

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

License

MIT; see LICENSE in this repository.

Author

Chris Dzombak (GitHub @cdzombak).

energybridge_to_influxdb's People

Contributors

ablyler avatar cdzombak avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

energybridge_to_influxdb's Issues

Suggestion: Change topic to event/metering/summation/minute

Have you considered changing the MQTT topic to event/metering/summation/minute? That seems to be a more accurate number than event/metering/instantaneous_demand. instantaneous_demand seems to update every 3 seconds and may miss small bits that add up. summation/minute seems to include an average of all usage for the past minute, to a floating point accuracy. For InfluxDB I think this might be a better topic.

The example output for this topic is

{
  "type":"minute",
  "time":1614969300000,
  "local_time":"2021-03-05T13:35:00",
  "value":632.543825
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.