A Flask-based REST API that provides HTTP access to Belkin WeMo smart home devices using the pywemo library.
DISCLAIMERS
I know enough Python and Flask to be dangerous but this is 100% "vibe coded" using GitHub Copilot with ChatGPT for the API and Claude Sonnet 4 for the web UI.
This might be the worst, ugliest, buggiest, most inefficient, most insecure implementation! You've been warned!
I only have Belkin WeMo smart plugs and it works well enough for these. I can't speak to the functionality of other types of devices.
Please don't ask me for support! You'll probably get better answers from ChatGPT! ;)
The modern web interface for controlling your WeMo devices
- Scheduling
- "Away mode" for random on/off functionality
- Device Discovery: Automatically discover WeMo devices on your network
- Manual Device Addition: Add devices by IP address
- Dynamic Method Calling: Call any public method on discovered devices via HTTP
- RESTful Interface: Simple HTTP API for device control and monitoring
- Docker Support: Easy deployment with Docker and Docker Compose
# Clone or download the project
cd pywemo-api
# Start the service
docker-compose up -d
The API will be available at http://localhost:5000
π New Web Interface: Open http://localhost:5000
in your browser to access the user-friendly web interface for controlling your WeMo devices!
-
Install Python dependencies:
pip install -r requirements.txt
-
Run the application:
python app.py
PyWemo API now includes a modern, responsive web interface that makes it easy to control your WeMo devices without writing code or using command-line tools.
- π± Responsive Design: Works on desktop, tablet, and mobile devices
- π Auto-Discovery: Automatically finds and displays all WeMo devices on your network
- ποΈ Device Control: Easy-to-use interface for controlling any device method
- β Manual Discovery: Add devices manually by IP address
- π Real-time Status: Get instant feedback on device operations
- π§ Method Explorer: Browse and execute any available device method with parameters
- π« Duplicate Prevention: Automatically prevents adding the same device multiple times
- Start the PyWemo API (using Docker Compose or manually)
- Open your browser and navigate to
http://localhost:5000
- Discover devices by clicking "π Refresh Devices" or add them manually
- Control devices by clicking "π§ Control Device" on any device card
- Execute methods with optional parameters through the intuitive interface
The web interface provides:
- A clean dashboard showing all discovered devices
- Device cards with name, model, and serial information
- Quick actions like "Get State" for immediate feedback
- A method explorer modal for advanced device control
- Form-based parameter input for methods requiring arguments
GET /devices
Returns all discovered WeMo devices.
Response:
[
{
"name": "Living Room Light",
"model": "Socket",
"udn": "uuid:Socket-1_0-221517K0101769",
"serial": "221517K0101769"
}
]
POST /devices/refresh
Re-discovers all devices on the network.
Response:
{
"status": "refreshed",
"count": 2
}
POST /device/discover_by_ip
Manually add a device by its IP address.
Request Body:
{
"ip": "192.168.1.100"
}
Response (new device):
{
"name": "Living Room Light",
"model": "Socket",
"udn": "uuid:Socket-1_0-221517K0101769",
"serial": "221517K0101769",
"already_discovered": false,
"message": "Device discovered and added successfully"
}
Response (duplicate device):
{
"name": "Living Room Light",
"model": "Socket",
"udn": "uuid:Socket-1_0-221517K0101769",
"serial": "221517K0101769",
"already_discovered": true,
"message": "Device was already discovered"
}
GET /device/{udn}/methods
Returns all available public methods for a specific device.
Response:
[
"get_state",
"on",
"off",
"toggle"
]
POST /device/{udn}/{method}
GET /device/{udn}/{method}
Execute a method on the specified device.
Request Body (optional):
{
"args": [],
"kwargs": {}
}
Examples:
Turn on a switch:
curl -X POST http://localhost:5000/device/uuid:Socket-1_0-221517K0101769/on
Get device state:
curl -X GET http://localhost:5000/device/uuid:Socket-1_0-221517K0101769/get_state
Set brightness (with arguments):
curl -X POST http://localhost:5000/device/uuid:Dimmer-1_0-221517K0101770/set_brightness \
-H "Content-Type: application/json" \
-d '{"args": [75]}'
This API works with any WeMo device supported by the pywemo library, including:
- WeMo Switch - Smart plugs and wall switches
- WeMo Dimmer - Dimmable light switches
- WeMo Light Switch - Basic light switches
- WeMo Motion - Motion sensors
- WeMo Maker - DIY automation device
- WeMo Insight Switch - Smart plugs with energy monitoring
- WeMo Bulbs - Smart light bulbs
The application can be configured using environment variables:
FLASK_ENV
: Set todevelopment
for debug modePORT
: Change the default port (default: 5000)
- The API server must be on the same network as your WeMo devices
- WeMo devices use UPnP for discovery on port 1900
- Individual devices typically listen on port 49153
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run in development mode:
FLASK_ENV=development python app.py
Build and run with Docker:
docker build -t pywemo-api .
docker run -p 5000:5000 pywemo-api
- Ensure devices are on the same network: WeMo devices must be on the same subnet as the API server
- Check firewall settings: Make sure UDP port 1900 (UPnP) is not blocked
- Manual discovery: Use the
/device/discover_by_ip
endpoint if automatic discovery fails - Refresh devices: Call
/devices/refresh
if devices become unavailable
404 Device not found
: The UDN doesn't match any discovered device404 Method not found
: The requested method doesn't exist on the device400 Bad Request
: Invalid arguments passed to device method
- Flask: Web framework for the REST API
- pywemo: Python library for WeMo device control
- Python 3.11+: Recommended Python version
- Fork the repository
- Share your work with others
That's it. I have a day job so, realistically, I'm not going to be maintaining this except for my own usage.
This project is open source and available under the MIT License.
- pywemo - The underlying Python library for WeMo control
- Home Assistant WeMo Integration - WeMo integration for Home Assistant