Read bitmask value of register in Modbus sensor

looks like your configuration is not formatted correctly. YAML needs correct indention (2 spaces per indention level, no tabs).

Btw, the modbus integration now requires a new config structure, all sensors etc within the modbus domain and not each respective sensor domains. So it now is following the new, required HA component structure. My current config looks like this:

Main modbus config

modbus:
  - name: e3dc
    type: tcp
    host: 192.168.0.XXX
    port: 502
    sensors:
      - name: E3DC solar power
        unit_of_measurement: W
        address: 40067
        device_class: power
      - name: E3DC battery power
        unit_of_measurement: W
        address: 40069
        device_class: power
      - name: E3DC battery soc
        unit_of_measurement: '%'
        address: 40082
        data_type: uint
        device_class: battery
      - name: E3DC power consumption
        unit_of_measurement: W
        address: 40071
        device_class: power
      - name: E3DC grid power
        unit_of_measurement: W
        address: 40073
        device_class: power
      - name: E3DC emergency power state
        data_type: uint
        address: 40083
      - name: E3DC EMS state
        data_type: uint
        address: 40084
      - name: E3DC autarky and consumption
        data_type: uint
        address: 40081
      - name: E3DC string 1 power
        data_type: uint
        address: 40101
        device_class: power
        unit_of_measurement: W
      - name: E3DC string 2 power
        data_type: uint
        address: 40102
        device_class: power
        unit_of_measurement: W
      - name: E3DC powermeter 1 L1
        data_type: int
        address: 40105
        device_class: power
        unit_of_measurement: W
      - name: E3DC powermeter 1 L2
        data_type: int
        address: 40106
        device_class: power
        unit_of_measurement: W
      - name: E3DC powermeter 1 L3
        data_type: int
        address: 40107
        device_class: power
        unit_of_measurement: W

Some binary sensors to prettify some of the modbus values

binary_sensor:
  - platform: template
    sensors:
      e3dc_emergency_power_possible:
        friendly_name: "E3DC Emergency Power possible"
        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 }}"
      e3dc_emergency_power_active:
        friendly_name: "E3DC Emergency Power Mode Active"
        value_template: "{{ is_state('sensor.e3dc_emergency_power_state', '1') }}"
      e3dc_emergency_power_available:
        friendly_name: "E3DC Emergency Power Available"
        value_template: "{{ is_state('sensor.e3dc_emergency_power_state', '1') or is_state('sensor.e3dc_emergency_power_state', '2') }}"
        device_class: "power"

And finally some sensors which I use in conjunction with the power-distribution card

sensor:
  - platform: template
    sensors:
      e3dc_autarky:
        friendly_name: 'E3DC Autarky'
        unit_of_measurement: '%'
        value_template: "{{ (states('sensor.e3dc_autarky_and_consumption')|int / 256)|round(0,'floor') }}"
      e3dc_own_consumption:
        friendly_name: 'E3DC Own Consumption ratio'
        unit_of_measurement: '%'
        value_template: "{{ ((states('sensor.e3dc_autarky_and_consumption')|int / 256 - states('sensor.e3dc_autarky')|int) * 256)|round(0,'floor') }}"
2 Likes