A robust Python application to control a TP-Link Tapo P100 smart plug for automating flood and drain cycles in a hydroponic system. This solution overcomes the Tapo app's 32-event limit by running unlimited cycles locally on your Mac.
- Unlimited Cycles: No restriction on the number of flood/drain cycles.
- Flexible Scheduling:
- Interval-Based: Simple flood/drain/wait cycles.
- Time-Based: Specific ON times throughout the day with configurable OFF durations.
- MCP (Model Context Protocol): Control your hydroponic system from AI assistants — Cursor, Claude Desktop, or any MCP client. Check status, turn the pump on/off, start or stop the scheduler, update schedules, and view logs without leaving your AI workflow.
- Web UI: Simple web interface for real-time monitoring and manual control.
- Error Recovery: Automatic retry on connection failures with state verification.
- Graceful Shutdown: Ensures the pump is off when the application stops.
- Logging: Detailed logging of all system events.
- Python 3.9+
- macOS (recommended for background daemon features)
- TP-Link Tapo P100 smart plug
- Clone the repository
- Create a virtual environment:
python3 -m venv venv source venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Configure:
Edit
cp config/config.json.example config/config.json
config/config.jsonwith your Tapo credentials and desired schedule.
# Activate virtual environment
source venv/bin/activate
# Start the application
python -m src.mainEnable the web interface in config/config.json:
"web": {
"enabled": true,
"host": "0.0.0.0",
"port": 8000
}Access at http://localhost:8000.
A single-file React UI is included for monitoring and control without running a local server. It talks to the daemon API over CORS.
-
Ensure the daemon is running (e.g.
python -m src.mainor the LaunchAgent). The API must have CORS enabled (it does by default, includingfile://origin). -
Open the file in a browser:
open hydro-standalone.html
Or double-click
hydro-standalone.htmlin Finder. The page loads React from a CDN and useshttp://localhost:8000/apifor all requests. -
If you see connection errors, confirm the daemon is listening on port 8000 and that you are opening the HTML from the project directory (or that your browser allows the request from your open location).
No build step is required; the script is plain JavaScript (no in-browser Babel).
The MCP server lets you monitor and control your hydroponic system from Cursor, Claude Desktop, or any MCP-compatible AI client. Ask your AI assistant to check status, turn the pump on or off, start/stop the scheduler, adjust schedules, or pull logs — all without opening the web UI.
Quick setup: Run ./setup_mcp.sh to install dependencies and print the exact config for your installation.
-
Install MCP dependencies:
pip install -r requirements-mcp.txt
-
Configure your AI client:
- Cursor: Settings → MCP → Add server. Use the config printed by
./setup_mcp.sh. - Claude Desktop: Add the config to
~/Library/Application Support/Claude/claude_desktop_config.json.
See
MCP_SETUP_INSTRUCTIONS.txtfor detailed setup and troubleshooting. - Cursor: Settings → MCP → Add server. Use the config printed by
-
Test (optional):
python -m src.mcp_server
Available tools: hydro_get_status, hydro_get_device_info, hydro_get_logs, hydro_get_config, hydro_get_schedule, hydro_device_on, hydro_device_off, hydro_scheduler_start, hydro_scheduler_stop, hydro_update_schedule.
src/main.py: Application entry point and service orchestration.src/core/: Configuration schema and scheduler factory.src/schedulers/: Core scheduling logic (Interval and Time-based).src/services/: Device abstraction and registration.src/web/: FastAPI web server and simple JavaScript UI.src/mcp_server.py: MCP server for AI-powered monitoring and control.
- Energy monitoring: The Tapo P100 is on/off only (no current, voltage, or power reporting). Supporting Tapo P110 or P115 in future would allow power/energy monitoring (e.g. pump run verification, usage tracking).
- Mac Sleep Prevention: Use
caffeinateor Amphetamine to keep the controller running. - Daemon Mode: Use
./scripts/install_daemon.shto run as a macOS background service. - Logging: Check
logs/hydro_controller.logfor system status.
If you move the project folder, run the post-move fix script to update the daemon, venv, and MCP paths:
./scripts/fix_after_move.shThis recreates the virtual environment (venvs break when moved), reinstalls the LaunchAgent daemon with correct paths, and prints the Claude Desktop config to update manually.
Disclaimer: This software is provided without warranty. Ensure proper electrical and water safety when automating hydroponic systems.