The api command in deyecli.py exposes all CLI commands as HTTP REST endpoints, making it easy to integrate with:
- Home Assistant (remote control of battery charging)
- Node-RED (automation flows)
- Mobile apps (custom integrations)
- Third-party home automation systems
./deyecli.py apiThis starts the server on http://0.0.0.0:8000 (all interfaces, port 8000)
In another terminal:
curl -X GET "http://localhost:8000/api/station/list" \
-H "Authorization: Bearer YOUR_TOKEN"See homeassistant_example.yaml for a complete Home Assistant configuration example.
┌─────────────────────────┐
│ Home Assistant │ ← Remote instance
│ (or other app) │
└────────────┬────────────┘
│
│ HTTP Request
│ e.g., POST /api/battery/parameter/update
│
▼
┌─────────────────────────────────────────┐
│ deyecli.py (HTTP REST server) │ ← localhost:8000
│ ┌─────────────────────────────────┐ │
│ │ HTTP Request Handler │ │
│ └────────────┬────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────┐ │
│ │ Route to CLI command │ │
│ │ (e.g., battery-parameter-update) │ │
│ └────────────┬────────────────────┘ │
│ │ │
└────────────────┼─────────────────────────┘
│
▼
┌─────────────────────┐
│ Deye Cloud API │
│ (REST endpoints) │
└─────────────────────┘
| File | Purpose |
|---|---|
| deyecli.py | Unified CLI + integrated HTTP REST server |
| README_API.md | Complete API documentation with all endpoints |
| homeassistant_example.yaml | Home Assistant integration template |
| test_api.sh | Simple test script for API endpoints |
# Start server on default port (8000)
./deyecli.py api
# Start on custom port
./deyecli.py api --port 9000
# Start on custom host and port
./deyecli.py api --host 192.168.1.100 --port 8080POST /api/token- Get access tokenGET /api/station/list- List all stationsGET /api/station/latest- Get station real-time dataGET /api/device/latest- Get device raw dataGET /api/config/battery- Read battery configGET /api/config/system- Read system configPOST /api/battery/parameter/update- Update battery parametersPOST /api/solar-charge-cron- Generate solar charge automation
Pass your bearer token via the Authorization header:
curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8000/api/station/listOr in the request body:
curl -X POST http://localhost:8000/api/station/latest \
-H "Content-Type: application/json" \
-d '{"token": "YOUR_TOKEN", "station_id": "123456"}'Home Assistant automation using the API:
automation:
- alias: "Reduce charge when sunny"
trigger:
platform: time
at: "10:00:00"
action:
- service: rest_command.deye_set_charge_current
data:
charge_current: "30" # Reduce to 30AUse the provided test script:
./test_api.sh # Test on localhost:8000
./test_api.sh 192.168.1.100:8000 # Test on specific host:portSet environment variables for full testing:
export DEYE_TOKEN="your-bearer-token"
export DEYE_DEVICE_SN="your-device-sn"
export DEYE_STATION_ID="your-station-id"
./test_api.shCreate /etc/systemd/system/deye-api.service:
[Unit]
Description=Deye CLI API Server
After=network.target
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/deyecli
ExecStart=/home/pi/deyecli/deyecli.py api --host 0.0.0.0 --port 8000
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetInstall and run:
sudo systemctl enable deye-api
sudo systemctl start deye-api
sudo systemctl status deye-apiView logs:
sudo journalctl -u deye-api -f- Always use HTTPS in production - Use a reverse proxy (nginx) with SSL/TLS
- Don't expose to the Internet without proper authentication and firewall rules
- Secure your config file - Run
chmod 600 ~/.config/deyecli/config - Use strong credentials - Store tokens securely in Home Assistant
- Run as non-root - Never run the server as root
lsof -i :8000 # Find process using the port
./deyecli.py api --port 9000 # Use a different portCheck if Python 3 is available:
python3 --versionIncrease curl timeout or check network connectivity:
curl --max-time 60 http://localhost:8000/api/station/list- See README_API.md for complete endpoint documentation
- See homeassistant_example.yaml for Home Assistant setup
Status: ✅ Ready for use
Requirements:
- Python 3.6+ (built-in
http.server,socketmodules) - Valid Deye Cloud credentials configured in
~/.config/deyecli/config - Network access to Deye Cloud API
Optional dependency:
pip install requests— recommended for better HTTP support