CJNE / ha-myenergi

Home Assistant integration for MyEnergi devices
MIT License
150 stars 33 forks source link

Calculating daily charge requirements and daily driving costs #518

Closed dunxd closed 7 months ago

dunxd commented 7 months ago

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

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: Zappi Charge Cost

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.

I posted this in the HA Community, but I have no idea if that will get the attention of anyone using, or working on, this integration so reposting here.

G6EJD commented 7 months ago

Why is it an issue? A comment/discussion would have been more appropriate.

dunxd commented 7 months ago

Fair enough. Reposted to the discussion.