參考中文教程: 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衝突,只能存在一個