EVCC integration via MQTT (sensor entity config)

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: "%"
2 Likes

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:

Related to Packages as a default part of the yaml based configuration

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.

Sorry if I didn’t understand that thought: Why do you need Riemann (which intrinsically introduces a drift) if we already have evcc_charged_energy_kwh coming directly from EVCC?

Would love to update my set of complete MQTT entities above, as soon as we agree on the solution.

@ThomDietrich
EVCC exports also the evcc/site/gridEnergy if the meter supports it.
Since the meter is placed at feed-in, is that the total grid consumption (home usage - PV produced) ?

evcc/site.go at 7d08f929857cfe8db28a3b5829483adde0122277 · evcc-io/evcc (github.com)

edit:
I found that at the “evcc/site/gridEnergy” mqtt topic evcc exports the grid energy usage.

First of all: Thank you very much @ThomDietrich for your effort in integrating evcc into Home Assistant via MQTT. It works like a charm and adds an unbelievable amount of WAF :slight_smile:
I have a side question: Do you know how to change the frontend values of the mqtt-state-options? As far as I know, these values don’t have friendly names. I’d like to enhance the WAF further and like to change the displayed names to stuff like “No Charging”, “PV only”, “Charge fast”:
image

1 Like

Thanks!

I can’t think of an easy way. Sadly you can’t “translate” states like in the example. You have to define a new input with your desired display names, then set the MQTT entity from that via an automation.

Something like the below. Please share your working solution!!

input_select:
  evcc_mode_friendly:
    name: EVCC Modus
    icon: mdi:tune-variant
    #initial: "Off"
    options:
      - "Off"
      - "Full throttle!"

automation:
  - alias: xxx
    trigger:
      - platform: state
        entity_id: input_select.evcc_mode_friendly
    action:
      - service: input_select.select_option
        entity_id: input_select.evcc_mode
        option: >
          {% if is_state(trigger_state, 'Off') %}
            off
          {% elif is_state(trigger_state, 'Full throttle!') %}
            now
          {% else %}
            unknown
          {% endif %}

Gnah, I thought there will be an easier way than another automation. Thanks for your input!
Edit: I found a solution. I don’t know if its easier but it’s at least prettier than the MQTT topics in a drop down menu (in my opinion):
grafik
grafik
The Buttons will change their color according to the current state of the select-entity. When the Mode is off, the other buttons will be dark, in any other case, they will light up so that you can see that your charger is ready for operation.

I couldn’t get what I wanted with on-board lovelace cards and used a custom integration. If you’d like to recreate the dashboard, you’ve got to install the Custom Button Card Integration first - use HACS for your convenience.
Then I stacked a couple of buttons horizontally with the following code:

type: horizontal-stack
cards:
  - type: custom:button-card
    entity: select.evcc_mode
    name: Aus
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        entity_id: select.evcc_mode
        option: 'off'
    color_type: card
    icon: mdi:power
    styles:
      card:
        - height: 60px
        - width: 110px
    state:
      - value: 'off'
        color: yellow
  - type: custom:button-card
    entity: select.evcc_mode
    name: Solarstrom
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        entity_id: select.evcc_mode
        option: pv
    color_type: card
    icon: mdi:solar-power
    styles:
      card:
        - height: 60px
        - width: 110px
    state:
      - value: pv
        color: yellow
  - type: custom:button-card
    entity: select.evcc_mode
    name: Minimum
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        entity_id: select.evcc_mode
        option: minpv
    color_type: card
    icon: mdi:ev-station
    styles:
      card:
        - height: 60px
        - width: 110px
    state:
      - value: minpv
        color: yellow
  - type: custom:button-card
    entity: select.evcc_mode
    name: Netzstrom
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        entity_id: select.evcc_mode
        option: now
    color_type: card
    icon: mdi:power-plug
    styles:
      card:
        - height: 60px
        - width: 110px
    state:
      - value: now
        color: yellow

You could even beautify that more with a grid (I’m not yet lucky with the colors, does anyone know the standard “yellow” for the default dark skin? :thinking:):
grafik

square: false
type: grid
columns: 4
cards:
  - type: custom:button-card
    entity: select.evcc_mode
    name: Aus
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        entity_id: select.evcc_mode
        option: 'off'
    color_type: card
    icon: mdi:power
    styles:
      card:
        - height: 60px
        - width: 100px
    state:
      - value: 'off'
        color: chocolate
  - type: custom:button-card
    entity: select.evcc_mode
    name: Solarstrom
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        entity_id: select.evcc_mode
        option: pv
    color_type: card
    icon: mdi:solar-power
    styles:
      card:
        - height: 60px
        - width: 100px
    state:
      - value: pv
        color: chocolate
  - type: custom:button-card
    entity: select.evcc_mode
    name: Netzstrom
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        entity_id: select.evcc_mode
        option: now
    color_type: card
    icon: mdi:power-plug
    styles:
      card:
        - height: 60px
        - width: 100px
    state:
      - value: now
        color: chocolate
  - type: custom:button-card
    entity: input_boolean.laden_bis_80
    name: Stop 80%
    tap_action:
      action: toggle
    color_type: card
    styles:
      card:
        - height: 60px
        - width: 100px
    state:
      - value: 'on'
        color: chocolate
1 Like