I’ve got a series of sensors on my PV inverter (MQTT inputs, basically) that output a cumulative value for energy in kWh (i.e. PV energy generated, power from the grid, battery power out, etc.). HA sees these entities and is able to plot historical data when I view the entity:
What I’d like to do is use ApexCharts to build a 14 day graph of stacked bar charts that show where my power came from for the day (PV, battery, grid). What I can’t figure out how to do is to have each day be represented by the data for that sensor only for that specific day. Essentially for any given day, the graphed value should be - . As it stands, each stacked bar in my graph just represents the cumulative value for that sensor at the end of day, so it just keeps getting bigger and bigger. I’ve looked into the data_generator option, which seems like what I need to do here, but I don’t know how to figure out where those values in the historical graph are coming from. Is this exposed anywhere in the UI?
For purposes of discussion, here’s a screenshot and my YAML (so far) for the graph:
Assuming your sensor has already data for more than one day:
Here is an example from me and it works.
I use daily sensors that reset each day. Maybe that is the issue, or using max I stead of last as function?
I like your thinking, but switching the function type doesn’t seem to give me a time slice.
As I understand it your sensors reset each day, whereas mine are just a cumulative value from the beginning of time. I’d need to write a function that is able to take a 24-hour slice of that stream and subtract <day_start_value> from <day_end_value> to get the total for the day. I’m assuming it’s possible given that there is a historical chart in HA for the entity values, just not sure how to go about accessing those and/or wrapping that up into a chart.
You should probably just use a different sensor that outputs your “realtime” kWh usage, not the cumulative lifetime one, and use “add” instead of “last” to get a total for each 24h period. I don’t think the cumulative sensor is the way to go here as it’s more complex to break out each day.
Sadly, that’s the only sensor I have. HOWEVER, I just read about the Utility Meter template which will give me the time slices into the entities of type total_increasing I’m looking for. So far it seems to be working.