Smart EVSE software EV-meter

Smart solar EV charging is fun and good for the energy transition, the hardware and software just work out of the ‘box’.

The integration in HA is a piece of cake with a a nice HACS integration.

One issue only: The charged energy is managed and measured, but not available for HA. The solution proposed by the SmartEVSE team is to install a separate EV meter. The data from this additional piece of hardware can be fed into the SmartEVSE system. This separate meter can be a formal requirement if you need accurate data for tax purposes or to bill your employer.

My solution is a free alternative for the EV meter, good enough if you just want to see and follow the data in and around your house.

All of this is achieved by creating 3 sensors:

First create a one or zero sensor indicating if your car is being charged:

- platform: template
    sensors:
      smartevse_charging_10:
        friendly_name: "Charging Yes or No"
        value_template: "{{ iif(is_state('sensor.smartevse_state_id', '2'), '1', '0') }}"
        unique_id: s10
        icon_template: mdi:battery-arrow-up-outline

This is needed because the charge current is available in the API/MQTT but retains it’s last value. So the power consumption is calculated as follows:

- platform: template
    sensors:
      smartevse_charge_power:
        friendly_name: "Charge power"
        unit_of_measurement: W
        value_template: "{{ ((states('sensor.smartevse_charge_current')|float) * (states('sensor.dsmr_reading_phase_voltage_l1')|float )  * (states('sensor.smartevse_charging_10')|float ) ) | round(0) }}"
        icon_template: mdi:ev-plug-type2
        unique_id: scp

Now the last sensor to convert the power to energy with the Riemann integration:

- platform: integration
    source: sensor.smartevse_charge_power
    name: smartevse_charge_energy
    unit_prefix: k
    unit_time: h
    round: 3
    method: left
    unique_id: sce

Just add the EV charged energy to your energy dashboard.

Screenshot 2024-08-06 at 10.44.47

Have fun

A bit of a starter question: when I copy this to configuration.yaml I get an error. So I guess this is supposed to be added somewhere else.
Where should I put this?
Thx

This should be part of your configuration.yaml or better create a subdirectory for all your (template) sensors. ref: Splitting up the configuration - Home Assistant

I have improved the setup by using the MQTT sensors and the calculation is now also working with3 phase solar charging:

#########################################################
#                                                       #
#         SMARTEVSE POWER & ENERGY SENSOR               #
#                                                       #
#########################################################      

- sensor:
  - unique_id: s10
    default_entity_id: sensor.smartevse_charging_10
    icon: mdi:battery-arrow-up-outline
    name: Charging 1/0
    state: '{{ iif(is_state(''sensor.smartevse_state'', ''Charging''), ''1'', ''0'')
      }}'

- sensor:
  - unique_id: scp
    name: Charge power
    icon: mdi:ev-plug-type2
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    state: >
      {{ (states('sensor.smartevse_chargecurrent') | float(0))
         * (states('sensor.dsmr_reading_phase_voltage_l1') | float(0))
         * (states('sensor.smartevse_nrofphases') | int(0))
         * iif(is_state('sensor.smartevse_state', 'Charging'), 1, 0) }}  

- sensor:
      - name: "SmartEVSE Energy Today"
        unique_id: smartevse_energy_today
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        state: >
          {% set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0) %}
          {% set current = states('sensor.smartevse_energy') | float(0) %}
          {% set midnight_value = state_attr('sensor.smartevse_energy_today', 'midnight_value') | float(current) %}
          {{ (current - midnight_value) | round(2) }}
        attributes:
          midnight_value: >
            {% if now().hour == 0 and now().minute < 5 %}
              {{ states('sensor.smartevse_energy') | float(0) }}
            {% else %}
              {{ state_attr('sensor.smartevse_energy_today', 'midnight_value') | float(0) }}
            {% endif %}  
    
#########################################################
#                                                       #
#            END OF CONFIGURATION FILE                  #
#                                                       #
#########################################################