Trying to get history stats for my ev charger per month


I am using HA since years now. currently I included my PV and EV stuff too. since I would like to track the energy consumption of my EV (paying from a different account), I had the idea of creating an new sensor giving me current months energy consumption delta from the historical stat. however I worked on this for a while and I am struggeling to get it working. here is what I have defined

  - platform: history_stats
    name: Monthly Power Consumption
    entity_id: sensor.goecharger_go_e_gemini_energy_total
    state: "total_increasing"
    type: count
    start: '{{ now().replace(day=1).replace(hour=0, minute=0, second=0).strftime("%Y-%m-%d %H:%M:%S") }}'
    end: '{{ (now().replace(day=1).replace(hour=0, minute=0, second=0) + timedelta(days=32)).strftime("%Y-%m-%d %H:%M:%S") }}'

The result is always 0. I am pretty sure that start and end condition will work like this, although the end date could be better calculated. about state and type I am uncertain here if the issue is coming from one of those.

if I check the entity in the developer options it gives me the following info

state_class: total_increasing
unit_of_measurement: kWh
device_class: energy
friendly_name: Total Charged

and state returns the current totally accumulated amout of energy consummed since the beginning.

Any help is very much apprechiated.


The history_stats sensor platform provides quick statistics about another integration or platforms, using data from the history integration.
It can track how long the integration has been in a specific state, in a custom time period.

That doesn’t sound like what you want. Your configuration is counting the number of times that the charger energy sensor state is “total_increasing”, which is never.

I think you want:

With that I will be able to do it for all future months. I was targeting a solution that would be able also to work with historical data. sure my example is for the current month, but with an alternative definition of the date to calculate all with (replace now() if some different startpoint. I could calculate it without a utility meter.
Any ideas on such an approach