You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Home Assistant通过Modbus连接Wago PFC200 PLC配置问题求助

适配Wago PFC200的HomeAssistant Modbus配置方案

报错问题修复

Wago PFC200的Modbus TCP默认使用短连接机制,每次请求响应完成后会主动断开连接,pymodbus库默认复用长连接,因此会触发连接意外关闭的报错,数据读取正常说明通信本身无问题,仅需修改modbus基础配置即可消除报错:

modbus:
  - name: PLC
    type: tcp
    host: 192.168.10.60
    port: 502
    timeout: 3 # 调整超时时间适配Wago设备响应节奏
    close_comm_on_error: true # 出错后主动关闭连接,下次请求重建连接适配短连接机制
    retry_on_empty: true # 空响应时自动重试避免偶发读取失败

如果不想调整通信配置,也可以通过修改HA日志级别屏蔽无效报错:

logger:
  logs:
    homeassistant.components.modbus.modbus: WARNING

刷新延迟问题修复

你当前配置将scan_interval写在switch平台下,新版HA Modbus集成的全局扫描间隔需配置在hub段,同时你使用的分散coil地址不连续,会导致Modbus拆分为多次请求读取,拖慢更新速度。建议将所有灯光状态在PLC侧汇总到连续的地址段,减少请求次数。

寄存器方案说明

建议改用保持寄存器替代分散coil配置,Wago的保持寄存器访问稳定性更高,批量读取效率远高于零散coil读取,大幅降低延迟和报错概率。你可以在PLC侧将所有灯光开关状态汇总到同一个16位保持寄存器(如%MW0),每一位对应一个灯光的状态,HA侧一次性读取该寄存器后解析各位状态即可。
参考配置如下,可根据你实际的PLC地址调整对应参数:

modbus:
  - name: PLC
    type: tcp
    host: 192.168.10.60
    port: 502
    timeout: 3
    close_comm_on_error: true
    retry_on_empty: true
    scan_interval: 2 # 全局扫描间隔写在hub配置下生效

# 读取汇总状态寄存器
sensor:
  - platform: modbus
    hub: PLC
    register_type: holding
    registers:
      - name: light_status
        slave: 1
        address: 0 # 对应PLC侧汇总状态的保持寄存器地址
        count: 1
        data_type: uint16

# 解析寄存器每一位对应灯光状态
template:
  - binary_sensor:
      - name: bedroom_main_light_status
        state: "{{ (states('sensor.light_status') | int(0) | bitwise_and(1)) == 1 }}"
      - name: bedroom_wardrobe_light_status
        state: "{{ (states('sensor.light_status') | int(0) | bitwise_and(2)) == 2 }}"
      - name: bathroom_main_light_status
        state: "{{ (states('sensor.light_status') | int(0) | bitwise_and(8)) == 8 }}"
      - name: bathroom_mirror_light_status
        state: "{{ (states('sensor.light_status') | int(0) | bitwise_and(16)) == 16 }}"

  # 绑定控制逻辑与状态
  - switch:
      - name: bedroom_main_light
        turn_on:
          service: modbus.write_coil
          data:
            hub: PLC
            address: 1
            slave: 1
            value: 1
        turn_off:
          service: modbus.write_coil
          data:
            hub: PLC
            address: 1
            slave: 1
            value: 0
        state: "{{ states('binary_sensor.bedroom_main_light_status') }}"
      # 其余灯光开关参考上述配置修改对应位运算参数与coil地址即可

# 映射为灯光实体
light:
  - platform: switch
    name: 卧室主灯
    entity_id: switch.bedroom_main_light
  - platform: switch
    name: 衣柜灯
    entity_id: switch.bedroom_wardrobe_light
  - platform: switch
    name: 卫生间主灯
    entity_id: switch.bathroom_main_light
  - platform: switch
    name: 卫生间镜前灯
    entity_id: switch.bathroom_mirror_light

内容的提问来源于stack exchange,提问作者Dawid Rutkowski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 09:24:03