Myenergi Zappi calculating daily charge requirements and daily driving costs

I want to have Home Assistant display how much I typically charge my car each day in kWh, as this will help me set my Zappi schedules more accurately to take advantage of the best rates. I am using the myenergi integration from HACS.

Here is where I have got so far:

Energy used each day

  • Create a template sensor to capture the final measure of sensor.zappi_energy_used_today
  • Create statistics sensors to calculate the mean and median of that value over 28 days

Here is my YAML:

template:
  - trigger:
    - platform: time
      at: "23:59:55"
  sensor:
    - name: "Daily Car Charge (max)"
       unique_id: "daily_car_charge_max"
       state: >
         {{ states('sensor.zappi_energy_used_today') }}
       state_class: measurement
       unit of measurement: "kWh"
sensor:
  - platform: statistics
    name: "Daily Car Charge (mean over 28 days)"
    unique_id: daily_car_charge_mean
    entity_id: sensor.daily_car_charge_max
    state_characteristic: mean
    sampling_size: 28
    max_age:
      days: 28
  - platform: statistics
    name: "Daily Car Charge (median over 28 days)"
    unique_id: daily_car_charge_median
    entity_id: sensor.daily_car_charge_max
    state_characteristic: median
    sampling_size: 28
    max_age:
      days: 28

Daily cost with variable energy cost
I am also trying to calculate how much I am spending on charging my car each day which complicated since I am on the Octopus Agile tarrif which has a different cost per kWh every 30 minutes. This means that I need to see how much I am charging my car every 30 minutes and multiply that by the rate at that time. I’m not sure the best sensor to use for this - I have opted to go for sensor.myenergi_home_power_charging but I suspect this wouldn’t work if I was using other myenergi products. I created a template helper to do the calculation with the following State template:

{{
  (states('sensor.octopus_energy_agile_current_rate') | float )
  *
  ((states('sensor.myenergi_home_power_charging') | float)/1000)
}}

That gets the cost at different times through the day like this:

I am still trying to figure out how to total this up each day so I can capture the daily total and start getting some interesting statistics about how much it costs me to drive each day/week/month/year. Perhaps a Reiman Sum Integral?

I’d love to hear if anyone else is working on this, or already has it nailed.

Also posted as a discussion in the Myenergi Integration github repo.