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

Could you elaborate a bit more on your use case and the issue?
By the way, it updates every minute + immediately when a condition becomes true/false.

I have a binary sensor ā€œBrühvorgang aktivā€ which switches to ā€œonā€ once the brewing process starts. I’d like to create a shot timer, that basically counts up the seconds for this process and display it in a browser-mod popup (i have a tablet positioned right next to the coffee machine, running HA + wallpanel).
After the brewing process is stopped, I would want to reset the timer to 0. It’s obviously important to not have a big delay for when the timer starts but also have the ability to show the timer itself on a realtime basis to make this use case work.

This thread https://community.home-assistant.io/t/stopwatch-with-start-stop-resume-lap-and-reset/443994?u=juergenjw might help.

MeasureIt it not really made for this usecase with live counting. It might be as simple as changing the update interval, but I’m not sure of the side effects. Better go with a regular timer like @juergenjw mentioned.

Thanks for pointing me to that other thread! Haven’t found that one before, might consider implementing that.

@danieldotnl

I’m still wondering how to edit the template for a MeasureIt counter

Someone else raised an issue on Github for this topic recently:

It would be great to be able to edit the template not only for timers but as well for counters.

Why I can’t create measureit time sensor?

Here is configuration:




I’m just not sure what it would mean to edit a sensor template. You suddenly measure different things and the history of your sensor doesn’t make sense anymore. Why wouldn’t you just create a new one then?

You let me guess without providing the logs, but I think the reason is that timestamp_custom outputs a string that cannot be interpreted anymore by the device class and UoM.

@danieldotnl, thanks a lot for picking this up :slight_smile:

for me there are several reasons, e.g.

  • for a long time, I was identifying runs of my (old) dishwasher based on its power consumption profile, now I got a new dishwasher which provides an API that allows to identify the end of a run by a sensor.
  • for quite some time I used a simple door-sensor to count openings of my physical mailbox, now I want to use a combination of sensors to be more sure that mail has arrived. Hence I want to change the template of the MeasureIT sensor to consider the combined sensors.
  • I am counting ā€œsunny daysā€ based on a condition taking illuminance into consideration, but now I want to change the lux threshold.

Of course, I could create new MeasureIT sensors, use the calibration service to set the former values, … and I would loose history

For the future I could consider creating a template sensor which I pass to MeasureIT as the template condition, and if I want to adjust I would re-configure the template sensor.

Since I am a big fan of MeasureIt (and advertising it here and there) I was hoping for the option to edit the template of a MeasureIT counter.

1 Like

Hi guys,
I’ve been trying to figure something out all day and it’s doing my head in. I hope someone can help.

Yes I’m a noob!

I have 2 sensors already set up, one to measure anything below 4
{{ states(ā€˜sensor.sophia11032014_glucose_value’) | float < 4 }}

And another to select anything above 7
{{ states(ā€˜sensor.sophia11032014_glucose_value’) | float > 7 }}

What I can’t figure out is how to select all values between 4 and 7

Is anyone able to help me please before I go completely crazy :rofl:

try it this solution in your templet editor first

Here’s the simplest Jinja2 template that will return true when the glucose value is between 4 and 7 (inclusive), and false otherwise:

{{ 4 <= states('sensor.sophia11032014_glucose_value') | float <= 7 }}

Usage examples:

  1. As a binary sensor:
binary_sensor:
  - platform: template
    sensors:
      glucose_in_range:
        value_template: "{{ 4 <= states('sensor.sophia11032014_glucose_value') | float <= 7 }}"
  1. In an automation condition:
condition: "{{ 4 <= states('sensor.sophia11032014_glucose_value') | float <= 7 }}"
  1. As a template sensor state:
template:
  - sensor:
      - name: "Glucose In Normal Range"
        state: "{{ 4 <= states('sensor.sophia11032014_glucose_value') | float <= 7 }}"

This template will evaluate to true when the value is ≄4 and ≤7, and false for any other values.

2 Likes

You are a star!
I could kiss you right now😘

condition: ā€œ{{ 4 <= states(ā€˜sensor.sophia11032014_glucose_value’) | float <= 7 }}ā€

This is exactly what I was looking for.

Thank you so much steve

1 Like

Hi there!

This looks like it’s exactly what I need, but I’m a bit lost on the value template part.

I am trying to make a counter that logs duration (hours) that the hot water system is on. I have a sensor that measures it the power draw of the hot water circuit in W. (When on, it’s typically around 1700W or so).

I’ve set up MeasureIt to read time, with the condition as:
{{ states('sensor.ctmeter_ch6_hws_power') | float(0) > 1000 }}

Sensor
name: hours
value template: ???
unit of measurement: h
device class: duration
state class: total

The main question is - what is the value template? I didn’t spot any examples in this thread, and searching HA comes up with no results.

The value_template configuration variable is optional and is used to modify the output of sensor.

In your case, the value_template will be a mathematical expression to convert the number of seconds returned by the Time option into you desired output of hours.

{{ value / 3600 }}

MeasureIt doc - notes on value precision

Thanks for that. It really didn’t seem intuitive.

It turns out that I didn’t need to set a value template, and my hot water sensor is working as it should. I think that’s because I set measure it to report hours.
I’m now trying to figure out how to get a daily maximum that can be its own history graph, summarising each day in to n hours of use.

At present, the measureIt counter will tell me the current amount of hours (determined by when the HWS is drawing 1000W or more). It would be useful to see the total hours per day plotted as a bar chart over time.

And whoever said that AI is poisoned by a load of old answers and broken ā€œdoes this workā€ type scenarios because it puts out some crazy suggestions.