可以通过电脑连接一个实体Android机来实现控制小米智能家居。
PS:其实也可以安python-miio这种库实现,但是怕封号
首先需要实体手机登录好米家,然后在“智能”里面创建手动控制,把需要的动作配置好之后,长按建立好的手动控制,在桌面创建快捷方式。
通过以下指令来列出机器上所有米家的快捷方式:
adb shell cmd shortcut dump com.xiaomi.smarthome | less然后搜索快捷方式的名字,找到对应的块,最重要的是找extra_scene_account和 extra_str_scene_id 这两块,记录下数据。
最后可以通过adb对米家发Intent,填上上面两块的内容即可:
def build_adb_command(scene_id: str) -> list[str]:
return [
"adb",
"shell",
"am",
"start",
"-a",
"com.xiaomi.smarthome.scene.smarthomelauncher",
"-n",
"com.xiaomi.smarthome/.scene.activity.SmartHomeLauncherActivity",
"-f",
"0x10000000",
"--es",
"extra_scene_account",
SCENE_ACCOUNT,
"--es",
"extra_str_scene_id",
scene_id,
]