Thank you so much @all for the information that you share here.
I tried to collect everything that I have read here in this whole topic and I have put it all together in one file.
I wanted to share it in case someone else finds it useful as well.
If this file is placed in a folder called integrations, it can be included like this in the configuration.yaml:
homeassistant:
packages: !include_dir_named integrations
integrations/alfen.yaml
#
# https://alfen.com/file-download/download/public/1610
# https://community.home-assistant.io/t/alfen-eve-pro-ev-chargepoint-interface-via-tcp-modbus
#
modbus:
- name: wallbox
type: tcp
host: 192.168.1.237
port: 502
sensors:
- name: Wallbox name
unique_id: wallbox_name
slave: 200
address: 100
count: 17
data_type: string
- name: Wallbox uptime
unique_id: wallbox_uptime
slave: 200
address: 174
data_type: uint64
unit_of_measurement: ms
- name: Wallbox temperature
unique_id: wallbox_temperature
slave: 200
address: 1102
data_type: float32
unit_of_measurement: °C
- name: Wallbox max current (active)
unique_id: wallbox_active_max_current
slave: 200
address: 1100
data_type: float32
unit_of_measurement: A
- name: Wallbox real power sum
unique_id: wallbox_real_power_sum
slave: 1
address: 344
data_type: float32
unit_of_measurement: W
- name: Wallbox mode3 state
unique_id: wallbox_mode3_state
slave: 1
address: 1201
count: 5
data_type: string
- name: Wallbox max current (applied)
unique_id: wallbox_actual_applied_max_current
slave: 1
address: 1206
data_type: float32
unit_of_measurement: A
- name: Wallbox max current
unique_id: wallbox_max_current
slave: 1
address: 1210
data_type: float32
unit_of_measurement: A
- name: Wallbox amount of used phases
unique_id: wallbox_amount_of_used_phases
slave: 1
address: 1215
data_type: uint16
- name: Wallbox max current valid time
unique_id: wallbox_max_current_valid_time
slave: 1
address: 1208
data_type: uint32
unit_of_measurement: s
template:
- sensor:
- name: Wallbox Status
state: >
{% set m3 = states('sensor.wallbox_mode3_state').replace('\0','') %}
{% if m3 in ['A', 'E'] %} available
{% elif m3 in ['B1', 'B2', 'C1', 'D1'] %} connected
{% elif m3 in ['C2', 'D2'] %} charging
{% else %} {{ m3 }}
{% endif %}
input_number:
wallbox_set_max_power:
name: Set wallbox max power
unit_of_measurement: kW
min: 0
max: 11
step: 0.1
automation:
- id: "wallbox_automation_set_max_power"
alias: Wallbox - Set max power
description: "Calculates and sets the amount of phaees and the max current"
trigger:
- platform: state
entity_id:
- input_number.wallbox_set_max_power
condition: []
action:
- variables:
power: "{{states('input_number.wallbox_set_max_power') | float }}"
current: |
{# no loading #}
{% if power <= 1.38 %} 5
{# 1 phase loading #}
{% elif power < 1.61 %} 6 {# 1.38kW #}
{% elif power < 1.84 %} 7 {# 1.61kW #}
{% elif power < 2.07 %} 8 {# 1.84kW #}
{% elif power < 2.30 %} 9 {# 2.07kW #}
{% elif power < 2.53 %} 10 {# 2.30kW #}
{% elif power < 2.76 %} 11 {# 2.53kW #}
{% elif power < 2.99 %} 12 {# 2.76kW #}
{% elif power < 3.22 %} 13 {# 2.99kW #}
{% elif power < 3.45 %} 14 {# 3.22kW #}
{% elif power < 3.68 %} 15 {# 3.45kW #}
{% elif power < 4.14 %} 16 {# 3.68kW #}
{# 3 phases loading #}
{% elif power < 4.83 %} 6 {# 4.14kW #}
{% elif power < 5.52 %} 7 {# 4.83kW #}
{% elif power < 6.21 %} 8 {# 5.52kW #}
{% elif power < 6.90 %} 9 {# 6.21kW #}
{% elif power < 7.59 %} 10 {# 6.90kW #}
{% elif power < 8.28 %} 11 {# 7.59kW #}
{% elif power < 8.97 %} 12 {# 8.28kW #}
{% elif power < 9.66 %} 13 {# 8.97kW #}
{% elif power < 10.35 %} 14 {# 9.66kW #}
{% elif power < 11.00 %} 15 {# 10.35kW #}
{% else %} 16 {# 11.04kW #}
{% endif %}
# https://www.h-schmidt.net/FloatConverter/IEEE754.html
registervalue: |
{% if current == 5 %}[0x40a0, 0x0000]
{% elif current == 6 %}[0x40c0, 0x0000]
{% elif current == 7 %}[0x40e0, 0x0000]
{% elif current == 8 %}[0x4100, 0x0000]
{% elif current == 9 %}[0x4110, 0x0000]
{% elif current == 10 %}[0x4120, 0x0000]
{% elif current == 11 %}[0x4130, 0x0000]
{% elif current == 12 %}[0x4140, 0x0000]
{% elif current == 13 %}[0x4150, 0x0000]
{% elif current == 14 %}[0x4160, 0x0000]
{% elif current == 15 %}[0x4170, 0x0000]
{% elif current == 16 %}[0x4180, 0x0000]
{% endif %}
alias: Calculate max current
- if:
- condition: template
value_template: "{{ power < 4.14 }}"
then:
- service: modbus.write_register
data:
address: 1215
unit: 1
hub: wallbox
value: 1
else:
- service: modbus.write_register
data:
address: 1215
unit: 1
hub: wallbox
value: 3
alias: Set amount of phases to 1 or 3
- service: modbus.write_register
data:
address: 1210
unit: 1
hub: wallbox
value: "{{ registervalue }}"
alias: Set max current
mode: single
This includes an automation that sets the max current (from 5A to 16A) and the amount of used phases depending on the set max power.
Here is an example card that can be used in a dashboard to show all the entitiees:
Dashboard Card
- type: entities
entities:
- entity: sensor.wallbox_name
- entity: sensor.wallbox_temperature
- entity: sensor.wallbox_uptime
- entity: sensor.wallbox_status
- entity: sensor.wallbox_mode3_state
- entity: sensor.wallbox_real_power_sum
- entity: input_number.wallbox_set_max_power
- entity: sensor.wallbox_max_current_active
- entity: sensor.wallbox_max_current_applied
- entity: sensor.wallbox_max_current
- entity: sensor.wallbox_amount_of_used_phases
- entity: sensor.wallbox_max_current_valid_time
title: Wallbox
