I’d like to export specific sensor data as daily values in CSV-format in a file.
Following sequence:
first day in a month: rename old output file, crate a new one
daily write a number of sensor data based on previous day in CSV Format into file
e.g.
average daily outdoor temperature
max daily outdoor temperature
min daily outdoor temperature
…
It’s simple to remotely access the HA DB, create a few SQL-queries to get those numbers. But, I’d like to get it done based on HA mechanisms.
So far I tried different things like helpers, templates, etc.. Unfortunately, all those mechanisms seem, don’t look straight forward to accomplish those simple(?) things.
Is there a simple way available on HA, or should I stick to my remote DB access approach?
Data is a mix of a) data retrieved from a data logger via C# wrapped C library fed into Home Assistant via AppDaemon script b) Ecowitt wind sensor directly in Home Assistant
I use the fuzzy archer template (see ABOUT on website) which enables the real time gauges and graphs. Weewx plot/graph system generates the 24 hours, Week, Month, Year plots
Most Weewx skins have NOAA data generators which is probably closest to what you desire. I have mine linked in on the history page. I have history going back to 2015 - I used Weewx prior to Home Assistant but now Home Assistant is the master of the data and Weewx uses the MQTT subscriber driver to get data that Home Assistant publishes to MQTT.
The good part of this approach is that Weewx handles the weather data with no crafting of anything in Home Assistant except to publish to MQTT in a format ready for the Weewx MQTT subscriber driver to pull.
Extras?
Weewx schema can be adjusted so you can bake in any weather related data which is not in its usual schema
skins can generate any text and plots so the sky is the limit without what would be lots of automations in Home Assistant.
If you want to do this in native HA it is fairly straightforward. There is an action recorder.get_statistics that will retrieve whatever statistics data you are wanting. You can choose the date range, the period (e.g. day) and the statistics types (e.g. max, min, and mean).
If you go to settings → developer tools → actions, you can try it out and see what it does.
Then you can perform this action in an automation that is triggered daily, and use templates to format the output however you’d like.
To write to a file, first set up a file notification service (you can also use shell commands as a more advanced method). Go to settings → devices and services → add integration → search for “file” → choose “set up a notification service”
Once that is configured, you can use the action notify.send_message to that new action and it will add a line to that file.
For monthly renaming I’d probably use Shell commands.
this is really a very helpful and fast reacting community!
As I intend collecting various data items - not only weather data - Ricks and slimaks hints are the ones I was aiming for. I just tested the recorder.get_statistics feature; it works perfect.