EVCC integration via MQTT (sensor entity config)

and what?

You are right, I’ve corrected the typo, even though it doesn’t really matter :slight_smile:

Beware,
updates to the code above needed after https://github.com/evcc-io/evcc/pull/3714

Just saw this :tada:

1 Like

Updated configuration:

mqtt:
  select:
    - name: evcc_mode
      unique_id: uniqueid__evcc_mode_select
      icon: mdi:tune-variant
      state_topic: "evcc/loadpoints/1/mode"
      command_topic: "evcc/loadpoints/1/mode/set"
      availability_topic: "evcc/status"
      options:
        - "off"
        - "now"
        - "minpv"
        - "pv"

    - name: evcc_phases
      unique_id: uniqueid__evcc_phases_select
      icon: mdi:backburger
      state_topic: "evcc/loadpoints/1/phasesEnabled"
      command_topic: "evcc/loadpoints/1/phasesEnabled/set"
      availability_topic: "evcc/status"
      options:
        - "0"
        - "1"
        - "3"

  #############################################################################

  sensor:
    - name: evcc_charge_power_w
      unique_id: uniqueid__evcc_charge_power_w
      icon: mdi:car-electric
      state_topic: "evcc/loadpoints/1/chargePower"
      value_template: "{{ value | round(0) }}"
      unit_of_measurement: "W"
      state_class: measurement
      availability_topic: "evcc/status"

    - name: evcc_charged_energy_kwh
      unique_id: uniqueid__evcc_charged_energy_kwh
      icon: mdi:battery-charging-high
      state_topic: "evcc/loadpoints/1/chargedEnergy"
      value_template: "{{ (value | float / 1000) | round(4) }}"
      unit_of_measurement: "kWh"
      availability_topic: "evcc/status"

    - name: evcc_charged_energy_self_kwh
      unique_id: uniqueid__evcc_charged_energy_self_kwh
      icon: mdi:battery-charging-high
      state_topic: "evcc/site/savingsSelfConsumptionCharged"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "kWh"
      availability_topic: "evcc/status"

    - name: evcc_charged_energy_grid_kwh
      unique_id: uniqueid__evcc_charged_energy_grid_kwh
      icon: mdi:battery-charging-high
      state_topic: "evcc/site/savingsGridCharged"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "kWh"
      availability_topic: "evcc/status"

    #############################################################################

    - name: evcc_phases_active
      unique_id: uniqueid__evcc_phases_active
      icon: mdi:backburger
      state_topic: "evcc/loadpoints/1/phasesActive"
      value_template: "{{ value | round(0) }}"
      availability_topic: "evcc/status"

    - name: evcc_charge_duration_s
      unique_id: uniqueid__evcc_charge_duration_s
      icon: mdi:timer-settings-outline
      state_topic: "evcc/loadpoints/1/chargeDuration"
      value_template: "{{ value | round(0) }}"
      unit_of_measurement: "s"
      availability_topic: "evcc/status"

    #############################################################################

    - name: evcc_charge_current_l1_a
      unique_id: uniqueid__evcc_charge_current_l1_a
      icon: mdi:current-ac
      state_topic: "evcc/loadpoints/1/chargeCurrents/l1"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "A"
      availability_topic: "evcc/status"

    - name: evcc_charge_current_l2_a
      unique_id: uniqueid__evcc_charge_current_l2_a
      icon: mdi:current-ac
      state_topic: "evcc/loadpoints/1/chargeCurrents/l2"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "A"
      availability_topic: "evcc/status"

    - name: evcc_charge_current_l3_a
      unique_id: uniqueid__evcc_charge_current_l3_a
      icon: mdi:current-ac
      state_topic: "evcc/loadpoints/1/chargeCurrents/l3"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "A"
      availability_topic: "evcc/status"

    #############################################################################

    - name: evcc_pv_power_w
      unique_id: uniqueid__evcc_pc_power_w
      icon: mdi:home-lightning-bolt-outline
      state_topic: "evcc/site/pvPower"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "W"
      availability_topic: "evcc/status"

    - name: evcc_battery_power_w
      unique_id: uniqueid__evcc_battery_power_w
      icon: mdi:home-lightning-bolt-outline
      state_topic: "evcc/site/batteryPower"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "W"
      availability_topic: "evcc/status"

    - name: evcc_grid_power_w
      unique_id: uniqueid__evcc_grid_power_w
      icon: mdi:home-lightning-bolt-outline
      state_topic: "evcc/site/gridPower"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "W"
      availability_topic: "evcc/status"

    - name: evcc_home_power_w
      unique_id: uniqueid__evcc_home_power_w
      icon: mdi:home-lightning-bolt-outline
      state_topic: "evcc/site/homePower"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "W"
      availability_topic: "evcc/status"

    #############################################################################

    - name: evcc_savings_self_consumption_percent
      unique_id: uniqueid__evcc_savings_self_consumption_percent
      icon: mdi:cash-multiple
      state_topic: "evcc/site/savingsSelfConsumptionPercent"
      value_template: "{{ value | round(1) }}"
      unit_of_measurement: "%"
      availability_topic: "evcc/status"

    - name: evcc_savings_amount
      unique_id: uniqueid__evcc_savings_amount
      icon: mdi:cash-multiple
      state_topic: "evcc/site/savingsAmount"
      value_template: "{{ value | round(2) }}"
      unit_of_measurement: "€"
      availability_topic: "evcc/status"

    #############################################################################

  binary_sensor:
    - name: evcc_loadpoint_enabled
      unique_id: uniqueid__evcc_loadpoint_enabled
      icon: mdi:ev-station
      state_topic: "evcc/loadpoints/1/enabled"
      payload_on: "true"
      payload_off: "false"
      #device_class: problem
      availability_topic: "evcc/status"

    - name: evcc_loadpoint_connected
      unique_id: uniqueid__evcc_loadpoint_connected
      icon: mdi:ev-station
      state_topic: "evcc/loadpoints/1/connected"
      payload_on: "true"
      payload_off: "false"
      #device_class: problem
      availability_topic: "evcc/status"

    - name: evcc_loadpoint_charging
      unique_id: uniqueid__evcc_loadpoint_charging
      icon: mdi:ev-station
      state_topic: "evcc/loadpoints/1/charging"
      payload_on: "true"
      payload_off: "false"
      #device_class: problem
      availability_topic: "evcc/status"

  #############################################################################

  number:
    - name: evcc_min_current
      unique_id: uniqueid__evcc_min_current
      icon: mdi:current-ac
      state_topic: "evcc/loadpoints/1/minCurrent"
      command_topic: "evcc/loadpoints/1/minCurrent/set"
      availability_topic: "evcc/status"
      min: 6
      max: 16
      step: 0.25
      unit_of_measurement: "A"

    - name: evcc_max_current
      unique_id: uniqueid__evcc_max_current
      icon: mdi:current-ac
      state_topic: "evcc/loadpoints/1/maxCurrent"
      command_topic: "evcc/loadpoints/1/maxCurrent/set"
      availability_topic: "evcc/status"
      min: 6
      max: 16
      step: 0.25
      unit_of_measurement: "A"

    - name: evcc_buffer_soc
      unique_id: uniqueid__evcc_buffer_soc
      icon: mdi:label-percent-outline
      state_topic: "evcc/site/bufferSoc"
      command_topic: "evcc/site/bufferSoc/set"
      availability_topic: "evcc/status"
      min: 1
      max: 100
      unit_of_measurement: "%"

    - name: evcc_priority_soc
      unique_id: uniqueid__evcc_priority_soc
      icon: mdi:label-percent-outline
      state_topic: "evcc/site/prioritySoc"
      command_topic: "evcc/site/prioritySoc/set"
      availability_topic: "evcc/status"
      min: 1
      max: 100
      unit_of_measurement: "%"

    - name: evcc_residual_power
      unique_id: uniqueid__evcc_residual_power
      icon: mdi:label-percent-outline
      state_topic: "evcc/site/residualPower"
      command_topic: "evcc/site/residualPower/set"
      availability_topic: "evcc/status"
      min: -5000
      max: +5000
      unit_of_measurement: "W"

#############################################################################
homeassistant:
  customize:
    number.evcc_min_current:
      friendly_name: "Garage Wallbox Minimale Stromstärke"
    select.evcc_mode:
      friendly_name: "Garage EVCC Modus"

15 Likes

Moin
Magst du mir sagen, wo die Config Schnipsel eingefügt werden müssen ?

Danke für die Hilfe.

2 Likes

Hi,

Is there a topic for t he batterySoC ?
In @ThomDietrich fist post there is betterySoC but I do not get values when I added

  - name: evcc_battery_soc
    unique_id: uniqueid__evcc_battery_soc
    state_topic: "evcc/site/batterySoC"
    icon: mdi:label-percent-outline
    value_template: "{{ value | round(1) }}"
    availability_topic: "evcc/status"
    unit_of_measurement: "%"

Is there a way to find all topics published by evcc?

Thank you
letsid

EDIT:

I found the solution:
evcc/site/batterySoc
and not SoC

I used MQTT Explorer (as a Home Assistant add on) to look into the topics.
Here is the corrected sensor:

 - name: evcc_battery_soc
    unique_id: uniqueid__evcc_battery_soc
    state_topic: "evcc/site/batterySoc"
    icon: mdi:label-percent-outline
    value_template: "{{ value | round(1) }}"
    availability_topic: "evcc/status"
    unit_of_measurement: "%"
1 Like

They have changed a few API and MQTT names the last couple of releases. The screenshot in my first post should not be your reference :slight_smile:

Checking the MQTT broker for published messages beyond what I use is anyhow a good idea. Any MQTT client will do the job. I can recommend MQTT Explorer.

1 Like

Thank you for your reply.

I did find mqtt explorer meanwhile and edited my question with the solution

Hi,

does anyone know, how to integrate the entire evcc webpage in the side panel as it is done when using the home assistant addon from evcc?

When putting it at the end of my evcc.yaml I got an error and evcc didnt start.
How should my evcc.yaml look like?

Let me rephrase that. You took a snippet of valid Home Assistant configuration and added it to the end of your evcc configuration. Hope you can hear the irony in this :slight_smile:

What I’ve posted must be part of your Home Assistant configuration. The code must go in a file under <HomeAssistantConfig>/packages/evcc-or-similar-name.yaml. In order to load that file you need to also enable packages in your <HomeAssistantConfig>/configuration.yaml. Read:

Thx a lot. I have overlook your reply above…

It works nearly perfectly now. The only thing missing is that I can’t use the sensors for the energy dashboard. Is it only my problem or do we need to configure the sensors differently?

any hint regarding the ha energy dashboard sensors asked by @Leedrag ?

Hey guys,

for the energy dashboard to work, you need to add state_class: measurement to the relevant sensor definitions. Which ones do you think are relevant and I am happy to amend them above.

ok, found it our by myself.

first, you have to create this template sensors (because the evcc sensors are positiv and negativ, we need to split up this sensors):

sensors:
  - name: "Netz Verbrauch (W)"
    unique_id: netz_verbrauch_w
    unit_of_measurement: "W"
    state_class: measurement
    device_class: power
    state: "{{ max(states('sensor.evcc_grid_power_w') | int, 0) | default(0)}}"

  - name: "Netz Einspeisung (W)"
    unique_id: netz_einspeisung_w
    unit_of_measurement: "W"
    state_class: measurement
    device_class: power
    state: "{{ min(states('sensor.evcc_grid_power_w') | int, 0) | abs | default(0)}}"

  - name: "Batterie Entladeleistung (W)"
    unique_id: batterie_entladeleistung_w
    unit_of_measurement: "W"
    state_class: measurement
    device_class: power
    state: "{{ max(states('sensor.evcc_battery_power_w') | int, 0) | default(0)}}"

  - name: "Batterie Ladeleistung (W)"
    unique_id: batterie_ladeleistung_w
    unit_of_measurement: "W"
    state_class: measurement
    device_class: power
    state: "{{ min(states('sensor.evcc_battery_power_w') | int, 0) | abs | default(0)}}"

Second, you need to create helper sensors “Riemann sum integral” with “k (kilo)” and “hour” for each of these new sensors (and in addition for the pv_grid_power sensor).

Third, you can use this Riemann sensors for the energy dashboard.

:slight_smile:

Hello, if you add the unique_id to the sensors you don’t need to do the conversion with Riemann, you can also do this via the user interface at the gear wheel at the top of the sensor.

@Bimbo009 I don’t want to convert from W to Wh, but from W to kWh, therefor I need the Riemann helper as far as I know :wink:

Are there any known issues with the march update. Since I have updated HA the mqtt sensors aren’t available any more…

You are right, the sensor would have to be in wh.