A Python utility to control Tapo P300 Smart Wi-Fi Power Strips via the terminal. This script allows you to manage multiple P300 strips, control individual child sockets by nickname, and manage your device IP configuration dynamically. Please note that the actual smart power strip and the devices must be previously set via the Tapo app.
git clone [https://github.com/dessertlab/tapo.git](https://github.com/dessertlab/tapo.git)
cd tapoThis script requires the tapo Python library and asyncio.
pip install tapoThe script relies on environment variables for authentication and device discovery. You can set these manually or add them to your shell profile (e.g., ~/.bashrc).
Run the following commands to set up your environment permanently:
# Set the path to this repository
echo 'export TAPO_PATH="'$PWD'"' >> ~/.bashrc
# Set your Tapo credentials
echo 'export TAPO_USERNAME="your_email@example.com"' >> ~/.bashrc
echo 'export TAPO_PASSWORD="your_password"' >> ~/.bashrc
# Set initial P300 IPs (comma-separated)
echo 'export TAPO_P300_IPS="192.168.1.50,192.168.1.51"' >> ~/.bashrc
# Create a convenient alias
echo 'alias tapo="python3 $TAPO_PATH/tapo_control.py"' >> ~/.bashrc
# Apply changes
source ~/.bashrcOnce the alias is set, you can use the tapo command directly.
To see all connected P300 power strips and their child devices (sockets), use the list flag. This displays the Nickname you will use to control them.
tapo -lOutput example:
=== P300 at 192.168.100.120 ===
- Nickname: zcu104
Device ID: 8012...
State: ON
- Nickname: kv260
Device ID: 8013...
State: OFF
You can turn devices on, off, or reset them (power cycle) using their nickname.
Syntax:
tapo <nickname> <action>Examples:
-
Turn ON a device:
tapo kv260 on
-
Turn OFF a device:
tapo zcu104 off
-
Reset (Power Cycle) a device: Useful for rebooting stuck hardware. This turns the device OFF, waits 2 seconds, and turns it back ON.
tapo zcu102 reset
You can add or remove P300 IP addresses from your configuration directly via the CLI.
Note: This modifies your ~/.bashrc and /root/.bashrc files.
-
Add a new P300 IP:
tapo -a 192.168.1.55
-
Remove an old P300 IP:
tapo -r 192.168.1.55
To view the built-in help message and arguments:
tapo -h- "No device with nickname found": Ensure the nickname matches exactly what is shown in the
tapo -loutput or your Tapo mobile app. - Connection Errors: Ensure the IP address in
TAPO_P300_IPSis correct and the device is online.