Install
openclaw skills install mijia-controlControl Xiaomi Mi Home (米家) smart devices via Xiaomi Cloud API. Use when: user wants to control smart home devices (lights, AC, heater, bath heater, switches, etc.), check device status, or create automation scenes. Triggers: "开灯", "关灯", "开空调", "关空调", "开浴霸", "我要洗澡", "设备状态", "创建场景", "自动化", "米家", "smart home", "turn on/off", any home device control request. NOT for: non-Xiaomi devices, HomeKit-only devices.
openclaw skills install mijia-controlControl Xiaomi smart home devices and create automations via cloud API.
Prerequisites: pip3 install micloud
Credentials: ~/.mijia_creds.json (chmod 600)
{"userId":"...", "serviceToken":"...", "ssecurity":"...", "cUserId":"..."}
If login requires 2FA (device trust verification), obtain credentials via browser:
https://account.xiaomi.com/pass/serviceLogin?sid=xiaomiio&_json=true in browser with existing cookiesserviceLoginAuth2 with hash password to get ssecurity + locationlocation URL to get serviceToken from cookiespython3 scripts/mijia.py devices
python3 scripts/mijia.py get <did> <siid> <piid>
python3 scripts/mijia.py set <did> <siid> <piid> <value>
# value: true/false for bool, integer for uint8, etc.
Note: Mesh devices (BLE switches) return code:1 on set — this is normal (async confirmation). The command still executes. Verify by reading the property after a 1-2 second delay.
Create a JSON file with commands:
[
{"did": "946635824", "siid": 2, "piid": 1, "value": true},
{"did": "946633803", "siid": 2, "piid": 1, "value": false}
]
python3 scripts/mijia.py batch /tmp/commands.json
Each device has services (siid) → properties (piid). Look up specs at:
https://home.miot-spec.com/spec/<model>
Common patterns:
python3 scripts/mijia.py scene_create scene.json
Scene JSON format (see references/scene_template.json):
{
"name": "回家自动开灯",
"identify": "homelight_1234",
"st_id": 8,
"setting": {"enable": 1, "enable_push": 0},
"trigger": {
"key": "event.<did>.<siid>.<eiid>",
"did": "<trigger_device_did>",
"model": "<model>",
"extra": "{\"siid\":2,\"eiid\":1}"
},
"action_list": [
{
"did": "<target_device_did>",
"model": "<model>",
"extra": "{\"props\":[{\"siid\":2,\"piid\":1,\"value\":true}]}",
"type": "device_ctrl"
}
]
}
Key fields:
trigger.key: format event.<did>.<siid>.<eiid> for device eventslaunch.attr_filter: optional conditions (e.g., only if light is off)action_list[].extra: JSON string with props arrayst_id: 8 = user automationhome_id and uid are auto-filled if omittedWhen user says "我要洗澡":
get 927361805 10 1set 927361805 3 1 1 (暖风), target 30°Cset 965879649 2 1 1, set 43°C: set 965879649 2 2 43set 946635824 2 1 trueFeeds fish once per day when BOSS leaves home.
Architecture:
/user/get_user_device_data~/.fish_feed_state.json: tracks last feed dateComponents:
2.1020, action=1 = auto-lock (leaving home)"in": [1] 而不是 [{"piid":5,"value":1}]scripts/fish_auto_feed.pyManual commands:
python3 scripts/fish_auto_feed.py # Normal run
python3 scripts/fish_auto_feed.py --dry-run # Check without feeding
python3 scripts/fish_auto_feed.py --force # Feed regardless
python3 scripts/fish_auto_feed.py --status # Show state
Trigger logic:
Make the XiaoAI speaker say something aloud.
python3 scripts/mijia.py tts <did> "<text>"
# Example: python3 scripts/mijia.py tts 100783118 "你好"
Flow: unmute → play-text → wait → pause playback → re-mute. This prevents the speaker from auto-playing music after TTS.
Important:
Tokens expire periodically. If API returns decode errors or auth failures:
~/.mijia_creds.json with new serviceToken and ssecurityThe ssecurity changes each login. The serviceToken is session-bound.