I created this template sensor to get an estimate of my car charging energy.
Looking at past data, the charging basically instantly goes to 11kW so can just use that as a base.
Basically, every 10 minutes while charging, return 10 minutes worth of kWh.
When charging stops, get the minutes from last 10 minute block if >0, and return that as kWh.
Looking at a blog post about total_increasing when it was added, I got the impression HA would know how to accumulate the data itself, but the data looks like this:
So if I need to calculate accumulation myself, how do I get a previous value?
Also, if a template sensor runs at for example 00:00:00, will the accumulated energy get assigned to 00-01, or previous day 23-00? Is there some way to achieve the latter?
I can’t isolate the energy or power of car charging, which is why I’m trying to do this as a stopgap until I can upgrade to a charger with built in metering.
I just could not find info on what should this type of sensor actually return.
Instead of having one simple out of the box supported template sensor, i don’t want to install extra stuff to accomplish the same, even if it would be “more correct”.
Nope. The state class total_increasing is only used to tell the energy dashboard what to do if the value decreases (it is treated as a reset). It has nothing to do with making the sensor accumulate.
I checked the data the sensor as in the first post generated for energy dashboard, and it’s missing one “tick”.
Exported data from the graph, and it shows:
00:00:00 → 0 , this is when charging started
00:10:00 → 1.83… , first 10 minute tick of 11kW
00:20:21 → 0.0 , looks like this is the first if branch due to the decimal
So why is there no 00:20:00 event from the second trigger, that would’ve added another 1.83kWh?
Can template sensor triggers get merged?, due to not getting a cron trigger in the template, the sensor lost 1.83kWh of energy.
Edit:
Or does this mean the value stayed the “same” at 00:20:00, and changed to 0.0 at 00:20:21?
That means the energy dashboard doesn’t understand this as is, and at least during charging i should return a sum that includes previous values, unless there’s some other setting i can change that indicates the sensor just ticks values, that can be the same as previous
Did not find a solution to the original problem, if the sensor reports in kWh twice with the same value, it doesn’t get summed up as it seems HA thinks there was no change.
Ended up adding a template sensor that outputs 11000 W during charging and 0W otherwise and adding an integral helper on that to get the actual energy estimate.