btschwertfeger/tasmota-plug-monitoring
Grafana, InfluxDB, and MQTT setup for monitoring electricity consumption measured by Tasmota smart plugs.
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.
Requirements
- Docker
- Docker Compose
- Tasmota plug(s), e.g. https://www.amazon.de/dp/B0CHMMKZCQ
Setup and Configuration
-
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). -
Install the latest version of Tasmota on your devices.
-
Create a password file for mosquitto by running the official docker image to
execute themosquitto_passwdcommand.docker run -it eclipse-mosquitto:latest sh $ mosquitto_passwd -c passwd_file mqtt_user Password: ******** Reenter password: ******** $ cat passwd_file mqtt_user:................
Copy the content of
passwd_fileinto./mosquitto/passwd_fileon your host
system.Do not change the path to
passwd_filefile within
./mosquitto/mosquitto.conf. This file must be present in the working
directory in which docker is run later on. -
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.# InfluxDB export INFLUXDB_HOST="http://192.168.2.141:8086" export INFLUXDB_USERNAME="influxdb_user" export INFLUXDB_PASSWORD="influxdb_password" export INFLUXDB_DATABASE="smart_home" export INFLUXDB_ORG="smart_home" export INFLUXDB_TOKEN="You have to create a token in the influxdb IU" # MQTT export MQTT_HOST="192.168.2.141" export MQTT_USERNAME="mqtt_user" export MQTT_PASSWORD="${INFLUXDB_PASSWORD}"
docker compose up
-
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". -
Stop the services started using Docker Compose and update the
INFLUXDB_TOKENwith the newly created token.docker compose down export INFLUXDB_TOKEN="<the new token>" docker compose up -d
-
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_USERNAMEandMQTT_PASSWORDenvironment 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. -
Increase the frequency of publishing metrics by setting
TelePeriod 10in
the Tasmota console ("Tools" -> "Console"). This will ensure that the metrics
are updated every 10 seconds. -
Login to the Grafana web UI at http://192.168.2.141:3000/ using the default
credentialsadminandadmin.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.
-
Now its time to import the Dashboard provided in this repository via
copy-pasting the content of thegrafana/dashboard.jsonfile 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". -
You may have to adjust the
price_per_kWhvariable 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. - In case the device don't auto-popup the config page when connecting with the
Smart Plugs' Hotspot, you can enter the page via http://192.168.4.1. - Resetting the WLAN settings for Tasmota Smart Plugs can be done by pressing
the button 6 times (tested with Tasmota >= v15). Sometimes it needs a few
tries.
