Homeassistant接入外部MQTT
0 票
搭建mqtt服务器略。。。。。
在homeassistant/configuration.yaml 文件中添加mqtt服务器地址、端口、用户及密码。
在homeassistant/configuration.yaml 文件中添加传感器或者开关详细见:https://www.home-assistant.io/docs/mqtt/discovery/ 我这里加入的是传感器。
mqtt:
broker: $mqtt.com # MQTT服务器地址(据实际填写)
port: 1883 # MQTT端口,默认是1883
username: $user # MQTT用户名(据实际填写)
password: $password # MQTT密码(据实际填写)
# 配置自动发现
discovery: true
discovery_prefix: $home # 自动发现使用的主题位置前缀,缺省为homeassistant(据实际填写)
sensor:
- platform: mqtt # 类型mtqq
name: "Sht20T" # 实体ID
state_topic: "$home/sensor/sht20" # 主题
unit_of_measurement: "°C" # 单位
value_template: "{{ value_json.sht20.temperature }}" # json值
- platform: mqtt
name: "Sht20H"
state_topic: "$home/sensor/sht20"
unit_of_measurement: "%"
value_template: "{{ value_json.sht20.humidity }}"
我这里 mqtt发布的内容为:{“sht20”:{“temperature”:”120″,”humidity”:”100″}}
因此json取值分别为{{ value_json.sht20.temperature }} 、{{ value_json.sht20.humidity }} 具体按实际填写。
最后重启homeassistant 然后再卡片中添加对应的实体完成外部MQTT的添加。