Conversation
Conversation 集成允许您与 Home Assistant 进行对话。您可以通过在前端按下麦克风(仅支持部分浏览器,不支持 iOS)或通过调用带有转录文本的 conversation.process 动作来进行对话。
Home Assistant 对话界面截图。
默认语句
默认情况下,Home Assistant 支持不断扩展的语言列表中的社区贡献语句。
以英语为例,如果您有一个名为 "bedroom" 的区域,您可以说 "turn on kitchen lights" 或 "turn off lights in the bedroom" 这样的句子。
添加自定义语句
您可以添加自己的语句模板来教 Home Assistant 新语句。这些语句可以与内置 intent一起工作,或通过intent script 集成定义自定义 intent 来触发自定义动作。
首先,在您的 Home Assistant config 目录中创建 custom_sentences/<language> 目录,其中 <language> 是您语言的语言代码,例如英语为 en。这些 YAML 文件会自动合并,可以包含 intent、列表或扩展规则。
以英语为例,创建文件 config/custom_sentences/en/temperature.yaml 并添加:
要教 Home Assistant 如何处理自定义 CustomOutsideHumidity intent,在您的 "configuration.yaml" 文件中创建一个 intent_script 条目:
更复杂的动作可以在 intent_script 中完成,例如执行动作和触发事件。
扩展内置 intent
扩展内置 intent,如 HassTurnOn 和 HassTurnOff,也可以做到。
例如,创建文件 config/custom_sentences/en/on_off.yaml 并添加:
现在,当您说 "engage the kitchen lights" 时,它会打开名为 "kitchen lights" 的灯;说 "disengage kitchen lights" 则会将其关闭。
接下来,您也可以把这种方式扩展到其他实体。内置的 {name} 和 {area} 列表包含了您在 Home Assistant 中的实体名称和区域名称。
将 {name} 添加到 config/custom_sentences/en/on_off.yaml:
现在,您可以对任何实体使用 "engage" 或 "disengage" 这样的说法。
最后,再添加一些用于控制特定区域灯光的语句:
现在,您可以说 "engage all lights in the bedroom",这会打开名为 "bedroom" 的区域中的所有灯。
动作 conversation.process
向对话代理发送消息进行处理。
此动作能够返回响应数据。响应与
/api/conversation/process API的响应相同。

