Skip to content

WangNingkai/micli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

96 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MiCLI

Go Version License

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.

Features

  • 🏠 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

Installation

Build from Source

git clone https://github.com/WangNingkai/micli.git
cd micli
go build -o micli

Prerequisites

  • Go 1.25 or higher
  • XiaoMi account

Quick Start

1. Initialize Configuration

Run any command for the first time, it will create conf.ini interactively:

./micli list

Configuration options:

  • MI_USER / MI_PASS - XiaoMi account credentials
  • REGION - Region (cn/de/us/i2/ru/sg/tw)
  • MI_DID - Default device DID
  • OpenAI settings (optional)

2. List Devices

./micli list

3. Device Properties

# 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)

4. MIoT Actions

# Execute MIoT action
./micli action <device_id> <siid-aiid> [args...]

5. XiaoAi Speaker

# 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

6. Text-to-Speech

# Interactive voice selection
./micli tts -t "δ½ ε₯½οΌŒδΈ–η•Œ"

# Specify voice
./micli tts -t "Hello" -v en-US-JennyNeural

7. QR Code Login

# Generate QR code for Mi Home app scan
./micli qr-login

Commands Reference

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

Automation

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)

MIoT Specification

Find your device specification at miot-spec.

Configuration

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.sh

Token cache: ~/.mi.token

Architecture

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

Development

# Run
go run main.go [command]

# Build
go build -o micli

# Test
go test ./...

# Test with race detection
go test -race ./...

# Lint
golangci-lint run

CI/CD

GitHub Actions builds binaries for Linux (amd64/arm64), macOS, and Windows on version tags (excluding -alpha*).

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments


Disclaimer: This project is for educational purposes only. Use at your own risk.

About

πŸ’₯Take XiaoMi Cloud Service to the command line

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages