Take XiaoMi Cloud Service to the command line.
MiCLI is a powerful CLI tool for controlling MIoT devices, XiaoAi speakers (Mina), and MiHome devices. It supports device property reading/writing, TTS synthesis, AI conversations, and more.
- π MIoT Device Control - Read and write device properties
- π XiaoAi Speaker - TTS, playback control, voice records
- π€ AI Integration - ChatGPT integration for smart conversations
- ποΈ Edge TTS - Microsoft Edge TTS without API key
- π± QR Code Login - Scan QR code with Mi Home app to authenticate
- π Web Server - Built-in Gin server for extended functionality
- βοΈ Automation - Keyword-based command chaining via
commands.json
git clone https://github.com/WangNingkai/micli.git
cd micli
go build -o micli- Go 1.25 or higher
- XiaoMi account
Run any command for the first time, it will create conf.ini interactively:
./micli listConfiguration options:
MI_USER/MI_PASS- XiaoMi account credentialsREGION- Region (cn/de/us/i2/ru/sg/tw)MI_DID- Default device DID- OpenAI settings (optional)
./micli list# Get device properties
./micli get -d <device_id> --props <prop1>,<prop2>
# Set device properties
./micli set -d <device_id> --props <prop1>=<value1>Property format: siid-piid (e.g., 2-1 for service 2, property 1)
# Execute MIoT action
./micli action <device_id> <siid-aiid> [args...]# TTS synthesis
./micli mina tts -d <device_id> --text "Hello, World!"
# List XiaoAi devices
./micli mina list
# Player control (play/pause/volume)
./micli mina player <command>
# Get voice records
./micli mina records [limit]
# Set default XiaoAi device
./micli mina set_did
# Start AI conversation mode
./micli mina serve# Interactive voice selection
./micli tts -t "δ½ ε₯½οΌδΈη"
# Specify voice
./micli tts -t "Hello" -v en-US-JennyNeural# Generate QR code for Mi Home app scan
./micli qr-login| Command | Description |
|---|---|
list |
List all devices |
get |
Get MIoT device properties |
set |
Set MIoT device properties |
action <iid> [args] |
Execute MIoT action |
spec [model] |
Show MIoT specification |
decode |
Decode MIoT encrypted data |
mina |
XiaoAi speaker commands |
mina list |
List XiaoAi devices |
mina tts |
TTS for XiaoAi |
mina player |
Player control (play/pause/volume) |
mina records [limit] |
Get voice conversation records |
mina serve |
Start web server + AI conversation |
mina set_did |
Set default XiaoAi DID |
tts -t <text> |
Edge TTS synthesis |
miot_raw <cmd> <params> |
Raw MIoT API call |
miio_raw <uri> <data> |
Raw MiIO API call |
set_did |
Set default MIoT DID |
qr-login |
QR code authentication |
reset |
Reset configuration |
Create commands.json (see commands.sample.json for examples) to define keyword-triggered automation chains:
[
{
"keyword": "倩ζ°ζδΉζ ·",
"step": [
{
"type": "request",
"request": {
"url": "http://www.weather.com.cn/data/sk/101010100.html",
"out": "res.data",
"wait": true
}
}
]
},
{
"keyword": "εΌε―ι«ηΊ§ε―Ήθ―",
"type": "chat",
"chat": {
"endFlag": "ε
³ιι«ηΊ§ε―Ήθ―",
"stream": true,
"useEdgeTTS": false
}
}
]Step types: tts, request, action, chat (ChatGPT)
Find your device specification at miot-spec.
Configuration file: conf.ini
[app]
DEBUG = false
PORT = :8080
[account]
MI_USER = your_email@example.com
MI_PASS = your_password
REGION = cn
MI_DID =
[mina]
DID = your_device_did
[openai]
KEY = sk-xxx
BASE_URL = https://api.openai.com/v1
[file]
TRANSFER_SH = https://transfer.shToken cache: ~/.mi.token
main.go β cmd.Execute() (Cobra)
β
ββ cmd/ # Cobra commands
β ββ root.go # Config & service init
β ββ mina*.go # XiaoAi commands
β ββ props_*.go # MIoT operations
β ββ action.go # MIoT actions
β ββ spec.go # MIoT spec viewer
β ββ miot_raw.go # Raw MIoT API
β ββ miio_raw.go # Raw MiIO API
β ββ tts.go # Edge TTS command
β ββ decode.go # MIoT decoder
β ββ set_did.go # Set default DID
β ββ qr_login.go # QR authentication
β ββ reset.go # Reset config
β
ββ pkg/
β ββ miservice/ # XiaoMi API core
β β ββ service.go # Auth & requests
β β ββ mina.go # XiaoAi API
β β ββ io.go # MIoT/MiIO ops
β β ββ token.go # Token storage
β β ββ qrlogin.go # QR login
β ββ jarvis/ # ChatGPT integration
β ββ tts/ # Edge TTS
β ββ util/ # Utilities (signing, crypto)
β
ββ internal/
β ββ app.go # Gin server
β ββ conf/ # Configuration
β ββ handlers/ # HTTP handlers
β ββ middleware/ # CORS middleware
β ββ static/ # Static files
β
ββ public/ # Embedded frontend (embed.FS)
β ββ dist/ # Frontend build output
β
ββ data/ # Local cache
ββ devices.json # Device list cache
ββ miot-spec.json # MIoT spec cache
# Run
go run main.go [command]
# Build
go build -o micli
# Test
go test ./...
# Test with race detection
go test -race ./...
# Lint
golangci-lint runGitHub Actions builds binaries for Linux (amd64/arm64), macOS, and Windows on version tags (excluding -alpha*).
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Cobra - CLI framework
- Gin - Web framework
- go-openai - OpenAI API client
- pterm - Terminal UI
- req - HTTP client
- Edge TTS - Microsoft Edge TTS
Disclaimer: This project is for educational purposes only. Use at your own risk.