danieldotnl / ha-measureit

Measure anything in Home Assistant based on time and conditions.
MIT License
151 stars 7 forks source link

Add a Service: Increment Counter #125

Open nicknol opened 6 months ago

nicknol commented 6 months ago

Checklist

Is your feature request related to a problem? Please describe.

no problem - just a new feature

Describe the solution you'd like

A service that would increase a MeasureIt counter

Describe alternatives you've considered

At the moment a counter is increased when a status change happens. Which works!!

But in some cases I only have an automation that detects something countable, e.g. the power consumption of my coffee machine drops below a specified value, and that means one more cup of coffee has been brewed. Currently, the automation turns an input_boolean to on, waits for 5 seconds, and turns it off again. and MeasureIt counts the status change.

Additional context

And it's not only my coffee machine ;) I use a similar approach for my dish washer, my dryer, ...

danieldotnl commented 6 months ago

Not saying this is not a good idea, but can't you do something like this in MeasureIt, instead of having an automation and input_boolean in between?

{{ states('sensor.my_coffee_machine_power') | float < 10 and now() - states.sensor.my_coffee_machine_power.last_changed > timedelta(seconds=5) }}

nicknol commented 6 months ago

thanks a lot for your suggestion. but, well, it's not that easy. the power consumption for brewing a coffee, just rinsing, or doing maintenance would trigger the mentioned template and count coffees not being brewed. Not do speak about the power consumption profiles of a dish washer, a dryer or a washing machine.

=>There are blueprints around for the detection of appliances being running or having finished.