Modbus integration help

Hi all I’ve a problem “translation” my configuration.yaml code to the new “syntax” needed with the 2021.7 version.

This is the old version. Can anyone help me to convert this to the new one, I’m not a programmer …

sensor:
  - platform: modbus
    scan_interval: 5
    registers:
      - name: E3DC Solar Hausdach
        unit_of_measurement: W
        register: 40067
        hub: e3dc
        device_class: power
      - name: E3DC Batterie
        unit_of_measurement: W
        register: 40069
        hub: e3dc
        device_class: power
      - name: E3DC Wallbox
        unit_of_measurement: W
        register: 40077
        hub: e3dc
        device_class: power
      - name: E3DC Hausbezug
        unit_of_measurement: W
        register: 40071 
        hub: e3dc
        device_class: power
      - name: E3DC Netzbezug
        unit_of_measurement: W
        register: 40073
        hub: e3dc
        device_class: power
      - name: E3DC Solar extern Garage
        register: 40075
        hub: e3dc
        device_class: power
      - name: E3DC Wallbox solar
        unit_of_measurement: W
        register: 40079
        hub: e3dc
        device_class: power
      - name: E3DC Autarkie
        data_type: uint
        register: 40081
        hub: e3dc
      - name: E3DC Batterie Ladung
        data_type: uint      
        register: 40082
        hub: e3dc
      - name: E3DC emergency power state
        data_type: uint
        register: 40083
        hub: e3dc        
      - name: E3DC_emergency_state
        slave: 1
        data_type: uint
        register: 40084
        hub: e3dc
      - name: E3DC_Leistungsmesser-L1 
        slave: 1
        data_type: uint
        register: 40105
        hub: e3dc        
      - name: E3DC_Leistungsmesser-L2
        slave: 1
        data_type: uint
        register: 40106
        hub: e3dc
      - name: E3DC_Leistungsmesser-L3  
        slave: 1
        data_type: uint
        register: 40107
        hub: e3dc
modbus:
  name: e3dc
  type: tcp
  host: 192.168.1.159
  port: 502
binary_sensor:
  - platform: template
    sensors:
      e3dc_emergency_power_available:
        friendly_name: "E3DC Emergency Power available"
        value_template: "{{ states('sensor.e3dc_ems_state')|int|bitwise_and(4) > 0 }}"
      e3dc_battery_loading_blocked:
        friendly_name: "E3DC Battery loading blocked"
        value_template: "{{ states('sensor.e3dc_ems_state')|int|bitwise_and(1) > 0 }}"
      e3dc_battery_unloading_blocked:
        friendly_name: "E3DC Battery unloading blocked"
        value_template: "{{ states('sensor.e3dc_ems_state')|int|bitwise_and(2) > 0 }}"
      e3dc_weather_based_loading:
        friendly_name: "E3DC weather based loading limiter"
        value_template: "{{ states('sensor.e3dc_ems_state')|int|bitwise_and(8) > 0 }}"
      e3dc_power_limiter:
        friendly_name: "E3DC power limiter"
        value_template: "{{ states('sensor.e3dc_ems_state')|int|bitwise_and(16) > 0 }}"
      e3dc_smartcharge_loading_blocked:
        friendly_name: "E3DC SmartCharge loading blocked"
        value_template: "{{ states('sensor.e3dc_ems_state')|int|bitwise_and(32) > 0 }}"
      e3dc_smartcharge_unloading_blocked:
        friendly_name: "E3DC SmartCharge unloading blocked"
        value_template: "{{ states('sensor.e3dc_ems_state')|int|bitwise_and(64) > 0 }}"
  - platform: template
    sensors:
      e3dc_autarky:
        friendly_name: 'E3DC Autarky'
        unit_of_measurement: '%'
        value_template: "{{ (states('sensor.e3dc_own_consumption')|int / 256)|round(0,'floor') }}"
      e3dc_own_consumption:
        friendly_name: 'E3DC Own Consumption ratio'
        unit_of_measurement: '%'
        value_template: "{{ ((states('sensor.e3dc_own_consumption')|int / 256 - states('sensor.e3dc_autarkie')|int) * 256)|round(0,'floor') }}"

Give this a try:

  1. Comment out all your modbus related lines in your sensor.yaml file
  2. Add this line to your configuration.yaml file: modbus: !include modbus.yaml
  3. Create file in your config directory called modbus.yaml and paste in these lines
- name: e3dc
  type: tcp
  host: 192.168.1.159
  port: 502
  sensors:
    - name: E3DC Solar Hausdach
      unit_of_measurement: W
      address: 40067
      slave: 1
      device_class: power
    - name: E3DC Batterie
      unit_of_measurement: W
      address: 40069
      slave: 1
      device_class: power
    - name: E3DC Wallbox
      unit_of_measurement: W
      address: 40077
      slave: 1
      device_class: power
    - name: E3DC Hausbezug
      unit_of_measurement: W
      address: 40071
      slave: 1
      device_class: power
    - name: E3DC Netzbezug
      unit_of_measurement: W
      address: 40073
      slave: 1
      device_class: power
    - name: E3DC Solar extern Garage
      address: 40075
      slave: 1
      device_class: power
    - name: E3DC Wallbox solar
      unit_of_measurement: W
      address: 40079
      slave: 1
      device_class: power
    - name: E3DC Autarkie
      data_type: uint
      address: 40081
      slave: 1
    - name: E3DC Batterie Ladung
      data_type: uint      
      address: 40082
      slave: 1
    - name: E3DC emergency power state
      data_type: uint
      address: 40083
      slave: 1
    - name: E3DC_emergency_state
      data_type: uint
      address: 40084
      slave: 1
    - name: E3DC_Leistungsmesser-L1 
      data_type: uint
      address: 40105
      slave: 1
    - name: E3DC_Leistungsmesser-L2
      data_type: uint
      address: 40106
      slave: 1
    - name: E3DC_Leistungsmesser-L3  
      data_type: uint
      address: 40107
      slave: 1
      
2 Likes

@jhart003
Thanks very much that worked!
Seems that it make sense to create such files, makes it easier to manage the configuration.
I’m still learning much every day with my home assistant environment.

have a nice Sunday
Peter