Read bitmask value of register in Modbus sensor

Glad you could sort out the networking issues, wouldn’t have had any idea what to tell.

As for the lovelace card - check HACS for the power-distribution-card or install it manually from here GitHub - JonahKr/power-distribution-card: A Lovelace Card for visualizing power distributions.

Thanks da-anda

well, had to move the server at the end and get rid of my dmz. NAT should have worked but didn’t.
Took a few paket traces and had loads of retransmissions. So it was easier for me to move the server.

I will take a look at the link. But have to say that i am a “copy & paste” programmer :slight_smile: lets see how far my skills can go.
Another thing is that i do run my system in docker so no supervisior is there.
But hey actually i am proud. A week ago i did not even knew what home automation could give me.
Ordered some ikea lamps… very curious about it…

cheers A.

Same here… I just checked and found

So something has to be added and you can use status attributes on the developer tools tab.
Some also put it into the customization.yamls. Looks like wildcards working as well.

cheers A

@ArminF well, easiest way to install custom components is via HACS, so follow it’s install instructions (will also run in your setup) and installing community components is as simple as one click. https://hacs.xyz/

Aloha da-anda

Thanks! I could install HACS and guess what… even i could do it :slight_smile:
works like a charm. I am very happy.
No i need check how i get this energy stuff up and running.

Evening,
all up and running. maybe some fine tuning here and there. But for now i am very pround

DId anyone of you activated the Energy Management?
I did and figured most of it out.
There seems to be a battery check every morning on the E3DC as i get some charge/discharge values even when there is no solar power and battery is not in discharge.

2021-11-21_21-16-00

Do you get the same? I do not think my settings are wrong actually. Checked them several times.
For the entities i used a template sensor and integration for the conversion from watt to kwh.
Sensors i had to split into only positive values by using ABS.
thanks A

@ArminF sorry didn’t read your question until today.
Do you mean this:

image

type: custom:power-distribution-card
title: Photovoltaik Anlage
animation: slide
entities:
  - solar:
      entity: sensor.e3dc_solar_hausdach
      icon: mdi:weather-sunny
      name: Hausdach
      unit_of_display: adaptive
    entity: sensor.e3dc_solar_hausdach
    name: Hausdach
    decimals: '3'
    unit_of_display: kW
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    preset: solar
    icon: mdi:home-roof
    invert_value: false
  - decimals: '3'
    display_abs: true
    name: Garage
    unit_of_display: kW
    icon: mdi:garage
    producer: true
    entity: sensor.e3dc_solar_extern_garage
    preset: producer
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    invert_value: true
  - grid:
      entity: sensor.e3dc_netzbezug
      name: Netz
      unit_of_display: adaptive
      invert_value: false
    entity: sensor.e3dc_netzbezug
    name: Netzbezug
    decimals: '3'
    unit_of_display: kW
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    preset: grid
    icon: mdi:transmission-tower
  - battery:
      entity: sensor.e3dc_batterie
      icon: mdi:battery-50
      name: Batterie
      unit_of_display: adaptive
      invert_value: true
    entity: sensor.e3dc_hausbezug
    name: Hausbezug
    decimals: '3'
    unit_of_display: kW
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    preset: consumer
    icon: mdi:home-assistant
    invert_value: true
  - home:
      entity: sensor.e3dc_hausbezug
      name: Haus
      unit_of_display: adaptive
      invert_value: true
    entity: sensor.e3dc_batterie
    name: Batterie
    decimals: '3'
    unit_of_display: kW
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    preset: battery
    icon: ''
    invert_value: true
  - decimals: '3'
    display_abs: true
    name: car
    unit_of_display: kW
    consumer: true
    icon: mdi:car-electric
    entity: sensor.e3dc_wallbox
    preset: car_charger
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    invert_value: true
center:
  type: bars
  content:
    - name: Batterie
      preset: ratio
      bar_color: green
      bar_bg_color: red
      entity: sensor.e3dc_batterie_ladung
      invert_value: false
1 Like

Hi Peter,
no worries. I could figure it out and got the nice card up and running.
It seems to be a battery/system check from our E3DC system which shows up daily.
Was my last post. So i accepted it as normal.
Rest is working proper and i am very happy with the details/statistics i get out of it.

cheers and merry christmas!
Armin

Hi Armin,

its very nice, can you post your entities please :-).

in order to use the Energy component of HA, you need a couple additional template sensors to convert the +/- values coming from e3dc to separate sensors for in and out.

These are all my e3dc related sensors (copied from a split out yaml, you if you have your config all in the main file, you have to adjust indention etc)

- 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') }}"
    # Grid out
    e3dc_grid_power_out:
      unit_of_measurement: 'W'
      device_class: power
      value_template: >
        {% if states('sensor.e3dc_grid_power') | int > 0 %}
          0
        {% else -%}
          {{ (states('sensor.e3dc_grid_power') | int) | abs }} 
        {% endif %}      
    # Grid in
    e3dc_grid_power_in:
      unit_of_measurement: 'W'
      device_class: power
      value_template: >
        {% if states('sensor.e3dc_grid_power') | int > 0 %}
          {{ states('sensor.e3dc_grid_power') | int }}
        {% else -%}
          0
        {% endif %}
    # Battery out
    e3dc_battery_power_out:
      unit_of_measurement: 'W'
      device_class: power
      value_template: >
        {% if states('sensor.e3dc_battery_power') | int > 0 %}
          0
        {% else -%}
          {{ (states('sensor.e3dc_battery_power') | int) | abs }} 
        {% endif %}
    # Battery in
    e3dc_battery_power_in:
      unit_of_measurement: 'W'
      device_class: power
      value_template: >
        {% if states('sensor.e3dc_battery_power') | int > 0 %}
          {{ states('sensor.e3dc_battery_power') | int }}
        {% else -%}
          0
        {% endif %}

- platform: integration
  source: sensor.e3dc_battery_power_out
  name: energy_battery_discharge
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.e3dc_battery_power_in
  name: energy_battery_charge
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.e3dc_solar_power
  name: energy_solar_production
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.e3dc_power_consumption
  name: energy_consumption
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.e3dc_grid_power_in
  name: energy_grid_usage
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.e3dc_grid_power_out
  name: energy_grid_feed_in
  unit_prefix: k
  round: 2
2 Likes

With the absolut value it worked like a charm for me as well.

Rest i splitted in to folders and extra yaml files.

Hi Armin,

your card look very nice. I have a E3DC Pro.
Could you perhaps post your configuration for the card (post 47/51)??
Grettings Matthias

Hi All,

the dashboard is mostly default cards.

  • HACS Energy Card
  • Power Distribution from Energy Tab is a custom card.
    Here is the code just create an empty on and paste this:
title: Energy distribution today
type: energy-distribution
link_dashboard: true

The Cost calculations are sensor templates which uses the powerprice we pay/earn.

# Costs
# EBL Electricity costs -> 0.17 CHF Import - 0.10 CHF Export
# Calculation Grid Import kWh and Export kWh
    e3dc_grid_cost_import:
      friendly_name: E3DC Grid Import Cost
      unit_of_measurement: 'CHF'
      value_template: "{{ (states('sensor.e3dc_grid_positive_energy')|float * 0.17 )|round(2,'floor') }}"
    e3dc_grid_cost_export:
      friendly_name: E3DC Grid Export Cost
      unit_of_measurement: 'CHF'
      value_template: "{{ (states('sensor.e3dc_grid_negative_energy')|float * 0.10 )|round(2,'floor') }}"

Costs and Statistic are buttons.
Statistic nabigates to /energy

Battery is a default gauge with thresholds.

Nothing fancy.
On the right is a entity card with header picture.

armin

1 Like

Hi Armin,
who do you get the information on kW/h. Is it calculated or measured?
When calculated, how?
When measured, where and how?
Matthias

calculated using the Riemann integration. See my previous post. You first need to create dedicated sensors for energy consumption and production since the Riemann can’t handle +/- values, and then you need to feed those normalized values to an additional Riemann sensor to get kWh and be able to use it in the energy panel

Hi , I would like to create a sensor with the status for example of the fan of my hvca, they would correspond to bits 3,4,5 of register 109, how do you advise me to do?

Hi. How do I integrate your githup code into HA?
Thanks
Danke deepl

sorry, missed your question. In case it’s still relevant, you need to create several sensors for this. First, a modbus sensor which is returning register 109. Then you have to convert this sensor into separate sensors for each bitmask you would like to extract by using a template sensor

binary_sensor:
  - platform: template
    sensors:
      hvca_bit_3:
        friendly_name: "Bit 3"
        value_template: "{{ states('sensor.your-sensor-with-register-109')|int|bitwise_and(3) > 0 }}"

all you have to do is to change the integer inside the bitwise_and() method of the value_template to the bit value you would like to read.

1 Like

best would be if somebody would write a HomeAssistant component for E3DC using one of the available python based RSCP clients.

modbus:
  - name: "hub1"
    type: tcp
    host: 192.xxxxx
    port: 8899
    # delay: 2
    # timeout: 3
    # retries: 3
    # retry_on_empty: true
    # close_comm_on_error: false
    sensors:    
      - name: Load Clivet
        address: 109
        hvca_bit_0:
            friendly_name: "Bit 0"
            value_template: "{{ states('sensor.load_clivet')|int|bitwise_and(0) > 0 }}"    
    
        hvca_bit_3:
            friendly_name: "Bit 3"
            value_template: "{{ states('sensor.load_clivet')|int|bitwise_and(3) > 0 }}"    
        hvca_bit_4:
            friendly_name: "Bit 4"
            value_template: "{{ states('sensor.load_clivet')|int|bitwise_and(4) > 0 }}"  
        hvca_bit_5:
            friendly_name: "Bit 5"
            value_template: "{{ states('sensor.load_clivet')|int|bitwise_and(5) > 0 }}" 

Do I have to configure the modbus sensor differently? because I don’t see a string of bits for the sensor.load_clivet

image

i try to a different sensor/register 100 but it doesn’ t work

      - name: Operation Mode Clivet
        address: 100

the HA sensor show 8 but i don’t know how to convert it because the hvca is in hybrid mode so the value should be 2.

image

        hvca_hybrid:
            friendly_name: "hybrid"
            value_template: "{{ states('sensor.operation_mode_clivet')|int|bitwise_and(2) > 0 }}"   

        hvca_e_heater:
            friendly_name: "e heater"
            value_template: "{{ states('sensor.operation_mode_clivet')|int|bitwise_and(3) > 0 }}"   
        hvca_vacation:
            friendly_name: "vacation"
            value_template: "{{ states('sensor.operation_mode_clivet')|int|bitwise_and(4) > 0 }}"   

image