Stopwatch with start/stop/resume, lap and reset

Have you tried to press “Reset” button? It should reset its state to “00:00:00”, as is stated here:

    sensor:
      - name: "Stopwatch"
        state: >-
          {% if is_state('input_boolean.reset_stopwatch','on') %}
              {{ '00:00:00' }}
...

No i did not. And that of course worked…

Thank you so much! :slight_smile:

Great to hear that!

I’m adding it to the initial post.

Thanks very much for this. I’ve been looking for a way to create a job-timer thing with a physical button and whilst I can sort the electronic and Tasmota side out, I was struggling with how to do it in HA. This does the trick and I shall have fun integrating it. - All the best! :slight_smile:

1 Like

Great to read this!
Thank you!

hello, and thank you for this work. I was looking for a timer to start work, be able to take breaks and finally stop. the goal was to count the working time over the day…
I’m a little new to HA and I would like to be able to switch the daily data into influxdb (I already have an HA database in there with consumption reports for example). And also know if once transferred to influx the HA database can be cleaned? in any case, the timer and what I was looking for!

I cannot help you here. I’m not expert in dababase and I don’t know anything about influxdb. I don’t know if anybody else can help you, or you can try creating a new topic about your question in configuration thread, as this is not directly related with the stopwatch, but with database management.

Awesome addition thanks.

I use it to time how long water is flowing through taps at my home.

When stopping my stopwatch it doubles the result. Any idea what can cause that?

1 Like

Hello,
Thank you!

I have found no reason for doubling the result when stopping it … It’s strange.

I saw the same issue on the first releases in September. It seems to be fixed in the latest release. (2023.9.3)

The button.start doesn’t seem to be available? What am I doing wrong? The reset button works but the start button is not available.


2023.10.1

somehow the display in lovelace is not updated, i have to refresh the page, any ideas why?

Check if you have entity button.stop_pause available and if so, change in the card button.start to button.stop_pause.

I think the rule of the button name assignation has changed in last versions of HA.

I really don’t know. In my browser (Google Chrome and the Android Companion app) it refreshes well.

No, it’s not available. I do have sensor.stopwatch though.

Ok, found I had “button.resume” and I got it working. Maybe you should update your example.

I think that the name of the button changes between button.resume, button.stop_pause and button.start.

I could change the code so it’s name is fixed … but it wouldn’t be meaningful.

I’ve fixed the name of the button in the code to avoid the variability in the name of the button entity.

1 Like

Hi, first of all - Thank you very much for your great work! I’ve got everything working flawlessly for my usecase :smiley:
I’m using the timer as an Espresso-Shot-Counter, and therefore only the elapsed time in seconds is relevant for me. Unfortunately, if I change the attribute in lovelace to “elapsed time”, there is only a value when the timer stopps. Is there a possibility to get the “elapsed time” view with a running counter?

Here are two screenshots to hopefully show more clearly what I mean.

  1. Timer is running but “elapsed time view” is stuck at zero
  2. Timer stopped and both times are fine.

Thank you very much for your answer.

Hello,

The elapsed time is an attribute needed to take into account the time the stopwatch is not running to calculate the sate of the sensor, so it is not intended to use as a running counter.

What you need is to change the format presentation of the sensor state. To do it, simply change the state lines of the sensor with this ones:

        state: >-
          {% if is_state('input_boolean.reset_stopwatch','on') %}
              {{ 0 }}
          {% elif  is_state('input_boolean.start_stopwatch','off') and is_state('input_boolean.lap_stopwatch','off') %}
              {% set value = as_timestamp(now()) - state_attr('sensor.stopwatch','initial_time') + state_attr('sensor.stopwatch','elapsed_time') %}
              {{ value|float|round(2) }}
          {% elif  is_state_attr('sensor.stopwatch','running','on') %}
              {% set value = as_timestamp(now()) - state_attr('sensor.stopwatch','initial_time') + state_attr('sensor.stopwatch','elapsed_time') %}
              {{ value|float|round(2) }}
          {% else %}
              {{ states('sensor.stopwatch') }}
          {% endif %}

It should work for you.

1 Like