Read bitmask value of register in Modbus sensor

Hey, thanks for sharing this! I’m pretty new to HA and struggle a lot with my E3DC. If you don’t mind would it be possible the share the implementation of the other values as well?
Thanks a lot!

1 Like

+1 for sharing your archivements

Hey, sorry, must have missed the notification about your reply. You still need help with the other values?

sensor:
  - platform: modbus
    registers:
      - name: E3DC solar power
        unit_of_measurement: W
        register: 40067
      - name: E3DC battery power
        unit_of_measurement: W
        register: 40069
      - name: E3DC battery soc
        unit_of_measurement: '%'
        register: 40082
        data_type: uint
      - name: E3DC power consumption
        unit_of_measurement: W
        register: 40071
      - name: E3DC grid power
        unit_of_measurement: W
        register: 40073
      - name: E3DC emergency power state
        data_type: uint
        register: 40083
      - name: E3DC EMS state
        data_type: uint
        register: 40084
1 Like

I have just started using home assistant, having received my raspberry pi just yesterday I am trying to add all available integrations to the setup.
I have a E3DC S10 Mini inverter in my network and noticed that there is no standard integration available. I stumbled upon this forum entry and am now trying to follow up and integrate the E3DC via Modbus.
I crosschecked the registers with the documentation that is available in the E3DC Webinterface.
I have enabled the Modbus on the E3DC itself.
Now I was trying to add the Modbus, the sensor and binary sensor as described in this thread to the configuration.yaml, however the sensor data is not available in home assistant. Guess I have either made a mistake in the config, or it is not retrieving information from the inverter. IP and Port are correct. Where could I start to investigate the issue?

modbus:
  - name: E3DC
    type: tcp
    host: 192.168.0.195
    port: 502

sensor:
  - platform: modbus
    registers:
      - name: E3DC solar power
        hub: E3DC
        unit_of_measurement: W
        register: 40067
[...]

Edit: I did find a home-assistant.log file indicating that Modbus is not able to setup the connection to the inverter…

2020-10-08 19:48:20 ERROR (SyncWorker_22) [pymodbus.client.sync] Connection to (192.168.0.195, 502) failed: [Errno 111] Connection refused

Still struggling to solve it though. So if anyone has made similar experience, I’d be glad for support

please note that at least for me the registers were off by -1, so you have to use 40066 in HA when the documentation says 40067. And you should enable the E3DC mode for Modbus and not the other one in the S10.
No idea about the connection issue though.

Issue has been solved. Somehow the Modbus was still deactivated on the E3DC, although I thought that I activated it. Everything seems to work as expected. Thanks for the reply and the help for integration.

FYI, I added the autarky and consumption ratio sensors to my setup in order to be able to use this gem for Lovelace: https://github.com/JonahKr/power-distribution-card

My new sensor setup looks like this:

sensors:
  - platform: modbus
    registers:
      - name: E3DC solar power
        unit_of_measurement: W
        register: 40067
        hub: e3dc
        device_class: power
      - name: E3DC battery power
        unit_of_measurement: W
        register: 40069
        hub: e3dc
        device_class: power
      - name: E3DC battery soc
        unit_of_measurement: '%'
        register: 40082
        data_type: uint
        hub: e3dc
        device_class: battery
      - name: E3DC power consumption
        unit_of_measurement: W
        register: 40071
        hub: e3dc
        device_class: power
      - name: E3DC grid power
        unit_of_measurement: W
        register: 40073
        hub: e3dc
        device_class: power
      - name: E3DC emergency power state
        data_type: uint
        register: 40083
        hub: e3dc
      - name: E3DC EMS state
        data_type: uint
        register: 40084
        hub: e3dc
      - name: E3DC autarky and consumption
        data_type: uint
        register: 40081
        hub: e3dc
  - 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') }}"

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 }}"

Thank you for the update, this looks briliant.

Seems to be solved - sunspec was chosen instead of E3DC. I now have values :smile:
Hi all, I’m a very basic user of HA. I managed some Integrations and now try to integrate my E3DC S10 Pro. I did some basic register entries in the config.yaml.
It seems that I got some steps in the right direction. I get entities but incorrect or no values.
eg. actual solar power is 2659 but I get 0.
There is a message (translated it from german) This entity in not unique…

Would be great if I could get any hints.

modbus:
  name: e3dc
  type: tcp
  host: 192.168.1.45
  port: 502

sensor:
  - platform: modbus
    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 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     

Hi Peter, all,
managed to enable the modbus connection by copying and adopting to my specifics (IP) - fine so far.
Also gave the templated sensors (binary sensors) a try - looks like they are working as well. To be honest, I have no clue of how to adopt additional (binary) sensors for the values deriving from the modbus register reads. What I’m looking for is a simple way to get sensor usable in e.g. lovelace (via power-distribution card or others) for all of the data from the modbus register(s).
In case anybody could help me on that: highly appreciated. Either directly or link or …
Thanks in advance.

I’m not sure what the problem is. Do you have these entities?


I use it now with the newest version of the power-distribution-card.

Hi Peter,
thanks for your fast reply. The listet entities is exactly what I’m missing.
For the sake of clarification here my snip from configuration.yaml:

modbus:

  • name: E3DC
    type: tcp
    host: 192.168.99.70
    port: 502

sensors:

  • platform: modbus
    scan_interval: 10
    registers:
    • name: E3DC_solar_power
      slave: 1
      unit_of_measurement: W
      register: 40068
      hub: e3dc
      device_class: power
    • name: E3DC_battery_power
      slave: 1
      unit_of_measurement: W
      register: 40070
      hub: e3dc
      device_class: power
    • name: E3DC_battery_soc
      slave: 1
      unit_of_measurement: ‘%’
      register: 40083
      data_type: uint
      hub: e3dc
      device_class: battery
    • name: E3DC_power_consumption
      slave: 1
      unit_of_measurement: W
      register: 40072
      hub: e3dc
      device_class: power
    • name: E3DC_grid_power
      slave: 1
      unit_of_measurement: W
      register: 40074
      hub: e3dc
      device_class: power
    • name: E3DC_emergency_power_state
      slave: 1
      data_type: uint
      register: 40084
      hub: e3dc
    • name: E3DC_EMS_state
      slave: 1
      data_type: uint
      register: 40085
      hub: e3dc
    • name: E3DC_autarky_and_consumption
      slave: 1
      data_type: uint
      register: 40082
      hub: e3dc
  • 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’) }}”

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 }}”

So, pretty much like listet here in the forum. Have tried both the original register addresses as listed above and the ones with -1 offset.
Absolutely no idea, why the register-based entities (sensors) do not show up. Have a likewise config for some of the values in node red (implemented by my more capable son) and there the registers show their values.
What I’d expect/like to see as entities are the usual suspects arising form the sensor definitions in the second section. What would be a bonus add-on are the wallbox values - but that is nice to have. The core stuff is my personal must have as I not only want to visualize and store the values but also want to be able to kick off my washer, dryer etc based on E3/DC states/values.
I am like a small brown coated animal running through the forrest not seing nothing …
Thanks.

a) have you enabled the modbus interface on your E3DC?
b) have you set the modbus spec to use also to E3DC (on your E3DC device)? If you have set it to “sunspec” it won’t work, since this spec doesn’t expose all the desired registers.

Hi da-anda (is there btw da-oa as well?),
yessir, ModBus is enabled, set to E3DC and IP port is 502.
In addition, checked the HA log for any error messages as such were also mentioned here.
As from the last restart the log states:
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 199, in _async_setup_platform
await asyncio.shield(task)
File “/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/src/homeassistant/homeassistant/components/modbus/sensor.py”, line 134, in setup_platform
hub = hass.data[MODBUS_DOMAIN][hub_name]
KeyError: ‘e3dc’
Was wollen uns - no idea what this tends to tell me …

Peter, da-anda, all,
clear case of “stupid me” - it was a quite simple missmatch in spelling: modbus platform E3DC vs. hub spelling e3dc. Corrected and what shall I say: works. Rest to follow.
Thanks for your contribution - at the least brought back my motivation and directed me to the right look-up. Cheers. Cool.

Hi da-anda (is there btw da-oa as well?),

seems you got the reference :+1: :laughing:

Hi all final found the bits for the status, thanks for that.

Sorry for hijacking this thread, but just if anyone is interested, because modbus to E3DC is limited and existing implementations are for specific use-cases, I wrote a lib to use the “Raw” RSCP protocol and included a command line utility to make use of it with the command_line sensor.
It requires a bit of knowledge about the Tag’s and datatypes structure, but you are not limited in what you request and how much.


It is already working fine in my home assistant setup. The utility combined with jq let you even do almost anything.
Feedback and contributions are always welcome :wink:
1 Like

@grandslam there already is a python based RSCP lib for E3DC around on github which we could use for a “native” HA component, but I lack the python knowledge to write such an integration. https://github.com/fsantini/python-e3dc/

Yes I know that one already, also contributed to it to include some Quattroporte specific stuff and specific case of my setup.
Also there are some others C-based with specific use cases.
But none of them allow the raw communication as command line utility for easy integration without python knowledge.
I have now complete control just by using the HA command_line platform and can use it also outside from HA.

Side note: also needed a reason to learn go :wink:

Maybe a little bit offtopic, but I have successfully integrated the mod bus read outs from my E3DC, creating multiple sensors for the current power (solar, battery, grid and home) in Watts.
Is it possible to track the energy consuption [Wh] using this information? I came across the utility meter integration, which would track Wh per day, week, year, but as an input already requires a sensor providing information in Wh.

My first step would be to understand how the home consumption can be tracked via an utility meter. Secondly the engery bought from grid over time would be interesting to track. Here the sensor could have positive and negative values (depending on if energy is sold, or bought).