EV Charger + Home Assistant via API (working example)

Hi all,

While we wait for GivTCP support for the EV charger, I’ve knocked together some config to get the EV charger working in Home Assistant via the cloud API. I will be publishing this in a proper video/article in a few weeks, but I figured it might be useful for other EV charger beta users too. These instructions assume you’re already familiar with Home Assistant and editing the configuration, if you’re not then you may be best off waiting for the proper guide.


Step 1:

  • Create an API key via the portal
  • Edit secrets.yaml
  • Add a line as follows and save:
givenergy_apikey: "Bearer YOUR_API_KEY"

Step 2:

  • Paste the below into configuration.yaml (or rearrange into your sections as required) and restart Home Assistant.
rest:
  - resource_template: 'https://api.givenergy.cloud/v1/ev-charger?page=1'
    scan_interval: 15
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"
    sensor:
      - name: "GivEnergy EV Status"
        unique_id: givenergy_ev_status
        value_template: '{{ value_json.data[0].status }}'
      - name: "GivEnergy EV UUID"
        unique_id: givenergy_ev_uuid
        value_template: '{{ value_json.data[0].uuid }}'

  - resource_template: 'https://api.givenergy.cloud/v1/ev-charger/{{ states("sensor.givenergy_ev_uuid") }}/meter-data?start_time={{ (utcnow() - timedelta( minutes = 1 )).strftime("%Y-%m-%dT%H:%M:%SZ") }}&end_time={{ utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") }}&measurands[]=13&meter_ids[]=0&page=1&pageSize=1'
    scan_interval: 60
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"
    sensor:
      - name: "GivEnergy EV Power"
        unique_id: givenergy_ev_power
        value_template: '{{ value_json.data[0].measurements[0].value }}'
        device_class: 'power'
        state_class: 'measurement'
        unit_of_measurement: 'kW'

  - resource_template: 'https://api.givenergy.cloud/v1/ev-charger/{{ states("sensor.givenergy_ev_uuid") }}/meter-data?start_time={{ (utcnow() - timedelta( minutes = 1 )).strftime("%Y-%m-%dT%H:%M:%SZ") }}&end_time={{ utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") }}&measurands[]=4&meter_ids[]=0&page=1&pageSize=1'
    scan_interval: 300
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"
    sensor:
      - name: "GivEnergy EV Energy"
        unique_id: givenergy_ev_energy
        value_template: '{{ value_json.data[0].measurements[0].value }}'
        device_class: 'energy'
        state_class: 'total_increasing'
        unit_of_measurement: 'Wh'
  - resource_template: 'https://api.givenergy.cloud/v1/ev-charger/{{ states("sensor.givenergy_ev_uuid") }}/commands/change-mode/'
    scan_interval: 15
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"
    sensor:
      - name: "GivEnergy EV Mode"
        unique_id: givenergy_ev_mode
        value_template: >-
            {% if value_json.data[0].active %}
              Eco+
            {% elif value_json.data[1].active %}
              Eco
            {% elif value_json.data[2].active %}
              Boost
            {% else %}
              Unknown
            {% endif %}
  - resource_template: 'https://api.givenergy.cloud/v1/ev-charger/{{ states("sensor.givenergy_ev_uuid") }}/commands/set-plug-and-go/'
    scan_interval: 15
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"
    binary_sensor:
      - name: "GivEnergy EV Plug And Go State"
        unique_id: givenergy_ev_plugandgo_state
        value_template: '{{ value_json.data.value }}'

rest_command:
  givenergy_ev_setmode:
    url: 'https://api.givenergy.cloud/v1/ev-charger/{{ states("sensor.givenergy_ev_uuid") }}/commands/change-mode'
    method: POST
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"
    payload: '{"mode": "{{ mode }}"}'
  givenergy_ev_setplugandgo:
    url: 'https://api.givenergy.cloud/v1/ev-charger/{{ states("sensor.givenergy_ev_uuid") }}/commands/set-plug-and-go/'
    method: POST
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"
    payload: '{"enabled": {{ enabled }}}'
  givenergy_ev_startcharge:
    url: 'https://api.givenergy.cloud/v1/ev-charger/{{ states("sensor.givenergy_ev_uuid") }}/commands/start-charge'
    method: POST
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"
  givenergy_ev_stopcharge:
    url: 'https://api.givenergy.cloud/v1/ev-charger/{{ states("sensor.givenergy_ev_uuid") }}/commands/stop-charge'
    method: POST
    headers:
      Authorization: !secret givenergy_apikey
      Accept: "application/json"
      Content-Type: "application/json"


switch:
  - platform: template
    switches:
      givenergy_ev_mode_eco:
        friendly_name: "GivEnergy EV Mode: Eco"
        value_template: "{{ is_state('sensor.givenergy_ev_mode', 'Eco') }}"
        turn_on:
          service: rest_command.givenergy_ev_setmode
          data:
            mode: Eco
        turn_off:
          service: rest_command.givenergy_ev_setmode
          data:
            mode: Eco
      givenergy_ev_mode_ecoplus:
        friendly_name: "GivEnergy EV Mode: Eco+"
        value_template: "{{ is_state('sensor.givenergy_ev_mode', 'Eco+') }}"
        turn_on:
          service: rest_command.givenergy_ev_setmode
          data:
            mode: SuperEco
        turn_off:
          service: rest_command.givenergy_ev_setmode
          data:
            mode: SuperEco
      givenergy_ev_mode_boost:
        friendly_name: "GivEnergy EV Mode: Boost"
        value_template: "{{ is_state('sensor.givenergy_ev_mode', 'Boost') }}"
        turn_on:
          service: rest_command.givenergy_ev_setmode
          data:
            mode: Boost
        turn_off:
          service: rest_command.givenergy_ev_setmode
          data:
            mode: Boost
      givenergy_ev_plugandgo:
        friendly_name: "GivEnergy EV Plug&Go"
        value_template: "{{ is_state('binary_sensor.givenergy_ev_plug_and_go_state', 'on') }}"
        turn_on:
          service: rest_command.givenergy_ev_setplugandgo
          data:
            enabled: "true"
        turn_off:
          service: rest_command.givenergy_ev_setplugandgo
          data:
            enabled: "false"
      givenergy_ev_chargingstopstart:
        friendly_name: "GivEnergy EV Charging Stop/Start"
        value_template: "{{ is_state('sensor.givenergy_ev_status', 'Charging') }}"
        turn_on:
          service: rest_command.givenergy_ev_startcharge
          data: {}
        turn_off:
          service: rest_command.givenergy_ev_stopcharge
          data: {}

template:
  binary_sensor:
    - name: "GivEnergy EV Charger Connected"
      state: >-
        {% if is_state('sensor.givenergy_ev_status','Preparing') %}true
        {%  elif is_state('sensor.givenergy_ev_status','Charging') %}true
        {%  elif is_state('sensor.givenergy_ev_status','SuspendedEVSE') %}true
        {%  elif is_state('sensor.givenergy_ev_status','SuspendedEV') %}true
        {%  elif is_state('sensor.givenergy_ev_status','Finishing') %}true
        {% endif %}

Step 3:

  • Create an entities card with all of the following controls on:
type: entities
entities:
  - entity: switch.givenergy_ev_plugandgo
  - entity: binary_sensor.givenergy_ev_plug_and_go_state
  - entity: switch.givenergy_ev_mode_ecoplus
  - entity: switch.givenergy_ev_mode_eco
  - entity: switch.givenergy_ev_mode_boost
  - entity: sensor.givenergy_ev_mode
  - entity: sensor.givenergy_ev_status
  - entity: binary_sensor.givenergy_ev_charger_connected
  - entity: switch.givenergy_ev_chargingstopstart
  - entity: sensor.givenergy_ev_energy
3 Likes

Works perfectly, thanks! For completeness ‘max charge current’ would be useful long term, although I suspect I’d only use if solar charging and wanted to minimise battery drain and doubt I’ll be doing that anytime soon :laughing:.

I’m sure GivTCP /official battery integration will be complete by then.

Thanks. Yes, the sliders would be good, however that would also require an automation to be created to manage the link between it, the real value, and the control of the value, rather than just template sensors/controls that these ones use. I went for simplicity to start with but might add the others soon.

1 Like

Looks great, I’m just installing my EVC today so hopefully can start GivTCP development shortly!

Just need to get it on the Wi-Fi, it’s not playing ball atm!

1 Like

Early good news, POC code reads data from EVC and preps for MQTT publish into HA. Control is next!

1 Like

That is good news :) are you able to auto detect it on the LAN or will people need to go searching for the IP? It doesn’t show up with an obvious name when you network scan at the moment so I reckon people might struggle finding the IP if they’re not that technical.

Just seen your latest dev push with EVC included. Doesn’t work for me at the moment, gives me this error which is probably a typo in your code?

    if GiV_Settings.first_run_evc:        # 09-July-23 - HA is seperated to seperate if check.
AttributeError: type object 'GiV_Settings' has no attribute 'first_run_evc'. Did you mean: 'first_run'?

Oh yeah, 2.3.44 has sorted that thanks :) got loads of stuff in there now! It’s brilliant, but it has ruined my video idea :)

Yeah, still a WIP getting it into GivTCP with startup etc…

No auto discovery yet. Need to get info from GE on MAC addresses etc…

Does it work for you? My .44 is not running!

1 Like

When using ethernet you should be aware that the WiFi is still on-line and connected. You’ll probably need to detect if ethernet is being used and prefer that MAC address over the other. The Wifi MACs seem to start with 94:C9:60 (hopefully that matches yours too?) and my ethernet one starts with 04:05:32, but I’ve no others to compare that against.

It’s running, working fine for the AIO and pulled in entities for the charger. No idea if the charger entities work yet because the car isn’t plugged in.

It’s seeing the voltage changes in the L1 voltage entity so I’d say it’s working

It picked my charge up last night on all the expected entities as well - looking good so far

3 Likes

@SpeakToTheGeek, Before I spend hours probably not achieving much :laughing:, do you have an example of how to control the front LEDs on/off via HA? Thanks

Yup, check out the updated configuration here: GivEnergy EV Charger and Home Assistant using the Cloud API « Speak to the Geek

1 Like