参考中文教程: https://www.hachina.io/docs/7230.htmlhtml
mqtt:
# 此处为mqtt原有的一些配置
# ……
# 配置自动发现
discovery: true
# 自动发现使用的主题位置前缀,缺省为homeassistant
discovery_prefix: homeassistant
<discovery_prefix>/<component>/[<node_id>/]<object_id>/config
<discovery_prefix>
:配置文件中的discovery_prefix,缺省为homeassistant<component>
:设备所在的域,例如light、switch、binary_sensor等<node_id>
:可选,节点ID<object_id>
:设备ID配置信息采用JSON格式。node
例如,MQTT设备在主题:git
homeassistant/switch/irrigation/config
发布信息:github
{"name": "garden", "command_topic": "hachina/switch/irrigation/set", "state_topic": "hachina/switch/irrigation/state"}
当HomeAssistant读取此信息,至关于配置文件中存在如下内容:spa
switch:
- platform: mqtt
name: "garden"
command_topic: "hachina/switch/irrigation/set"
state_topic: "hachina/switch/irrigation/state"
打开手机mqtt调试助手调试
在hass配置信息话题上发布本身的消息code
远程登陆hass,咱们发现自动多出一一个设备component
设备类型 开关orm
名字 gardenhtm
说明:
灯光这个设备,是以前咱们本身手动在配置文件中添加的
警告:
自动发现设备的时候,必定要改配置话题第三个参数ID,
第一个设备 名字 RGBlight ID garden 存在
homeassistant/light/garden/config
{"name": "RGBlight", "command_topic": "hachina/rgb1/light/switch",
第二个设备 名字light ID garden1 存在
homeassistant/light/garden1/config
{"name": "light", "command_topic": "hachina/rgb1/light/switch",
第三个设备 名字light ID garden2 存在
homeassistant/light/garden2/config
{"name": "light", "command_topic": "hachina/rgb1/light/switch",
第四个设备 名字light ID garden 不存在
homeassistant/light/garden/config
{"name": "light", "command_topic": "hachina/rgb1/light/switch",
ID和第一个配置ID冲突,只能存在一个