A Node.js script to discover and control TP-Link Tapo smart devices using their local API with Lodash utilities and command-line filtering.
- 🔍 Scan network for Tapo devices
- 🎛️ Control device power states (on/off)
- 🔎 Filter devices by nickname
- 📊 Detailed device information logging
- 🔄 Automatic retry mechanism for failed operations
- Node.js 18.x or higher
- TP-Link Tapo compatible smart devices
- Network access to device IPs
- Clone the repository:
git clone https://github.com/nidhhoggr/iot-device-controller.git
cd iot-device-controller- Install dependencies:
npm install- Create a
config.jsonfile:
{
"tapo": {
"email": "your@tapo.email",
"password": "yourPassword123"
},
"plug_probe": {
"networkPrefix": "192.168.0",
"expectedResponse": "<html><body><center>200 OK</center></body></html>",
"cacheTtlMs": 1800000,
"concurrentRequests": 30,
"cacheFile": "/../../cache/ip-scanner-cache.json"
"scanTimeout": 5000
}
}node toggle.jsnode toggle.js --nickname "Basking Lamp"node toggle.js --debugnode toggle.js --help| Option | Description |
|---|---|
-n, --nickname |
Filter devices by nickname (partial match) |
-d, --debug |
Enable verbose debug logging |
-h, --help |
Display help information |
iot-device-controller/
├── src/
│ ├── toggle.js # Main control script
│ ├── utils/ # Utility modules
│ └── iot-probe/ # Device discovery
├── config.json # Configuration file
├── cache/ # Cache directory
├── package.json
└── README.md
Modify config.json to adjust:
- IP range for scanning
- Scan timeout duration
- Operation delay intervals
- Retry attempt counts
The script includes comprehensive error handling for:
- Device connection failures
- Authentication errors
- Network timeouts
- Power state mismatches
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is not affiliated with TP-Link. Use at your own risk with compatible Tapo devices.