HomeAssistant升级新MQTT格式 - 2022.9.0后的版本

2022-11-20 11:02:51 浏览数 (2)

Home Assistant 2022.9.0以后的版本升级了MQTT格式,抽空把升级了下自己的配置文件,顺便做个记录

新旧对比

拿ztc1的MQTT来举个例子

旧版
代码语言:javascript复制
switch:
  - platform: mqtt
    name: 'ztc1_1_xxxxxxxxxxxx'
    unique_id: ztc1_1_xxxxxxxxxxxx
    state_topic: 'device/ztc1/xxxxxxxxxxxx/state'
    command_topic: 'device/ztc1/xxxxxxxxxxxx/set'
    payload_on: '{"mac":"xxxxxxxxxxxx","plug_0":{"on":1}}'
    payload_off: '{"mac":"xxxxxxxxxxxx","plug_0":{"on":0}}'
    value_template: '{{ value_json.plug_0.on }}'
    state_on: '1'
    state_off: '0'
新版
代码语言:javascript复制
mqtt:
    switch:
      - name: 'ztc1_1_xxxxxxxxxxxx'
        unique_id: ztc1_1_xxxxxxxxxxxx
        state_topic: 'device/ztc1/xxxxxxxxxxxx/state'
        command_topic: 'device/ztc1/xxxxxxxxxxxx/set'
        payload_on: '{"mac":"xxxxxxxxxxxx","plug_0":{"on":1}}'
        payload_off: '{"mac":"xxxxxxxxxxxx","plug_0":{"on":0}}'
        value_template: '{{ value_json.plug_0.on }}'
        state_on: '1'
        state_off: '0'

差别

旧版
代码语言:javascript复制
switch:
  - platform: mqtt
    name: 'ztc1_1_xxxxxxxxxxxx'
    其他参数: 参数值
新版
代码语言:javascript复制
mqtt:
    switch:
      - name: 'ztc1_1_xxxxxxxxxxxx'
        其他参数: 参数值

0 人点赞