#tracking values over a week and saving to csv.

1 messages · Page 1 of 1 (latest)

wispy elm
#

hey all, so I've had a month or two with home assistant now and loving every minute of it. One of my automations is a pair of reminders to take my meds morning/night and a barcode I scan when I've done it. I get a reminder to my phone if I forget.

I've been on a health kick lately so would like to do something similar with my drinking. I do like a beer and have some daily. but I'd like to track my consumption over a week and then at the end of week save that total to a csv file for long term tracking. I figure a button near the fridge could be used to record intake.

So:
a) is there a way to setup a week's worth of integers so the automation can track against the day of week?
b) is there a way to save to a local csv file on home assistant and (ideally) have a button to download it locally or graph it?
thanks

tender basalt
#

Why don't you want to graph it in home assistant? The long term statistics https://data.home-assistant.io/docs/statistics/ will save the records forever

Home Assistant has support for both short- and long-term statistics. For short-term statistics a snapshot is taken every 5 minutes. It keeps track of supported entities and different elements of the entity state. For long-term statistics, an hourly aggregate is stored of the short-term statistics. Currently two types of entities are differentiat...

wispy elm
#

I did not know that was a thing....will look into it.

silver talon
#

You could just make a counter helper and increment it with a button on a dashboard. It would increment forever and never reset, but if you want to know how many beers you had per day/week/month/etc you can see that with its statistics

wispy elm
silver talon
#

You will have the states history (timestamp of change and value it changed to) for as long as you save your recorder history (default 10 days). But what I was suggesting is that the important part is that it will generate statistics that will be stored indefinitely, like the link Spiegelmann shared

wispy elm
#

ok, I guess I've got some homework to do

silver talon
#

That gives you an hourly snapshot of what the total was of the counter. And the “statistics graph card” on your dashboard can use that data to show hourly/daily/etc results. For any time period.

#

Ack. Looks like I was wrong about counters, they don’t get statistics generated.

#

You can just create a template sensor that mirrors that state of the counter, and has a state class of total so that it generates the correct statistics

wispy elm
#

well, I just tried it. I can see a graph of changes over time, so...hmm...maybe?

The only thing from there is I'd like to have a daily/weekly limit and show a countdown, as that motivates me to cut back overall...

Anyway, thanks for the advice. I'll do some research/experiments

silver talon
#

You can also feed the template sensor into a utility meter that resets weekly if you want its state to be only for that week

#

Other options: create a trigger-based template sensor to handle everything with a single entity. You can have it reset whenever you want, you can have it generate the statistics you want, etc.