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

 找回密码
 立即注册
查看: 2377|回复: 10

[已解决] 求助,关于esphome接modbus 传感器的配置文件写法

[复制链接]

3

主题

76

帖子

1107

积分

金牌会员

Rank: 6Rank: 6

积分
1107
金钱
1031
HASS币
0
发表于 2022-2-23 22:07:06 | 显示全部楼层 |阅读模式
本帖最后由 sss190 于 2022-2-25 15:24 编辑

手上弄了一个modbus-rtu协议的传感器,打算用esphome刷esp-c3-13u接入ha。该设备为单线上有两个设备一个设备的地址为01一个设备的地址为15H
写配置文件时遇到一些问题,协议如下图
[url=] 12.png [/url]

配置文件如下
uart:
  id: esp485_uart
  rx_pin: 18
  tx_pin: 19
  baud_rate: 9600
  data_bits: 8
  stop_bits: 1

modbus:
  send_wait_time: 200ms
  id: esp485_modbus
  uart_id: esp485_uart


modbus_controller:
  - id: nh193_WDSP_modbus_controller
    modbus_id: esp485_modbus
    address: 0x1  #设备地址码(一般是1根据实际情况填)#
    command_throttle: 200ms
    setup_priority: -10
    update_interval: 10s

  - id: nh193_THP_modbus_controller
    modbus_id: esp485_modbus
    address: 0x15  #设备地址码(一般是1根据实际情况填)#
    command_throttle: 200ms
    setup_priority: -10
    update_interval: 10s  

sensor:
  - platform: modbus_controller
    modbus_controller_id: nh193_WDSP_modbus_controller
    id: nh193_WDSP_wind_speed
    name: "windspeed"
    address: 0x010
    #register_count: 2
    unit_of_measurement: "m/s"
    register_type: read
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    modbus_controller_id: nh193_WDSP_modbus_controller
    id: nh193_WDSP_wind_direction
    name: "wind direction"
    address: 0x9017
    # register_count: 2
    unit_of_measurement: "°"
    register_type: read
    value_type: U_WORD
    # accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: nh193_THP_modbus_controller
    id: nh193_THP_modbus_TEMP
    name: "Outside temperature"
    address: 0
    # register_count: 2
    unit_of_measurement: "℃"
    register_type: read
    value_type: S_WORD
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
      - lambda: |-
          float MAX_DIFFERENCE = 1.0;  // adjust this!
          static float last_value = NAN;
          if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE)
            return last_value = x;
          else
            return {};
  
  - platform: modbus_controller
    modbus_controller_id: nh193_THP_modbus_controller
    id: nh193_THP_modbus_HUM
    name: "outside humidity"
    address: 1
    # register_count: 2
    unit_of_measurement: "%RH"
    register_type: read
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    modbus_controller_id: nh193_THP_modbus_controller
    id: nh193_THP_modbus_PRESSURE
    name: "STP"
    address: 2
    # register_count: 2
    unit_of_measurement: "hPa"
    register_type: read
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1



目前碰到的问题是当前配置文件生成固件写入后可以读取地址为15H的设备的数据,但地址为1的设备的数据无法读取。谢谢

01设备的数据无法读取,设备的日志如下:
[D][modbus_controller:032]: Modbus command to device=1 register=0x10 countdown=0 no response received - removed from send queue
[D][modbus_controller:032]: Modbus command to device=1 register=0x9017 countdown=0 no response received - removed from send queue
[D][modbus_controller.sensor:025]: Sensor new state: 162.00
[D][sensor:125]: 'Outside temperature': Sending state 16.20000 ℃ with 1 decimals of accuracy
[D][modbus_controller.sensor:025]: Sensor new state: 457.00
[D][sensor:125]: 'outside humidity': Sending state 45.70000 %RH with 1 decimals of accuracy
[D][modbus_controller.sensor:025]: Sensor new state: 10347.00
[D][sensor:125]: 'STP': Sending state 1034.70007 hPa with 1 decimals of accuracy
[D][modbus_controller:032]: Modbus command to device=1 register=0x10 countdown=0 no response received - removed from send queue
[D][modbus_controller:032]: Modbus command to device=1 register=0x9017 countdown=0 no response received - removed from send queue
[D][modbus_controller.sensor:025]: Sensor new state: 162.00
[D][sensor:125]: 'Outside temperature': Sending state 16.20000 ℃ with 1 decimals of accuracy
[D][modbus_controller.sensor:025]: Sensor new state: 456.00
[D][sensor:125]: 'outside humidity': Sending state 45.60000 %RH with 1 decimals of accuracy
[D][modbus_controller.sensor:025]: Sensor new state: 10347.00
[D][sensor:125]: 'STP': Sending state 1034.70007 hPa with 1 decimals of accuracy


直接使用modbus转wifi是可以在ha里读取全部数据

回复

使用道具 举报

5

主题

265

帖子

1899

积分

金牌会员

Rank: 6Rank: 6

积分
1899
金钱
1634
HASS币
0
发表于 2022-2-24 09:49:24 | 显示全部楼层
直接用HA就可以啊。还用esphome转一下做啥
回复

使用道具 举报

3

主题

76

帖子

1107

积分

金牌会员

Rank: 6Rank: 6

积分
1107
金钱
1031
HASS币
0
 楼主| 发表于 2022-2-24 18:47:28 | 显示全部楼层
zkxa 发表于 2022-2-24 09:49
直接用HA就可以啊。还用esphome转一下做啥

为了一起接入其他的传感器。用wifi网关没有esphome灵活
回复

使用道具 举报

3

主题

76

帖子

1107

积分

金牌会员

Rank: 6Rank: 6

积分
1107
金钱
1031
HASS币
0
 楼主| 发表于 2022-2-25 15:27:53 | 显示全部楼层
通过查询esphome的文档解决了问题
- platform: modbus_controller
    modbus_controller_id: nh193_WDSP_modbus_controller
    id: nh193_WDSP_wind_speed
    name: "windspeed"
    address:  16
    #register_count: 2
    unit_of_measurement: "m/s"
    register_type: holding
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

问题出在红字部分register_type,功能码03,register_type应该为holding
另外address是说明书提供的地址10H转为10进制的值16
回复

使用道具 举报

5

主题

265

帖子

1899

积分

金牌会员

Rank: 6Rank: 6

积分
1899
金钱
1634
HASS币
0
发表于 2022-2-26 19:38:45 | 显示全部楼层
还有一个地址呢
回复

使用道具 举报

3

主题

76

帖子

1107

积分

金牌会员

Rank: 6Rank: 6

积分
1107
金钱
1031
HASS币
0
 楼主| 发表于 2022-3-2 20:25:32 | 显示全部楼层

d

本帖最后由 sss190 于 2022-3-2 20:26 编辑

通过查询esphome的文档解决了问题
- platform: modbus_controller
    modbus_controller_id: nh193_WDSP_modbus_controller
    id: nh193_WD
    name: "wd"
    address:  17
    #register_count: 2
    unit_of_measurement: "°"
    register_type: holding
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
回复

使用道具 举报

1

主题

79

帖子

969

积分

高级会员

Rank: 4

积分
969
金钱
890
HASS币
0
发表于 2022-4-15 20:12:39 | 显示全部楼层
sss190 发表于 2022-2-25 15:27
通过查询esphome的文档解决了问题
- platform: modbus_controller
    modbus_controller_id: nh193_WDSP_m ...

问个问题  HA上的modbus address:是十进制,不是十六进制了?
回复

使用道具 举报

41

主题

1295

帖子

5328

积分

论坛元老

Rank: 8Rank: 8

积分
5328
金钱
4028
HASS币
20
发表于 2022-4-15 20:25:13 | 显示全部楼层
文档写的很清楚
折腾精神永存,感恩感谢论坛每一位愿意分享和帮助过我的大佬,论坛有你更精彩
回复

使用道具 举报

3

主题

76

帖子

1107

积分

金牌会员

Rank: 6Rank: 6

积分
1107
金钱
1031
HASS币
0
 楼主| 发表于 2022-4-16 20:41:37 | 显示全部楼层
五千万啊 发表于 2022-4-15 20:12
问个问题  HA上的modbus address:是十进制,不是十六进制了?

这个是esphome的配置文件。不是ha的
回复

使用道具 举报

11

主题

77

帖子

764

积分

高级会员

Rank: 4

积分
764
金钱
682
HASS币
20
发表于 2022-10-17 17:41:40 | 显示全部楼层
我也碰到同样的问题,一个ESP32s读取address: 0xd6 或者address: 0xd7 着两个同一总线上的两个不同地址设备,读取任意一个都没有问题但是读取两个设备ESP直接挂了连接不上API那位大神帮忙看看那里出问题了!
modbus:
  id: esp485_modbus
  send_wait_time: 2000ms

modbus_controller:
  - id: esp485_modbus_controller
    modbus_id: esp485_modbus
    address: 0xd6
    command_throttle: 2000ms
    setup_priority: -8
    update_interval: 5s

  - id: esp485_modbus_controller_01
    modbus_id: esp485_modbus
    address: 0xd7
    command_throttle: 1500ms
    setup_priority: -10
    update_interval: 10s

sensor:
  #母排电压
  - platform: modbus_controller
    modbus_controller_id: esp485_modbus_controller
    id: esp485_modbus_HWMP_Voltage
    name: "HWMP_Voltage"
    address: 0x0000
    unit_of_measurement: "V"
    register_type: holding
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01
    device_class: voltage
#电池01
  - platform: modbus_controller
    modbus_controller_id: esp485_modbus_controller_01
    id: esp485_modbus_HWMP_Voltage_01
    name: "HWMP_Voltage_1"
    address: 0x0000
    unit_of_measurement: "V"
    register_type: holding
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01
    device_class: voltage
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-29 07:58 , Processed in 1.149884 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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