I would like to generate a dynamic monthly report (ie since month start) based on various statistics on different measures like temperature, electricity consumption…
I cannot seem to get a decent way to create statistics on a defined period like the statistics-graph or statistic cards would do.
I have tried:
statistics helper, but it runs on fixed duration;
history_stats, but it’s only about duration or count of states, what I need is average, min, mix
SQL integration (advised by AI), but it cannot combine short-term and long-term data
Also, my recorder is kept on 14 days to keep my db size under control.
Has anyone achieved this?
My goal is to include these statistics in template sensors I could publish any way I want.
tbh I am not sure what you want to achieve, you seem to be happy with statistics-graph or similar… so what is this ‘report’ that you would like to see ? Small example of layout? The better you detail, the easier it is to answer
This third party integration can average over a defined period (e.g. current month or last month).
it hasn’t been updated in quite a while but there don’t appear to be any show stopping issues open.
You would have to adjust your recorder to keep state data for at least the length of time you want to average over as this integration uses state data that is purged after 10 days by default.
Assuming your sensor is set up appropriately to record statistics, you can use the recorder.get_statistics action to query the info you want. And the statistics are retained indefinitely, so it doesn’t matter what your history purge settings are.
To try it out, go to developer tools → actions, choose recorder.get_statistics, and fill out the appropriate info. In your case you’d choose your temperature sensor entity, period = month, and type = mean.
After you execute it, you can select “copy to clipboard as template” and then switch over to the template tab, and paste it there. Then you can play around with the template to get what you need.
A template like this (pasted into the template window after the action response) could get you started:
{% set temps = action_response.statistics['sensor.temperature'] | map(attribute='mean') | list %}
{% set diff = (temps[1]-temps[0])|round(1) %}
The average temperature this month is {{ temps[1]|round(1) }}°c, which is {{ diff|abs }}°c {{ 'warmer' if diff >= 0 else 'colder' }} than last month”
However, we can not use them in any card that requires actual entities, and that is what Id love to do.
Be able to check the current state of each of my panels in a nice UI, and not perse the graph. Update each 15 minutes or so, or, if that cant be done, use the system options for 5 minutes or 1 hour.
for that I suppose I need an SQL query and create the entities out of them some way or another. Maybe like above, with the response_variable and a template. Or, maybe a SQL sensor entity?
How can I go about creating that, I am not experienced at all using these queries, and find them hard to test in the UI.
hmm, cant make that work.
as a mater of fact, the statistics seem to have died upon me completely now, nothing is available in the statistics tool for the panels currently. Might be the login for them I need to check once more, SolarEdge is acting up…