zoukankan      html  css  js  c++  java
  • (二 -2) 天猫精灵接入Home Assistant-自动发现Mqtt设备

    参考中文教程:  https://www.hachina.io/docs/7230.html

    英文官网 两个温度传感器:https://www.home-assistant.io/docs/mqtt/discovery/
     

    1HomeAssistant中MQTT设备的自动发现逻辑是:

    • MQTT设备将自身的配置信息发布在事前定义的主题位置上
    • HomeAssistant从这个主题位置读取信息,生成对应的系统内实体设备

    2支持自动发现的设备包括:

    • 开关型传感器(binary_sensor)
    • 摄像头(camera)
    • 窗帘(cover)
    • 电扇(fan)
    • 灯(light)
    • 传感器(sensor)
    • 开关(switch)

    3HomeAssistant支持自动发现,需要在配置文件中增加:

    mqtt:
      # 此处为mqtt原有的一些配置
      # ……
      # 配置自动发现
      discovery: true
      # 自动发现使用的主题位置前缀,缺省为homeassistant
      discovery_prefix: homeassistant

    4设备将自己的配置信息发布在主题位置:

    • <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格式。


    例如,MQTT设备在主题:

    homeassistant/switch/irrigation/config
    

      

    发布信息:

    当HomeAssistant读取此信息,相当于配置文件中存在以下内容:

     
     

    警告:

     自动发现设备的时候,一定要改配置话题第三个参数ID,

    • 跟换设备名没关系。设备名重复,ID不重复,可以添加。
    • 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冲突,只能存在一个

  • 相关阅读:
    C++ 的查漏补缺
    Model元数据解析
    Controller
    路由
    win8系统 Reflect 破解
    MVC运行原理
    源代码Log
    linq 分类
    EF 实体关系
    第二十六章 计算限制的异步操作
  • 原文地址:https://www.cnblogs.com/kekeoutlook/p/9471884.html
Copyright © 2011-2022 走看看