https://github.com/btschwertfeger/tasmota-plug-monitoring

Grafana, InfluxDB, and MQTT setup for monitoring electricity consumption measured by Tasmota smart plugs.

https://github.com/btschwertfeger/tasmota-plug-monitoring

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.5%) to scientific vocabulary

Keywords

docker docker-compose grafana grafana-dashboard influxdb influxdb2 monitoring mqtt mqtt-client mqtt-server tasmota tasmota-devices tasmota-templates
Last synced: 5 months ago · JSON representation

Repository

Grafana, InfluxDB, and MQTT setup for monitoring electricity consumption measured by Tasmota smart plugs.

Basic Info
  • Host: GitHub
  • Owner: btschwertfeger
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 529 KB
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 1
  • Releases: 3
Topics
docker docker-compose grafana grafana-dashboard influxdb influxdb2 monitoring mqtt mqtt-client mqtt-server tasmota tasmota-devices tasmota-templates
Created about 1 year ago · Last pushed 6 months ago
Metadata Files
Readme License Codeowners Security

README.md

Tasmota Plug Monitoring

This repository contains the necessary knowledge and resources to setup and monitor energy consumption measured by Tasmota-driven smart plugs using InfluxDB, Grafana, and MQTT.

The setup consists of the following components:

  • InfluxDB as a time series database to store the metrics.
  • Grafana as a visualization tool to create dashboards and panels.
  • Mosquitto as a MQTT broker to receive the metrics from the Tasmota plugs.
  • A custom script that listens to the MQTT broker and writes the metrics to the InfluxDB.

The dashboard is designed to automatically detect new devices and include them in the visualization.

Grafana dashboard of collected data
Grafana dashboard of collected data

Requirements

  • Docker
  • Docker Compose
  • Tasmota plug(s), e.g. https://www.amazon.de/dp/B0CHMMKZCQ

Setup and Configuration

  1. Connect the Tasmota smart plug(s) to your network by following the instructions provided by the manufacturer. You can find the IP address of the plug by checking the DHCP leases of your router. You may also want to assign a static IP address to the plug(s).
  2. Install the latest version of Tasmota on your devices.
  3. Create a password file for mosquitto by running the official docker image to execute the mosquitto_passwd command.

```bash docker run -it eclipse-mosquitto:latest sh $ mosquittopasswd -c passwdfile mqtt_user Password: ******** Reenter password: ********

$ cat passwdfile mqttuser:................ ```

Copy the content of passwd_file into ./mosquitto/passwd_file on your host system.

Do not change the path to passwd_file file within ./mosquitto/mosquitto.conf. This file must be present in the working directory in which docker is run later on.

  1. Run the docker-compose file to start the services, but first, ensure that the required environment variables are set.

The host must match the IP address of the machine running the Docker containers. For simplicity, we take the same password for MQTT and InfluxDB.

Note: The MQTT password must match the password used when generating the passwd_file.

The InfluxDB token must be created in the InfluxDB web UI in the next step.

```bash # InfluxDB export INFLUXDBHOST="http://192.168.2.141:8086" export INFLUXDBUSERNAME="influxdbuser" export INFLUXDBPASSWORD="influxdbpassword" export INFLUXDBDATABASE="smarthome" export INFLUXDBORG="smarthome" export INFLUXDBTOKEN="You have to create a token in the influxdb IU"

# MQTT export MQTTHOST="192.168.2.141" export MQTTUSERNAME="mqttuser" export MQTTPASSWORD="${INFLUXDB_PASSWORD}" ```

bash docker compose up

  1. Open the InfluxDB web UI at http://192.168.2.141:8086/, login using the credentials and create a new API token at "Load Data" -> "API Tokens".
  2. Stop the services started using Docker Compose and update the INFLUXDB_TOKEN with the newly created token.

bash docker compose down export INFLUXDB_TOKEN="<the new token>" docker compose up -d

  1. Setup the Tasmota devices to use the MQTT broker. The IP address must match the host of the MQTT broker. The username and password must match the MQTT_USERNAME and MQTT_PASSWORD environment variables. For this go to the IP address of the Tasmota smart plugs, go to "Configuration" -> "Configure MQTT" and enter the values. You may also want to rename the "Topic" to distinguish the devices. You can verify the connection by reviewing the logs of the MQTT service container and the Tasmota smart plug logs. Additionally, you can use tools like mqtt-explorer to verify the connection.
  2. Increase the frequency of publishing metrics by setting TelePeriod 10 in the Tasmota console ("Tools" -> "Console"). This will ensure that the metrics are updated every 10 seconds.
  3. Login to the Grafana web UI at http://192.168.2.141:3000/ using the default credentials admin and admin.

9.1 Add the InfluxDB as a data source at "Connections" -> "Data Sources".

9.2 Set the query language to "Flux"

9.3 Enter the correct IP and port to access the InfluxDB.

9.4 Enter the "organization" and "token" to the values defined earlier.

  1. Now its time to import the Dashboard provided in this repository via copy-pasting the content of the grafana/dashboard.json file into the "Dashboards" -> "New" -> "Import" section of the Grafana UI.

    Note: You may need to click through each panel, select your InfluxDB data source, and hit "Refresh".

  2. You may have to adjust the price_per_kWh variable in some of the panels to match your electricity price.

Notes

  • This is a basic setup and can be extended with more features like alerts, additional metrics, and more.
  • The setup is designed to be run on a local network and is not secured for public access. You may want to add more security features like SSL certificates, further authentication, and authorization.
  • The setup is tested and running on Ubuntu 24.04. It should work on other systems as well.
  • For any questions, issues, or feature requests please open an issue in this repository.

Owner

  • Name: Benjamin T. Schwertfeger
  • Login: btschwertfeger
  • Kind: user
  • Location: Germany
  • Company: CONTACT Software GmbH

Quality Manager in Software Development

GitHub Events

Total
  • Create event: 10
  • Issues event: 7
  • Release event: 2
  • Watch event: 3
  • Delete event: 10
  • Issue comment event: 7
  • Public event: 1
  • Push event: 14
  • Pull request review event: 6
  • Pull request event: 20
Last Year
  • Create event: 10
  • Issues event: 7
  • Release event: 2
  • Watch event: 3
  • Delete event: 10
  • Issue comment event: 7
  • Public event: 1
  • Push event: 14
  • Pull request review event: 6
  • Pull request event: 20

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 4
  • Total pull requests: 16
  • Average time to close issues: about 8 hours
  • Average time to close pull requests: 2 days
  • Total issue authors: 2
  • Total pull request authors: 2
  • Average comments per issue: 1.25
  • Average comments per pull request: 0.06
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 13
Past Year
  • Issues: 4
  • Pull requests: 16
  • Average time to close issues: about 8 hours
  • Average time to close pull requests: 2 days
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 1.25
  • Average comments per pull request: 0.06
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 13
Top Authors
Issue Authors
  • Antibraatz (3)
  • clmcavaney (1)
Pull Request Authors
  • dependabot[bot] (13)
  • btschwertfeger (3)
Top Labels
Issue Labels
bug (1)
Pull Request Labels
dependencies (13) github_actions (5) bug (1) documentation (1)