Tuyapower

Python module to read status and energy monitoring data from Tuya based WiFi smart devices. This includes state (on/off), current (mA), voltage (V), and power (wattage).

Internet of Things (IoT)PythonMIT

Abstract

Tuyapower is an open-source Internet of Things (IoT) project. Python module to read status and energy monitoring data from Tuya based WiFi smart devices. This includes state (on/off), current (mA), voltage (V), and power (wattage). This module uses the python tinytuya or pytuya library to poll Tuya compatible Smart Plugs, Switches and Lights for state and power data that can be used for point in time monitoring or stored for trending. There are two test scripts here. It is built using Python. Key capabilities include: deviceInfo - Poll device and return on, w, mA, V and err data; deviceRaw - Poll device and return raw response data; devicePrint - Poll device and print formatted output to stdout. The complete source code is publicly available on GitHub under the MIT License, making it a useful reference for students building an Internet of Things (IoT) mini project or final-year project.

1. Introduction

This module uses the python tinytuya or pytuya library to poll Tuya compatible Smart Plugs, Switches and Lights for state and power data that can be used for point in time monitoring or stored for trending. There are two test scripts here. The plugpower.py script responds with a human readable output of state (on/off), current (mA), voltage (V), and power (W). The plugjson.py script responds with JSON containing the same but adds a timestamp for convenient time series processing.

This python module will poll WiFi Tuya compatible Smart Plugs/Switches/Lights for state (on/off), current (mA), voltage (V), and power (wattage).

2. Objective

Python module to read status and energy monitoring data from Tuya based WiFi smart devices. This includes state (on/off), current (mA), voltage (V), and power (wattage).

This project demonstrates how Python can be applied to a real-world Internet of Things (IoT) problem.

3. Key Features / Modules

  • deviceInfo - Poll device and return on, w, mA, V and err data.
  • deviceRaw - Poll device and return raw response data.
  • devicePrint - Poll device and print formatted output to stdout.
  • deviceJSON - Poll device and return JSON formatted details.
  • deviceScan(verbose, max_retries=15) - Scans network for smart plug devices and return dictionary of devices and power data.

4. Technology Stack

Python

5. System Requirements

General requirements for this technology stack — check the README for exact versions.

  • Python 3.8 or later
  • pip / virtualenv for dependencies
  • VS Code, PyCharm or Jupyter Notebook
  • Git (to clone the repository)

6. Installation & Setup

git clone https://github.com/jasonacox/tuyapower.git
cd tuyapower
# Install required libraries
 sudo apt-get install python-crypto python-pip  # for RPi, Linux
 python3 -m pip install pycryptodome            # or pycrypto, pyaes, Crypto
 python3 -m pip install tinytuya                # or pytuya
 python3 -m pip install tuyapower               # Pull this tuyapower module from PyPi
# Friendly Output
# Run tuyapower container - replace with device ID, IP and VERS
docker run -e PLUGID="01234567891234567890" \
    -e PLUGIP="10.0.1.x" \
    -e PLUGKEY="0123456789abcdef" \
    -e PLUGVERS="3.3" \
    jasonacox/tuyapower

# JSON Output
# Run tuyapower container - replace with device ID, IP and VERS
docker run -e PLUGID="01234567891234567890" \
    -e PLUGIP="10.0.1.x" \
    -e PLUGKEY="0123456789abcdef" \
    -e PLUGVERS="3.3" \
    -e PLUGJSON="yes" \
    jasonacox/tuyapower

Full setup instructions are in the project README.

7. Future Enhancements

Suggested extensions you can add to make this your own project.

  • Add a mobile dashboard using Blynk or Firebase
  • Store readings in a cloud database for history charts
  • Add alerts via SMS / Telegram when thresholds are crossed

8. Viva / Review Questions

Common questions examiners ask for projects in this domain.

  1. Which microcontroller / board and sensors are used and why?
  2. How does the device send data (Wi-Fi, MQTT, HTTP, Bluetooth)?
  3. Where is the sensor data stored and visualised?
  4. How is power consumption managed?
  5. How would you secure the device and its communication?

9. Source Code & License

This project is developed by jasonacox and published on GitHub under the MIT License. Please follow the license terms and credit the original author when you use or modify this code.

Want to build this as your internship project?

Work on an Internet of Things (IoT) project like this with mentor guidance, weekly reviews and an internship certificate from Training Trains, Erode — online or offline.

Apply for Internet of Things (IoT) Internship