A local-first, cloud-free telemetry system for monitoring TP-Link Tapo Matter plugs/outlets/switches (P110m, P210M, S515) using python-kasa CLI utilities. This system logs power metrics and network health into a local SQLite database and serves a responsive web dashboard.
- Backend: Python 3 + SQLite3
- Hardware Interface: python-kasa (via --credentials-hash auth)
- Frontend: Flask + Chart.js
- Automation: System Cron
Ensure your system is updated and has the necessary packages installed.
Command: sudo apt update && sudo apt install python3-pip sqlite3 -y
Before running any code, you must check this setting, or the plug will continue to reject your "challenge":
Open the Tapo App on your phone.
Go to Me (Profile) > Settings > Third-Party Compatibility.
Ensure this is set to ON.
Optional but recommended: Log into tplinkcloud.com and verify your password. If it contains complex symbols like & or #, consider changing it to a purely alphanumeric password, as these often cause "challenge mismatch" errors in Python.
-
Clone the project directory:
Command:
cd ~ && git clone https://github.com/ChicoFabLab/PowerShift.git tapo-monitor && cd tapo-monitor -
Install python-kasa: The collector relies on the kasa command-line utility.
Command:
pip install python-kasa --upgrade -
Install Flask:
Command:
pip install flask
Run this script once to create power_data.db and the required tables for device registry and power logs.
Command: python3 initialize_system.py
Run the management tool for each device. This script handshakes with the device using your credentials, retrieves the Credentials Hash and Device Label, and saves only the hash to the database for future use. Hostname can be either a proper DNS name or an IP address.
Command: python3 manage_devices.py HOSTNAME USERNAME PASSWORD
To protect your credentials hashes, set restrictive file permissions:
Command: chmod 600 power_data.db
The collector.py script should be run every minute to capture a time-series record of your power usage.
-
Open the crontab editor: Command:
crontab -e -
Add the following line at the bottom (Replace 'user' with your actual username):
* * * * * /usr/bin/python3 /home/user/tapo-monitor/collector.py >> /home/user/tapo-monitor/collector.log 2>&1
Start the Flask server to view your live graphs and network health metrics.
Command: python3 app.py
Access the dashboard at: http://<your-ip>:5000
The system collects the following metrics every 60 seconds:
- Power: Current Watts, Today's kWh, Monthly kWh.
- Network: SSID and RSSI (Signal Strength).
- Uptime: 'On Since' timestamp for each outlet.
- State: Logical On/Off status.
Developed for local-first power hardware monitoring at ChicoFabLab. ~sfranzyshen
