本帖最后由 anlong 于 2022-1-5 15:44 编辑
小爱音响在通过 Xiaomi Miot Auto 插件接入到HA后会生成一个 media_player 实体,该实体可以控制播放暂停、调节音量和静音等。很多朋友会觉得没什么用,甚至有时候还控制不了。
其实更多的功能需要通过HA服务去调用,服务还可被用于自动化、脚本、模板实体等。本插件为小爱提供了 xiaomi_miot.intelligent_speaker 服务可以实现TTS和执行语音命令。
调试HA服务可以进入:开发者工具 > 服务
让小爱朗读文本(TTS):
service: xiaomi_miot.intelligent_speaker
data:
entity_id: media_player.xiaomi_entity_id
text: 要朗读的文本
execute: false # false为不执行,朗读文本
让小爱执行语音命令(控制米家设备):
service: xiaomi_miot.intelligent_speaker
data:
entity_id: media_player.xiaomi_entity_id
text: 打开客厅的小米电视
execute: true # true执行语音命令
silent: true # true为静默执行,小爱音响不回应执行结果
温馨提示:部分小米电视(支持小爱同学)也可用此服务执行语音命令,但是由于协议限制,无法TTS
下面是一个使用小爱服务结合模板生成一个虚拟的风扇实体的例子:
# configuration.yaml
fan:
- platform: template
# https://www.home-assistant.io/integrations/fan.template
fans:
xiaoai_fan:
friendly_name: "小爱风扇"
value_template: "{{ states('input_boolean.xiaoai_fan_state') }}" # 创建一个辅助元素记录状态
percentage_template: 0
preset_mode_template: ""
oscillating_template: false
speed_count: 3
preset_modes:
- 直吹风
- 自然风
turn_on:
- service: xiaomi_miot.intelligent_speaker
data:
entity_id: media_player.xiaoai_entity_id # 改成你的小爱实体ID
text: 打开风扇
execute: true
silent: true
- service: input_boolean.turn_on
target:
entity_id: input_boolean.xiaoai_fan_state
turn_off:
- service: xiaomi_miot.intelligent_speaker
data:
entity_id: media_player.xiaoai_entity_id # 改成你的小爱实体ID
text: 关闭风扇
execute: true
silent: true
- service: input_boolean.turn_off
target:
entity_id: input_boolean.xiaoai_fan_state
set_percentage:
service: xiaomi_miot.intelligent_speaker
data:
entity_id: media_player.xiaoai_entity_id # 改成你的小爱实体ID
text: "风扇风速调到{{ percentage }}"
execute: true
silent: true
set_preset_mode:
service: xiaomi_miot.intelligent_speaker
data:
entity_id: media_player.xiaoai_entity_id # 改成你的小爱实体ID
text: "风扇模式切换为{{ preset_mode }}"
execute: true
silent: true
set_oscillating:
service: xiaomi_miot.intelligent_speaker
data:
entity_id: media_player.xiaoai_entity_id
text: "{{ '风扇摇头' if oscillating else '风扇停止摇头' }}"
execute: true
silent: true
总的来说,小爱同学通过 Xiaomi Miot Auto 接入HA后除了不能获取设备状态,可以TTS及控制任意米家设备。通过自动化、模板实体可以实现很多的DIY功能。
|