dh1tw / tasmota-exporter

A Prometheus exporter for Tasmota-enabled devices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tasmota Prometheus Exporter

Build Status Docker Hub

A Prometheus exporter for Tasmota-enabled devices.
It subscribes to the topics tele/+/+ and stat/++ to which Tasmota devices send their updates.

Grafana dashboard

Grafana dashboard is available here on the GitHub repository.

Prerequisites

Installation

Build from the source code

You can pull the latest version of the source code and build it using the command line:

go mod download
go build -o tasmota-exporter ./cmd
chmod +x tasmota-exporter

Before running the application, you have to define the following environment variables:

MQTT_HOSTNAME //default is localhost
MQTT_PORT //default is 1883
MQTT_USERNAME //default is empty
MQTT_PASSWORD //default is empty
MQTT_TOPICS //default is "tele/+/+, stat/+/+". If you're using deeper topics, you can set as "tele/#, stat/#"
PROMETHEUS_EXPORTER_PORT //listening port. Default is 9092
REMOVE_WHEN_INACTIVE_MINUTES //optional. Default is 1. If the device is inactive for more than 1 minute, it will be removed from the list of active devices

Then run it using:

./tasmota-exporter

Using Docker

The exporter is also available as a Docker image. You can run it using the following example and pass configuration environment variables:

docker run \
  -e 'MQTT_HOSTNAME=192.168.1.10' \
  -e 'MQTT_PORT=1883' \
  -e 'MQTT_USERNAME=user' \
  -e 'MQTT_PASSWORD=password' \
  -e 'PROMETHEUS_EXPORTER_PORT=9092' \
  -p 9092:9092 \
  --restart unless-stopped \
  --name tasmota-exporter \
  eugenezadyra/tasmota-exporter:latest

Using docker-compose

You can run it using docker-compose and the template:

version: '3.4'
services:
  tasmota-exporter:
    image: eugenezadyra/tasmota-exporter:latest
    environment:
      MQTT_HOSTNAME: 192.168.1.10
      MQTT_PORT: 1883
      MQTT_USERNAME: user
      MQTT_PASSWORD: password
      PROMETHEUS_EXPORTER_PORT: 9092
    ports:
      - '9092:9092'
    restart: unless-stopped
#run in the background
docker-compose up -d
#update to the latest version and restart
docker-compose pull
docker-compose restart

Once the exporter is running, you also have to update your prometheus.yml configuration to let it scrape the exporter:

scrape_configs:
  - job_name:       'tasmota'
    scrape_interval: 5s
    static_configs:
      - targets: ['metrics.home:9092']

! Note: Available metrics may vary by device.

About

A Prometheus exporter for Tasmota-enabled devices


Languages

Language:Go 98.1%Language:Dockerfile 1.9%