MeasureIt: Measure all you need based on time and templates!

Please have some patience. I’m currently rewriting this integration to solve some issues and add some features. It got popular faster than expected :slightly_smiling_face:

One of the issues is that the device_class is hard-coded for time sensors, which interferes with the units you want to use for measurements.,

1 Like

I’m not sure that is a good use case for this integration. If you would have a total production sensor, you could use that one as a source, and measure per day/week/month. Sound like you are now trying to create that total number with measureit, but I guess wattage is all over the place with the sun coming and going and clouds in front of it.
I can only think of negative values if you start measuring while your panels are producing and after a while production decreases. MeasureIt would measure the difference between those moments. But once your reset at midnight, this shouldn’t occur anymore.

1 Like

In Germany there are some youtubers that have made it popular :sunglasses:

Can someone provide a sample of using it for counting times sensor is in on? i.e number of times a door is opened or lights are switched on. I am having problems getting it to count. thanks

3 Likes

I have MeasureIT set up to measure the number of seconds each day that the thermostat is calling for heat.

How can I save that data to be able to look back at earlier date’s totals?

Thank you.

:partying_face: Relauching MeasureIt! :partying_face:

It took some time but here you have a brand new MeasureIt. And I heard you! It contains:

  • a counter sensor :raised_hands:. Count each time a template evaluates to True! E.g. {{ is_state('binary_sensor.front_door', 'on') }}
  • a reset service that can reset any sensor, now or at a future datetime
  • sensors that do not reset (automatically, but you can reset them with the reset service)
  • source sensors now update immediately when the source entity updates
  • the issues with the sensors sometimes resetting at UTC midnight has been fixed.
  • fixed issue with device_class and state_class that did not respect what you configured.
  • lots of automated tests

I think all of this deserves a version jump to 0.5.x!

A lot changed and have been rewritten but I tried to support your existing configurations as good as possible! If you still do encounter issues with those, please delete it a create a new config entry.
If you have sensors that were affected by the UTC reset time bug, you can set the correct datetime with the new reset service.

Documentation has been updated as well, so please re-read the README on github. (or the updated first post of this thread)

Last but not least, please share your use cases in this thread, so I can summarize them every now and then, in the first post to inspire other people!

2 Likes

v0.6.0

You can now choose a sensor that will reset after each measuring session. E.g. when you want to measure some device that is running multiple times per day.

An issue with daylight savings time is fixed which caused the monthly pattern to finish 1 hour too early. Please fix your existing configurations manually with the reset service.
Thank you @misa1515 for providing Slovakian translations!

Changes

2 Likes

Hi all

I have defined a day sensor and it looks like this

if I use it in a card without templating, I see like this

Screenshot 2024-03-17 162748

How can I show it as HH:MM ?

Thanks

First of all, Your unit_of_measurement should be s. Then, together with the device_class: duration, Home Assistant will automatically format the duration, usually in HH:MM:SS.
If that’s not desired, please check the FAQ in the readme.

1 Like

Thanks!
If I want to create also a weekly and monlthly sensor, it will also convert in a relative format, showing also days ?

Yes, I believe it does! I’m hoping for some more configuration options in the frontend soon, as I feel formatting durations is quite messy at the moment. The number of questions about it on the forum is significant.

The best thing in my opinion is to format in a frontend card. E.g. I’m using a mushroom chip template card to format tv time:

- type: custom:mushroom-chips-card
    chips:
      - type: template
        icon: mdi:eye-circle
        content: >-
          Today - {{ '%2d:%02d' % ((states('sensor.tvtime_day')|int/3600)|int,
          (states('sensor.tvtime_day')|int%3600)/60) }} hour

image

1 Like

Is it possible to start the counting when the condition is ‘> 3’ and not a fixed value?

{{ is_state('sensor.psa_charge_rate', '> 3') }}

Sure: {{ states('sensor.psa_charge_rate') | float > 3 }}
Note that if this is the template for a counter sensor, it will only count when the value becomes higher than 3 and not after that when the value changes but is still higher than 3.
The template should first become False before it will be counted again.

1 Like

Nice work, @danieldotnl! Very useful integration.

Is there a built-in way to measure cycle times with this integration? Some duration examples:

  • refrigerator compressor
  • clothes dryer
  • irrigation zone
  • septic/sump pump

I think you could do it with a regular duration sensor that resets each time the monitored sensor switches from off to on, but I’m wondering if there’s a simpler way.

In the latest release you can choose for a reset period ‘after each session’. So it would reset each time the conditions become false. Would that be what you are looking for?

v0.7.0

For source meter configurations: source entities that reset can now still be tracked if they have state_class total_increasing.
As an example: we can now measure the precipitation per hour/day/week/month etc. based on a source sensor that resets every day.

Changes

  • Support source entities that reset with state class total_increasing @danieldotnl (#104)
  • Make sure we are compatible with HA core change regarding event filters in 2024.4 @danieldotnl (#109)
  • Add translatable icons @danieldotnl (#110)
  • Update dependency pytest-homeassistant-custom-component to v0.13.109 @renovate (#108)
  • Update dependency ruff to v0.3.4 @renovate (#107)

I’m glad having found MeasureIt ! :slight_smile:

till now I was using history_stats which has some drawbacks especially in regards to the recorder.
Question for you @danieldotnl: how could I initialize/set a measureIt counter with the value I’m currently having?
e.g. I counted the number of coffees my coffee machine has brewed, and each 400 cups I need to perform a maintenance. If my new coffee counter (based on measureIt) would start at 0 I would miss the right time for the maintenance.

I’m glad having found MeasureIt ! :slight_smile:

till now I was using history_stats which has some drawbacks especially in regards to the recorder.

Happy to hear that, and spread the word! :slight_smile:

Question for you @danieldotnl: how could I initialize/set a measureIt counter with the value I’m currently having?

That’s not yet possible. Could you please create a feature request at github? Thanks!

What you could do for now is to add the current number of cups in the value_template of the sensor, like: (value | int) + 102.
Once you clean it and reset the sensor, you should then also update the value_template.

@danieldotnl Thanks a lot for the fast reply.

Unfortunately I can’t figure out where to edit the existing template. Please have a look at the screenshots below.

grafik
Edit the main configuration shows the template as empty:

Edit a sensor configuration adding the value template leads to an “unknown error”
grafik

Seems like a bug. I’ll need to dive into the unknown error…