『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 2119|回复: 7

[技术探讨] 新版的mqtt 更改后mqtt服务器和斐讯TC1的问题

[复制链接]

21

主题

121

帖子

1049

积分

金牌会员

Rank: 6Rank: 6

积分
1049
金钱
928
HASS币
0
发表于 2022-11-12 15:34:35 | 显示全部楼层 |阅读模式
我原先的MQTT服务器是在yaml里设置的mqtt:
  broker: 192.168.1.2
  port: 1883
  username: admin
  password: public
  discovery: true
MQTT.jpg

但是在按照新版mqtt的格式改完后,日志里有以下错误


Logger: homeassistant.components.mqtt
Source: helpers/config_validation.py:826
Integration: MQTT ([color=var(--primary-color)]documentation
, [color=var(--primary-color)]issues
)
First occurred: 15:00:01 (5 occurrences)
Last logged: 15:00:02
  • The 'broker' option near /config/configuration.yaml:19 is deprecated, please remove it from your configuration
  • The 'discovery' option near /config/configuration.yaml:19 is deprecated, please remove it from your configuration
  • The 'password' option near /config/configuration.yaml:19 is deprecated, please remove it from your configuration
  • The 'port' option near /config/configuration.yaml:19 is deprecated, please remove it from your configuration
  • The 'username' option near /config/configuration.yaml:19 is deprecated, please remove it from your configuration
1. 请问新版的mqtt怎么在configure.yaml 文件里面如何自定义mqtt服务器啊?


我发现在改完TC1 的mqtt后。TC1 有以下错误
Logger: homeassistant.config
Source: config.py:822
First occurred: 15:00:02 (1 occurrences)
Last logged: 15:00:02
Invalid config for [mqtt]: [unit_of_measurement] is an invalid option for [mqtt]. Check: mqtt->mqtt->switch->12->unit_of_measurement. (See /config/configuration.yaml, line 19). Please check the docs at https://www.home-assistant.io/integrations/mqtt

TC1改后的mqtt定义
mqtt
  sensor:
    - name: 'ztc1_time_d0bae462f5a6'
      state_topic: 'device/ztc1/d0bae462f5a6/sensor'
      unit_of_measurement: '秒'
      icon: 'mdi:gauge'
      value_template: '{{ value_json.total_time }}'
      value_template: >-
        {% set time = value_json.total_time %}
        {% set minutes = ((time % 3600) / 60) | int %}
        {% set hours = ((time % 86400) / 3600) | int %}
        {% set days = (time / 86400) | int %}
        {%- if time < 60 -%}
          <1分钟
        {%- else -%}
          {%- if days > 0 -%}
              {{ days }}天
          {%- endif -%}
          {%- if hours > 0 -%}
              {{ hours }}小时
          {%- endif -%}
          {%- if minutes > 0 -%}
              {{ minutes }}分钟
          {%- endif -%}
        {%- endif -%}

2. 请问新版的mqtt用什么替换unit_of_measurement?
3. 还有value_template: '{{ value_json.total_time }}'这一条也被系统自动注释掉了。我没在日志中查到错误。请问有谁知道这是为什么被自动注释掉?

回复

使用道具 举报

2

主题

138

帖子

1769

积分

金牌会员

Rank: 6Rank: 6

积分
1769
金钱
1631
HASS币
0
发表于 2022-11-12 16:44:08 | 显示全部楼层
unit_of_measurement: '秒'
value_template: '{{ value_json.total_time }}'

这两条在作者的例子里就是注销掉的。
MQTT服务器现在在UI里直接设置。
回复

使用道具 举报

21

主题

121

帖子

1049

积分

金牌会员

Rank: 6Rank: 6

积分
1049
金钱
928
HASS币
0
 楼主| 发表于 2022-11-13 21:09:26 | 显示全部楼层
本帖最后由 geniusliang 于 2022-11-13 21:11 编辑

我已经在UI 直接配置了MQTT 服务器。但是我把TC1的配置文件改成下面的之后就无法在HA开发者工具里面找到TC1的那些开关实体了。改回原来的就能用。请问有哪位高手能告知下我改的哪里有错误么?
mqtt:
# TC1
  switch:
    - name: 'ztc1_1_d0bae462f5a6'
      state_topic: 'device/ztc1/d0bae462f5a6/state'
      command_topic: 'device/ztc1/d0bae462f5a6/set'
      payload_on: '{"mac":"d0bae462f5a6","plug_0":{"on":1}}'
      payload_off: '{"mac":"d0bae462f5a6","plug_0":{"on":0}}'
      value_template: '{{ value_json.plug_0.on }}'
      state_on: '1'
      state_off: '0'   
    - name: 'ztc1_2_d0bae462f5a6'
      state_topic: 'device/ztc1/d0bae462f5a6/state'
      command_topic: 'device/ztc1/d0bae462f5a6/set'
      payload_on: '{"mac":"d0bae462f5a6","plug_1":{"on":1}}'
      payload_off: '{"mac":"d0bae462f5a6","plug_1":{"on":0}}'
      value_template: '{{ value_json.plug_1.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_3_d0bae462f5a6'
      state_topic: 'device/ztc1/d0bae462f5a6/state'
      command_topic: 'device/ztc1/d0bae462f5a6/set'
      payload_on: '{"mac":"d0bae462f5a6","plug_2":{"on":1}}'
      payload_off: '{"mac":"d0bae462f5a6","plug_2":{"on":0}}'
      value_template: '{{ value_json.plug_2.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_4_d0bae462f5a6'
      state_topic: 'device/ztc1/d0bae462f5a6/state'
      command_topic: 'device/ztc1/d0bae462f5a6/set'
      payload_on: '{"mac":"d0bae462f5a6","plug_3":{"on":1}}'
      payload_off: '{"mac":"d0bae462f5a6","plug_3":{"on":0}}'
      value_template: '{{ value_json.plug_3.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_5_d0bae462f5a6'
      state_topic: 'device/ztc1/d0bae462f5a6/state'
      command_topic: 'device/ztc1/d0bae462f5a6/set'
      payload_on: '{"mac":"d0bae462f5a6","plug_4":{"on":1}}'
      payload_off: '{"mac":"d0bae462f5a6","plug_4":{"on":0}}'
      value_template: '{{ value_json.plug_4.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_6_d0bae462f5a6'
      state_topic: 'device/ztc1/d0bae462f5a6/state'
      command_topic: 'device/ztc1/d0bae462f5a6/set'
      payload_on: '{"mac":"d0bae462f5a6","plug_5":{"on":1}}'
      payload_off: '{"mac":"d0bae462f5a6","plug_5":{"on":0}}'
      value_template: '{{ value_json.plug_5.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_1_d0bae463658b'
      state_topic: 'device/ztc1/d0bae463658b/state'
      command_topic: 'device/ztc1/d0bae463658b/set'
      payload_on: '{"mac":"d0bae463658b","plug_0":{"on":1}}'
      payload_off: '{"mac":"d0bae463658b","plug_0":{"on":0}}'
      value_template: '{{ value_json.plug_0.on }}'
      state_on: '1'
      state_off: '0'   
    - name: 'ztc1_2_d0bae463658b'
      state_topic: 'device/ztc1/d0bae463658b/state'
      command_topic: 'device/ztc1/d0bae463658b/set'
      payload_on: '{"mac":"d0bae463658b","plug_1":{"on":1}}'
      payload_off: '{"mac":"d0bae463658b","plug_1":{"on":0}}'
      value_template: '{{ value_json.plug_1.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_3_d0bae463658b'
      state_topic: 'device/ztc1/d0bae463658b/state'
      command_topic: 'device/ztc1/d0bae463658b/set'
      payload_on: '{"mac":"d0bae463658b","plug_2":{"on":1}}'
      payload_off: '{"mac":"d0bae463658b","plug_2":{"on":0}}'
      value_template: '{{ value_json.plug_2.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_4_d0bae463658b'
      state_topic: 'device/ztc1/d0bae463658b/state'
      command_topic: 'device/ztc1/d0bae463658b/set'
      payload_on: '{"mac":"d0bae463658b","plug_3":{"on":1}}'
      payload_off: '{"mac":"d0bae463658b","plug_3":{"on":0}}'
      value_template: '{{ value_json.plug_3.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_5_d0bae463658b'
      state_topic: 'device/ztc1/d0bae463658b/state'
      command_topic: 'device/ztc1/d0bae463658b/set'
      payload_on: '{"mac":"d0bae463658b","plug_4":{"on":1}}'
      payload_off: '{"mac":"d0bae463658b","plug_4":{"on":0}}'
      value_template: '{{ value_json.plug_4.on }}'
      state_on: '1'
      state_off: '0'
    - name: 'ztc1_6_d0bae463658b'
      state_topic: 'device/ztc1/d0bae463658b/state'
      command_topic: 'device/ztc1/d0bae463658b/set'
      payload_on: '{"mac":"d0bae463658b","plug_5":{"on":1}}'
      payload_off: '{"mac":"d0bae463658b","plug_5":{"on":0}}'
      value_template: '{{ value_json.plug_5.on }}'
      state_on: '1'
      state_off: '0'


  sensor:
    - name: 'ztc1_time_d0bae462f5a6'
      state_topic: 'device/ztc1/d0bae462f5a6/sensor'
      #unit_of_measurement: '秒'
      icon: 'mdi:gauge'
      #value_template: '{{ value_json.total_time }}'
      value_template: >-
        {% set time = value_json.total_time %}
        {% set minutes = ((time % 3600) / 60) | int %}
        {% set hours = ((time % 86400) / 3600) | int %}
        {% set days = (time / 86400) | int %}
        {%- if time < 60 -%}
          <1分钟
        {%- else -%}
          {%- if days > 0 -%}
              {{ days }}天
          {%- endif -%}
          {%- if hours > 0 -%}
              {{ hours }}小时
          {%- endif -%}
          {%- if minutes > 0 -%}
              {{ minutes }}分钟
          {%- endif -%}
        {%- endif -%}
    - name: 'ztc1_power_d0bae463658b'
      state_topic: 'device/ztc1/d0bae463658b/sensor'
      unit_of_measurement: 'W'
      icon: 'mdi:gauge'
      value_template: '{{ value_json.power }}'
    - name: 'ztc1_time_d0bae463658b'
      state_topic: 'device/ztc1/d0bae463658b/sensor'
      #unit_of_measurement: '秒'
      icon: 'mdi:gauge'
      #value_template: '{{ value_json.total_time }}'
      value_template: >-
        {% set time = value_json.total_time %}
        {% set minutes = ((time % 3600) / 60) | int %}
        {% set hours = ((time % 86400) / 3600) | int %}
        {% set days = (time / 86400) | int %}
        {%- if time < 60 -%}
          <1分钟
        {%- else -%}
          {%- if days > 0 -%}
              {{ days }}天
          {%- endif -%}
          {%- if hours > 0 -%}
              {{ hours }}小时
          {%- endif -%}
          {%- if minutes > 0 -%}
              {{ minutes }}分钟
          {%- endif -%}
        {%- endif -%}

回复

使用道具 举报

5

主题

259

帖子

1608

积分

金牌会员

Rank: 6Rank: 6

积分
1608
金钱
1349
HASS币
0
发表于 2022-11-13 23:20:05 | 显示全部楼层
按新版改好TC1能用,加上DC1就不行了,好修哪里冲突
回复

使用道具 举报

5

主题

187

帖子

966

积分

高级会员

Rank: 4

积分
966
金钱
779
HASS币
10
发表于 2022-11-14 08:42:46 | 显示全部楼层
damp521 发表于 2022-11-13 23:20
按新版改好TC1能用,加上DC1就不行了,好修哪里冲突

一个文件一个设备试试吧
回复

使用道具 举报

21

主题

121

帖子

1049

积分

金牌会员

Rank: 6Rank: 6

积分
1049
金钱
928
HASS币
0
 楼主| 发表于 2022-11-14 09:45:04 | 显示全部楼层
damp521 发表于 2022-11-13 23:20
按新版改好TC1能用,加上DC1就不行了,好修哪里冲突

能发下兄弟你的TC1的配置么。我找了半天没搞懂哪里配错了
回复

使用道具 举报

5

主题

259

帖子

1608

积分

金牌会员

Rank: 6Rank: 6

积分
1608
金钱
1349
HASS币
0
发表于 2022-11-15 13:40:10 | 显示全部楼层
geniusliang 发表于 2022-11-14 09:45
能发下兄弟你的TC1的配置么。我找了半天没搞懂哪里配错了
mqtt:
  switch:
    name: 'tc1_1_MACMAC'
    state_topic: 'device/ztc1/MACMAC/state'
    command_topic: 'device/ztc1/MACMAC/set'
    payload_on: '{"mac":"MACMAC","plug_0":{"on":1}}'
    payload_off: '{"mac":"MACMAC","plug_0":{"on":0}}'
    value_template: '{{ value_json.plug_0.on }}'
    state_on: '1'
    state_off: '0'    
  switch:
    name: 'tc1_2_MACMAC'
    state_topic: 'device/ztc1/MACMAC/state'
    command_topic: 'device/ztc1/MACMAC/set'
    payload_on: '{"mac":"MACMAC","plug_1":{"on":1}}'
    payload_off: '{"mac":"MACMAC","plug_1":{"on":0}}'
    value_template: '{{ value_json.plug_1.on }}'
    state_on: '1'
    state_off: '0'
回复

使用道具 举报

5

主题

259

帖子

1608

积分

金牌会员

Rank: 6Rank: 6

积分
1608
金钱
1349
HASS币
0
发表于 2022-11-15 13:41:35 | 显示全部楼层
本帖最后由 damp521 于 2022-11-15 13:50 编辑

或者下面这样,官方是这个格式
mqtt:
  switch:
    - name: 'tc1_1_MACMAC'
      state_topic: 'device/ztc1/MACMAC/state'
      command_topic: 'device/ztc1/MACMAC/set'
      payload_on: '{"mac":"MACMAC","plug_0":{"on":1}}'
      payload_off: '{"mac":"MACMAC","plug_0":{"on":0}}'
      value_template: '{{ value_json.plug_0.on }}'
      state_on: '1'
      state_off: '0'   



https://www.home-assistant.io/in ... 或.mqtt/#new_format
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-28 18:46 , Processed in 0.062626 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表