Hello!
…and Thanks a lot Volker for shareing your code!
It safed me a lot of time, since many of the adresses are not correct in the E3DC ModBus documentation file.
Unfortunatelly I was not able to get your code running as splited files.
So a merged all files into one and it worked like a charme.
I also added a wallbox.
I hope it is ok to share my attempt here, maybe someone else can benefit.
++ needs to be added configuration.yaml:
homeassistant:
packages: !include_dir_named packages/
++ file location:
config\packages\e3dc_modebus.yaml
++ file content:
#### get data over ModBus
modbus:
- name: e3dc
type: tcp
host: 10.1.1.71
port: 502
sensors:
- name: power_solar
address: 40067
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 2
- name: power_battery
address: 40069
state_class: measurement
scan_interval: 2
- name: soc_battery
address: 40082
state_class: measurement
unit_of_measurement: "%"
scan_interval: 30
- name: power_consumption
address: 40071
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 2
- name: power_grid
address: 40073
state_class: measurement
scan_interval: 2
- name: power_wallbox
address: 40077
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 2
- name: power_solar_used_by_wallbox
address: 40079
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 2
- name: power_external_source
address: 40076
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 30
- name: state_emergency_power
address: 40083
state_class: measurement
scan_interval: 30
- name: state_ems
address: 40084
state_class: measurement
scan_interval: 30
- name: state_wb0
address: 40087
state_class: measurement
scan_interval: 5
- name: autarky_and_consumption
address: 40081
state_class: measurement
scan_interval: 30
- name: power_string_1
address: 40101
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 5
- name: power_string_2
address: 40102
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 5
- name: power_meter1_p1
address: 40105
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 5
- name: power_meter1_p2
address: 40106
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 5
- name: power_meter1_p3
address: 40107
state_class: measurement
unit_of_measurement: "W"
device_class: power
scan_interval: 5
#### power meters
sensor:
- platform: template
sensors:
power_battery_in:
#unique_id: "power_battery_in"
friendly_name: "Leistung Batterie Laden"
unit_of_measurement: "W"
device_class: power
value_template: >
{% if states('sensor.power_battery') | int > 0 %}
{{ states('sensor.power_battery') | int }}
{% else -%}
0
{% endif %}
power_battery_out:
#unique_id: "power_battery_out"
friendly_name: "Leistung Batterie Entaden"
unit_of_measurement: "W"
device_class: power
value_template: >
{% if states('sensor.power_battery') | int > 0 %}
0
{% else -%}
{{ (states('sensor.power_battery') | int) | abs }}
{% endif %}
power_grid_in:
#unique_id: "power_grid_in"
friendly_name: "Leistung Netz Beziehen"
unit_of_measurement: "W"
device_class: power
value_template: >
{% if states('sensor.power_grid') | int > 0 %}
{{ states('sensor.power_grid') | int }}
{% else -%}
0
{% endif %}
power_grid_out:
#unique_id: "power_grid_in"
friendly_name: "Leistung Netz Einspeisen"
unit_of_measurement: "W"
device_class: power
value_template: >
{% if states('sensor.power_grid') | int > 0 %}
0
{% else -%}
{{ (states('sensor.power_grid') | int) | abs }}
{% endif %}
power_autarky:
#unique_id: ""
friendly_name: "Autarkie"
unit_of_measurement: "%"
value_template: "{{ (states('sensor.autarky_and_consumption')|int / 256)|round(0,'floor') }}"
power_consumption_percent:
#unique_id: ""
friendly_name: "Eigenverbrauch"
unit_of_measurement: "%"
value_template: "{{ ((states('sensor.autarky_and_consumption')|int / 256 - states('sensor.power_autarky')|int) * 256)|round(0,'floor') }}"
#### energy meters
- platform: integration
source: sensor.power_solar
name: energy_solar
unit_prefix: k
unit_time: h
round: 1
- platform: integration
source: sensor.power_battery_out
name: energy_battery_out
unit_prefix: k
unit_time: h
round: 1
- platform: integration
source: sensor.power_battery_in
name: energy_battery_in
unit_prefix: k
unit_time: h
round: 1
- platform: integration
source: sensor.power_grid_out
name: energy_grid_out
unit_prefix: k
unit_time: h
round: 1
- platform: integration
source: sensor.power_grid_in
name: energy_grid_in
unit_prefix: k
unit_time: h
round: 1
- platform: integration
source: sensor.power_consumption
name: energy_consumption
unit_prefix: k
unit_time: h
round: 1
- platform: integration
source: sensor.power_wallbox
name: energy_wallbox
unit_prefix: k
unit_time: h
round: 1
- platform: integration
source: sensor.power_solar_used_by_wallbox
name: energy_solar_used_by_wallbox
unit_prefix: k
unit_time: h
round: 1
- platform: integration
source: sensor.power_external_source
name: energy_external_source
unit_prefix: k
unit_time: h
round: 1
binary_sensor:
- platform: template
sensors:
#### EMS
battery_loading_blocked:
friendly_name: "Laden der Batterien ist gesperrt"
value_template: "{{ states('sensor.state_ems')|int|bitwise_and(1) > 0 }}"
battery_unloading_blocked:
friendly_name: "Entladen der Batterien ist gesperrt"
value_template: "{{ states('sensor.state_ems')|int|bitwise_and(2) > 0 }}"
emergency_power_possible:
friendly_name: "Notstrommodus ist möglich"
value_template: "{{ states('sensor.state_ems')|int|bitwise_and(4) > 0 }}"
weather_based_loading:
friendly_name: "Wetterbasiertes Laden"
value_template: "{{ states('sensor.state_ems')|int|bitwise_and(8) > 0 }}"
power_limiter:
friendly_name: "Abregelungs-Status"
value_template: "{{ states('sensor.state_ems')|int|bitwise_and(16) > 0 }}"
smartcharge_loading_blocked:
friendly_name: "Ladesperrzeit aktiv"
value_template: "{{ states('sensor.state_ems')|int|bitwise_and(32) > 0 }}"
smartcharge_unloading_blocked:
friendly_name: "Entladesperrzeit aktiv"
value_template: "{{ states('sensor.state_ems')|int|bitwise_and(64) > 0 }}"
emergency_power_active:
friendly_name: "Notstrom Modus aktiviert"
value_template: "{{ is_state('sensor.state_emergency_power', 1) }}"
#### Wallbox
wallbox_available:
friendly_name: "Wallbox vorhanden und verfügbar"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(1) > 0 }}"
wallbox_solarmode_active:
friendly_name: "Sonnenmodus aktiv"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(2) > 0 }}"
wallbox_charging_blocked:
friendly_name: "Laden blockiert"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(4) > 0 }}"
wallbox_charging_ongoing:
friendly_name: "Auto lädt"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(8) > 0 }}"
wallbox_typ2_plug_locked:
friendly_name: "Typ-2-Stecker verriegelt"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(16) > 0 }}"
wallbox_typ2_plug_plugged:
friendly_name: "Typ-2-Stecker gesteckt"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(32) > 0 }}"
wallbox_power_plug_active:
friendly_name: "Schukosteckdose an"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(64) > 0 }}"
wallbox_power_plug_plugged:
friendly_name: "Schukostecker gesteckt"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(128) > 0 }}"
wallbox_power_plug_locked:
friendly_name: "Schukostecker verriegelt"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(256) > 0 }}"
wallbox_relais_p1_aktive:
friendly_name: "Relais 1. Phase an"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(512) > 0 }}"
wallbox_relais_p2_aktive:
friendly_name: "Relais 2. Phase an"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(1024) > 0 }}"
wallbox_relais_p3_aktive:
friendly_name: "Relais 3. Phase an"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(2048) > 0 }}"
wallbox_1_phase_active:
friendly_name: "Eine Phase aktiv"
value_template: "{{ states('sensor.state_wb0')|int|bitwise_and(4096) > 0 }}"
#### daily meters
utility_meter:
energy_solar_daily:
source: sensor.energy_solar
cycle: daily
energy_grid_in_daily:
source: sensor.energy_grid_in
cycle: daily
energy_grid_out_daily:
source: sensor.energy_grid_out
cycle: daily
energy_battery_in_daily:
source: sensor.energy_battery_in
cycle: daily
energy_battery_out_daily:
source: sensor.energy_battery_out
cycle: daily
energy_consumption_daily:
source: sensor.energy_consumption
cycle: daily
energy_wallbox_daily:
source: sensor.energy_wallbox
cycle: daily
energy_solar_used_by_wallbox_daily:
source: sensor.energy_solar_used_by_wallbox
cycle: daily
energy_external_source_daily:
source: sensor.energy_external_source
cycle: daily