Git Product home page Git Product logo

hubitat2prom's Introduction

hubitat2prom

This application runs in a docker container, talks to the Hubitat Maker API and returns the metrics in a format suitable for consumption by Prometheus

Getting up and running

Docker

This is the recommended way to launch the service as it takes care of the dependencies for you.

First, retrieve your API token and API path from your Hubitat device. These will look something like;

  • HE_URI: http://<hubitat_hostname>/apps/api/26/devices
  • HE_TOKEN: f4a20ab3-..-670f559be5a6

Put these values into a new file named .env as below:

HE_URI=http://<hubitat_hostname>/apps/api/26/devices
HE_TOKEN=f4a20ab3-..-670f559be5a6

Next, run the following command to start the container:

docker run --rm --env-file .env -p 5000:5000 ghcr.io/budgetsmarthome/hubitat2prom:latest

You can also use docker-compose if you prefer:

$ cat <<EOF >docker-compose.yaml
---
version: '3'
services:
  hubitat2prom:
    image: ghcr.io/budgetsmarthome/hubitat2prom:latest
    env_file:
    - '.env'
    ports:
    - 5000:5000

EOF

$ docker-compose run --rm hubitat2prom

This will start the container listening on your local machine on port 5000, and you can visit http://localhost:5000/metrics to confirm that the metrics are coming through.

You can additionally visit http://localhost:5000/info to view basic configuration infomation and check the connection status with the Hubitat API.

Once you've confirmed this, you can move on to configuring Prometheus.

Build Image

docker buildx build --push --platform linux/amd64 -t jahvond/hubitat2prom:latest .

Local Installation

If you want to run this service without installing from Docker, then the steps are as follows:

  1. Install pipenv for python3; python3 -m pip install pipenv.
  2. Create the .env file as per the instructions above.
  3. Run the following command: pipenv run app

A Python virtual environment will be created automatically, if the service has never run before and then pipenv will also automatically install all of the dependencies that the service requires to run. After this is completed the application will start. If you stop and start the application, the dependencies will persist unless otherwise removed.

As with the docker container, your service will now be exposed on port 5000, and you can test it is working by visiting http://localhost:5000/metrics in a browser.

Prometheus

Configuring Prometheus to scrape the metrics is easy.

Add the following to the bottom of your Prometheus Outputs:

  - job_name: 'hubitat'
    scrape_interval: 30s
    static_configs:
    - targets: ['my.ip.address.or.hostname']

Prometheus will now scrape your web service every 30 seconds to update the metrics in the data store.

InfluxDB

Configuring InfluxDB is equally as simple.

Visit the InfluxDB admin console, then navigate to; Data --> Scrapers --> 'Create Scraper'

Provide a name to your scraper, assign a bucket where the data should be stored, then provide the path to the metrics path as listed above, substituting your localhost address with the IP address/hostname of the server running the container.

InfluxDB - Create Scraper

Metrics data from your new scraper is now available to be queried:

InfluxDB - Query Metrics

Collected Metrics

Hubitat2Prom is capable of collecting any of the metrics that Hubitat exposes via the MakerAPI.

By default it will collect the list below, however adding a new metric is as simple as checking the output of the MakerAPI and adding the attribute name to your configuration, and then restarting the service.

The default collections are:

  - battery
  - humidity
  - illuminance
  - level # This is used for both Volume AND Lighting Dimmers!
  - switch # We convert from "on/off" to "1/0" so it can be graphed
  - temperature

Grafana

There's a sample dashboard in the grafana/ directory that you can import into Grafana to give you an idea of what is possible!

The sample Grafana dashboard

hubitat2prom's People

Contributors

proffalken avatar jahvon avatar djw4 avatar snyk-bot avatar

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.