EVSE Keba P30 integration

The enable command (ena X) should be used to permanently disable the system by using the parameter 0. After receiving ena 0 the device will be disabled until it is rebooted or ena 1 or currtime are used. The execution of ena 0 will take approximately 1 second. If ena 0 is used, then no other command should be sent for 2 seconds to ensure an undisturbed execution of the disable command.

I would not go with a solution to use ena for authentication.

Have you tried to use little-endian hex representation of the RFID tag in the home assistant keba config? E.g. 78 56 34 12 instead of 12 34 56 78? I remember that the RFID tag is stored differently than printed in the manual and on the card.

I had a look in the manual again: If I got it correctly the report 101-130 contain historical values which from my point of view do not make sense to push to home assistant (there is no support to store past values). However, report 100 is all zero in case of no active charging process and will be filled with starting parameters (including the RFID tag) once a session starts. So it should be possible to add a sensor(s) or attribute values in home assistant to hold the parameters of the active session (starting time, RFID tag, RFId class, …). If you have influxdb recording, you can calculate the individual energy consumption afterwards.

I have only used one card so far, thus had no need for this feature. Implementation should be straight forward. I might find some time in the next weeks.

This is also my understanding: 100 for current, 1xx for older.
I was looking at the history data, besides the current one, because I log the power consumption of all devices and have some statistics.
I know that I have the total power consumed already now, but then I have no time relation.
I need to have a deeper look at it, as soon as I can.

By the way, I have initialized 1 card as master (and put away for security reasons :slight_smile: ) and then 2 other cards. One that I use every day for charging and one for friends or neighbors that may need to charge when I am not there. My wallbox is installed in an underground garage where also other cars are parked.

I have made some progress and I would like to share my results.

The authentication settings, that proved to work with my wallbox (Vattenfall branded) and this integration are as follows:

Authorization: On

Online Authorization Mode: FirstLocal

Offline Authorization Mode: OfflineNoAuthorization

For me, the RFID number needs to be specified in the HA config file in the same way it is stored in the RFID card database of the wallbox. I have already commented in this thread how to inject a RFID card number into the database even without an integrated RFID card reader present.

Now about another quite interesting part:
Even with these setting, there was still a long delay in the wallbox response (up to 1-2s) or no reaction at all. I tracked it down to the WLAN connection in the end. The OCPP communication is, as far as I know, TCP, which might explain why this was working reliably. For the UDP only protocol there seems to be a quite high packet loss rate, if connected via WLAN. A bit of a disappointment, concerning the price of the wallbox and the fact that an access point is located just some 5m from the box.
I re-cabled the wallbox to use the LSA connector for a wired LAN connection and ever since, UDP is working perfectly with a nearly immediate response.

I still have the issue though, that using the keba.deauthorize service after a keba.authorize, the boxs shows “unknown card”. I will have to look into that later on.

For those interested, I still use the integration in parallel to the OCPP Home Assistant integration (from HACS). Works well and delivers some additional info like serial number and firmware version right now.

1 Like

Hi @stefankns

I’m in the same boat. Just got my Keba X-series without RFID. As you already found out, I made the same observation till now. Can’t test everything, because the Car is not arriving till at Monday :wink:
But could already test the authorization stuff.
Not sure if you got that already, but currently have with OnlyLocal and OfflineNoAuthorization and it works without “hacking” an specific RFID.
From my current observations, for me it looks like KEBA is adding every used RFID code into the Whitelist with Status unknown. With with my settings from above, it works with the default integration RFID no. without a problem. I think it should also work with other Authorization settings when the RFID no. Status is changed to accepted. So if the integration would allow to define at runtime the code it would even be possible to use multiple codes, even it probably only makes sense to differentiate the reason for authorization in automations vs. manual.
My goal is to just authorize when low tariff starts. And stop when the car has reached a defined SOC.

@dannerph
Maybe it would be nice to have the possibility to send custom RFID no. at runtime via the services and depending on the testing results without a RFID no. also. Would allow to use a specific RFID no. during automations and i.e. per person also a specific RFID no. when unlocked by hass from a user. With this it would be possible to track who did the authorization.

Hi @grandslam,
that should be possible. I will keep it in mind to add optional RFID codes in the service call to replace the default one when I have some time. But anyhow, feel free submit a PR to the home assistant core, the python library already supports this :slight_smile:

FYI: a good friend of mine will install a second keba wallbox soon. Thus I now have both motivation and a testing setup for multiple wallbox support.

2 Likes

Hi @dannerph ,

I have finally looked at your implementation (very good indeed!) and I have made some tests to retrieve the history data, but it is still not working as I expected.

In the meantime I have cleaned up my interface, adding some extra info from the wallbox and now it looks much nicer :slight_smile:


I think it would be nice to be able to use different keys to unlock the wallbox, beside the one in the configuration file.

As soon as I have a good idea on how to manage the history data I will ping you. But it could take a while. My job is not leaving me any free time in this period.

Cheers.

2 Likes

I changed to a more minimal UI (implemented with the picture-elements card). For inspiration:
grafik
grafik

The grey background changes to blue while charging, perfectly in line with the car.

grafik

Very nice indeed!
It is very clean and elegant… but I still prefer all the details… :wink:
By the way, what are the 7 liters of gasoline you have on your i3? :slight_smile:

Range extender :grimacing: the 60Ah battery (~18kWh usable) is enough to reach most destinations (>98% for me). For the remaining, I have the range extender.

Nice.

Can you share the code for your picture elements card?

sure, however there is nothing special, just using picture elements

Images

Code
type: picture-elements
elements:
  - type: image
    entity: binary_sensor.bmw_wallbox_charging_state
    image: /local/blank.png
    style:
      top: 50%
      left: 50%
      width: 100%
    state_image:
      'on': /local/bg_charging.png
  - type: image
    entity: binary_sensor.bmw_wallbox_plug
    image: /local/blank.png
    style:
      top: 50%
      left: 50%
      width: 100%
    state_image:
      'on': /local/wallbox_plugged.png
      'off': /local/wallbox_not_plugged.png
  - type: conditional
    conditions:
      - entity: lock.bmw_wallbox_authentication
        state: locked
    elements:
      - type: state-icon
        entity: lock.bmw_wallbox_authentication
        tap_action:
          action: call-service
          service: keba.authorize
        style:
          top: 12%
          left: 9%
  - type: conditional
    conditions:
      - entity: lock.bmw_wallbox_authentication
        state: unlocked
    elements:
      - type: state-icon
        entity: lock.bmw_wallbox_authentication
        tap_action:
          action: call-service
          service: keba.deauthorize
        style:
          top: 12%
          left: 9%
  - type: state-icon
    entity: sensor.bmw_wallbox_session_energy
    style:
      top: 81%
      left: 75%
  - type: state-label
    entity: sensor.bmw_wallbox_session_energy
    style:
      top: 91%
      left: 75%
  - type: state-icon
    entity: sensor.bmw_wallbox_max_current
    style:
      top: 81%
      left: 91%
  - type: state-label
    entity: sensor.bmw_wallbox_max_current
    style:
      top: 91%
      left: 91%
  - type: conditional
    conditions:
      - entity: binary_sensor.bmw_wallbox_charging_state
        state: 'on'
    elements:
      - type: state-icon
        entity: sensor.bmw_wallbox_charging_power
        style:
          top: 30%
          left: 51.5%
          '--paper-item-icon-color': white
      - type: state-label
        entity: sensor.bmw_wallbox_charging_power
        style:
          top: 40%
          left: 51.5%
          color: white
image: local/bg_not_charging.png
1 Like

Hello everyone;

I was wondering how precisely I can configure the maximum current used by the P30. Is it possible to set the current every 5 seconds to exactly match* the amount of returned power to the grid read from my P1 meter? Does it accept all values as floats, or maybe only ints, which would get me pretty far, or only a predefined set of values such as 8, 16, 22 etc.?

  • I obviously need to do some calculations and know the power factor, but that’s all doable.

Thanks in advance.

Hi vic,

Your interface are nice, can you give me more info how to get extra info from wallbox ?

I’m interesting !

Bernard

Hi @bernardp,

the extra info is already polled, so I have slightly modified the Keba binary sensor file to have extra attributes. Then I have defined sensors to show these attributes.
I am not the creator/owner of the binary sensor file though.

@dannerph is it OK to share the changes to the original file?

The templates are here…

sensors.yaml
  - platform: template
    sensors:
      ##
      ## Keba sensors
      ##
      keba_status_product:
        value_template: '{{ state_attr("binary_sensor.keba_p30_status", "product") }}'
        friendly_name: 'Wallbox type'
        icon_template: mdi:ev-station
      keba_status_up_time:
        value_template: '{{ state_attr("binary_sensor.keba_p30_status", "up_time") }}'
        friendly_name: 'Wallbox up-time'
        icon_template: mdi:clock-outline
      keba_status_serial:
        value_template: '{{ state_attr("binary_sensor.keba_p30_status", "serial") }}'
        friendly_name: 'Wallbox serial number'
        icon_template: mdi:pound
      keba_status_firmware:
        value_template: '{{ state_attr("binary_sensor.keba_p30_status", "firmware") }}'
        friendly_name: 'Wallbox firmware'
        icon_template: mdi:numeric
      keba_charging_state_status:
        value_template: '{{ state_attr("binary_sensor.keba_p30_charging_state", "status") }}'
        friendly_name: 'Wallbox state'
        icon_template: mdi:ev-station
      keba_charging_state_charging_rate:
        value_template: '{{ state_attr("binary_sensor.keba_p30_charging_state", "max_charging_rate") }}'
        friendly_name: 'Max charging rate'
        icon_template: mdi:percent-outline
        unit_of_measurement: '%'
      keba_plug_plugged_on_wallbox:
        value_template: '{{ state_attr("binary_sensor.keba_p30_plug", "plugged_on_wallbox") }}'
        friendly_name: 'Plugged on Wallbox'
        icon_template: mdi:ev-plug-type2
      keba_plug_plug_locked:
        value_template: '{{ state_attr("binary_sensor.keba_p30_plug", "plug_locked") }}'
        friendly_name: 'Plug locked'
        icon_template: mdi:lock
      keba_plug_plugged_on_ev:
        value_template: '{{ state_attr("binary_sensor.keba_p30_plug", "plugged_on_EV") }}'
        friendly_name: 'Plugged on EV'
        icon_template: mdi:ev-plug-type2
      keba_charging_power_power_factor:
        value_template: '{{ state_attr("sensor.keba_p30_charging_power", "power_factor") }}'
        friendly_name: 'Power factor'
        icon_template: mdi:percent-outline
        unit_of_measurement: '%'
      keba_charging_power_voltage_u1:
        value_template: '{{ state_attr("sensor.keba_p30_charging_power", "voltage_u1") }}'
        friendly_name: 'Voltage phase 1'
        icon_template: mdi:sine-wave
        unit_of_measurement: 'V'
      keba_charging_power_voltage_u2:
        value_template: '{{ state_attr("sensor.keba_p30_charging_power", "voltage_u2") }}'
        friendly_name: 'Voltage phase 2'
        icon_template: mdi:sine-wave
        unit_of_measurement: 'V'
      keba_charging_power_voltage_u3:
        value_template: '{{ state_attr("sensor.keba_p30_charging_power", "voltage_u3") }}'
        friendly_name: 'Voltage phase 3'
        icon_template: mdi:sine-wave
        unit_of_measurement: 'V'
      keba_charging_power_current_i1:
        value_template: '{{ state_attr("sensor.keba_p30_charging_power", "current_i1") }}'
        friendly_name: 'Current phase 1'
        icon_template: mdi:current-ac
        unit_of_measurement: 'A'
      keba_charging_power_current_i2:
        value_template: '{{ state_attr("sensor.keba_p30_charging_power", "current_i2") }}'
        friendly_name: 'Current phase 2'
        icon_template: mdi:current-ac
        unit_of_measurement: 'A'
      keba_charging_power_current_i3:
        value_template: '{{ state_attr("sensor.keba_p30_charging_power", "current_i3") }}'
        friendly_name: 'Current phase 3'
        icon_template: mdi:current-ac
        unit_of_measurement: 'A'
      keba_max_current_max_current_hw:
        value_template: '{{ state_attr("sensor.keba_p30_max_current", "max_current_hardware") }}'
        friendly_name: 'Max current HW'
        icon_template: mdi:current-ac
        unit_of_measurement: 'A'

and the cards are here…

card_1
type: vertical-stack
title: Wallbox
cards:
  - type: entities
    entities:
      - entity: sensor.keba_status_product
        name: Model
      - entity: sensor.keba_status_serial
        name: Serial number
      - entity: sensor.keba_status_firmware
        name: Software
      - entity: sensor.keba_status_up_time
        name: Up-time
      - entity: binary_sensor.keba_p30_status
        name: Link
  - type: entities
    entities:
      - entity: binary_sensor.keba_p30_charging_state
        name: Charging state
      - entity: sensor.keba_charging_state_status
      - entity: sensor.keba_charging_state_charging_rate
  - type: entities
    entities:
      - entity: binary_sensor.keba_p30_plug
        name: Power cable
      - entity: sensor.keba_plug_plugged_on_wallbox
      - entity: sensor.keba_plug_plugged_on_ev
      - entity: sensor.keba_plug_plug_locked
  - type: entities
    entities:
      - type: custom:text-input-row
        entity: input_text.keba_set_text_display
        name: Input text for LED display
card_2
type: vertical-stack
title: null
cards:
  - type: entities
    entities:
      - entity: sensor.keba_p30_total_energy
        name: Total energy charged
      - entity: sensor.keba_p30_session_energy
        name: Last session energy
      - entity: sensor.keba_p30_energy_target
        name: Energy target
  - type: entities
    entities:
      - type: custom:slider-entity-row
        entity: input_number.keba_set_max_current
        name: Set max current
      - entity: sensor.keba_p30_max_current
        name: Max current
      - entity: sensor.keba_max_current_max_current_hw
  - type: entities
    entities:
      - entity: sensor.keba_p30_charging_power
        name: Charging energy
  - type: horizontal-stack
    cards:
      - type: gauge
        entity: sensor.keba_charging_power_voltage_u1
        min: 0
        max: 255
        needle: true
        name: Phase 1
        severity:
          red: 0
          yellow: 200
          green: 220
      - type: gauge
        entity: sensor.keba_charging_power_voltage_u2
        min: 0
        max: 255
        needle: true
        name: Phase 2
        severity:
          red: 0
          yellow: 200
          green: 220
      - type: gauge
        entity: sensor.keba_charging_power_voltage_u3
        min: 0
        max: 255
        needle: true
        name: Phase 3
        severity:
          red: 0
          yellow: 200
          green: 220
  - type: horizontal-stack
    cards:
      - type: gauge
        entity: sensor.keba_charging_power_current_i1
        min: 0
        max: 16
        needle: true
        name: Phase 1
        severity:
          red: 0
          yellow: 5
          green: 11
      - type: gauge
        entity: sensor.keba_charging_power_current_i2
        min: 0
        max: 16
        needle: true
        name: Phase 2
        severity:
          red: 0
          yellow: 5
          green: 11
      - type: gauge
        entity: sensor.keba_charging_power_current_i3
        min: 0
        max: 16
        needle: true
        name: Phase 3
        severity:
          red: 0
          yellow: 5
          green: 11
  - type: custom:button-card
    entity: script.unlock_wallbox
    icon: mdi:lock
    size: 20%
    layout: icon_label
    label: |
      [[[ return 'Unlock Wallbox<br/>Key 1 - xxxxxxxx'; ]]]
    show_label: true
    show_name: false
    color_type: card
    styles:
      card:
        - background-color: rgb(255,255,255)
    state:
      - value: 'off'
        styles:
          icon:
            - color: rgb(255,0,0)
    confirmation:
      text: '[[[ return `Are you sure you want to unlock the Wallbox?` ]]]'
    lock:
      enabled: true
      exemptions:
        - username: xxxxxxxx
        - user: xxxxxxxx

Many thanks @vic

I will integrate it this weekend

I can see that there is some information about i and report 1 upd command

After if @dannerph can share the file this will help me too

Thanks again for your help

Hi @vic

I got time to intergrate your card, I adjust sensor template and removed data missing from keba driver.

It seems that there is a error on the max charging rate because it is not a pourcentage (there is as well a max charging rate poucentage on the UDP API) but it is a value in mA.

See Keba Doc :

image

See below new sensor definition (it seems that charging rate is Max curr)

 keba_charging_state_charging_rate:
    value_template: '{{ state_attr("binary_sensor.bmw_wallbox_charging_state", "max_charging_rate") }}'
    friendly_name: 'Max charging rate'
    icon_template: mdi:current-ac
    unit_of_measurement: 'A'

Thanks for sharing

sure, Home Assistant is open Source. Everyone is wellcome to share, improve and contribute to the code.

Hi @bobkersten,
I have an automation that sends new charging rates once a new meter reading is received. My meter updates every 3-4 seconds, so 5 seconds should work as well.

It should accecpt float values (will be parsed to int), however the communication between every wallbox and every car is limited to integer steps (6A - 63A). This is limited by the PWM “communication” over the charging cable. Depending on how many phases your car is charging, you can control between 1.38kW - 7.36 kW (single phase) and 4.14 kW - 22 kW (three phase). If you own an older VW/Skoda (two phase charging), it is somewhere in between (I observed that depending on the SoC either single or two-phase charging is used).

I was already thinking of integrating a new command so that power in kW could be set. By using the internal measurements of current it would be possible to identify the number of phases that are used to charge and using the measured voltage it would be possible to set a charging current as near as possible to the given charging power (maximum gap depending on the number of phases and in the range of ~230 W - 690 W).
What do you think, is that helpful? (Planning to do a re-design of the integration in near future anyhow)