I would like to track the consumption of bottled water manually. The idea is to put a button next to the water storage and you press that button when you take a fresh bottle from the storage.
In the end I would like to have pretty statistics like on the energy dashboard: bottles per day, summed up over the weeks, monthly overview, averages, etc.
I am fine with the hardware: there is a Zigbee button firing events. But how does it go in from there? I could define a counter helper and an automation increasing it on each press.
Maybe I am missing something obvious here.
How would you set it up? And how do I get the visualization?
Thanks for your answer. I also saw that but I thought that the statistics card is only usable on sensors.
I do not have a sensor from my button presses, only a helper. Or am I missing something?
That also looks interesting. Then I would not need a helper counter and a triggered template sensor but just your special sensor instead.
An automation to run when the button is pressed and it updates the sensor. Sounds doable, I will give it a try.
Thank you.
No, all you need is a trigger-based template sensor. Nothing else. The state of that sensor would be the count of bottles of water. Something like this:
If you want monthly/yearly/etc. counts, you can create utility meter helpers (either in YAML or through the UI) and have them reset at whatever interval you want.
Every time the sensor is triggered, its last_changed and last_updated properties will update (just like any other entity in HA).
You can access those properties in a template like this:
{{ states['sensor.water_bottle_count']['last_changed'] }}
or
{{ states.sensor.water_bottle_count.last_changed }}
The easy way, without code changes and only from the UI, would be to go to developer tools → states, then filter for your entity and click it, and you can set it to 0 (or to any value you desire).
Another option is to add a custom event as another trigger, and change your template to handle that other trigger differently. Then you can fire that custom event along with event data that has the value you want to set the entity to. If you want to reset this sensor from a script or automation, this would be the way to do it. But also keep in mind if you have utility meter entities based off this sensor, those can already be set to any value with a service call.