Trying to create a count up timer for a laundy cycle that displays in minutes:seconds

I’ve been through a bunch of topics and posts (and tests) but I have not seen someone attempt something close enough that I can copy it close enough.

When my dryer switches from idle to drying state, I want to start a “timer” of time elapsed to display in minutes:seconds on my entity card for the timer. I can’t count down because different cycles have different times and its simpler to give the user/me the elapsed time. Bonus would be the ability to resume the timer if the state change is close enough (so if you pause it for 30 seconds to take a single article of clothing out - but start back at zero the next time a load is started.

I’ve tried history_stats and I got this working but it doesn’t reset to zero its cumulative (which I understand is the point of that function) and I have to adjust the templating to really get it to display in mintues:seconds. Next I tried timer.start function but it also counted down, so i found someone counting up with a step calculation separate automation but It wasn’t clear to me how to translate it. Thanks for any guidance.

You could record the time (as a timestamp) when it gets to drying, and then create a template sensor that calculates ‘(as_timestamp(now()) - as_timestamp(recorded_time|int))| timestamp_custom("%H:%M")’

That would show time since the drying started.

How you record is could vary, but I’ve just published it to an MQTT topic, and then subscribed a sensor to that topic to read the value back.

I cheated for my washing machine timer and just used a standard counter.
An automation increments the counter every minute while the washing machine is running.

Another automation resets the counter when a new washing cycle starts

doesn’t play together.

I wanted to have some indication how long ago the last sensor’s reading arrived and ended up with a template sensor that I update every 5 seconds via trigger: time_pattern because you cannot use timer.remaining for that.
Would love to see a better solution.

Why not ?
The only bit he wont have is seconds, but its the equivalent of a count up timer

Because he won’t get seconds I think…

That’s fair, but measuring seconds in a process that takes hours I think is irrelevant.

I think just minutes would be fine could you post an example of how you did that? I thought a minutes:seconds would look more professional, but technically it’s only counting minutes to give a general idea to the person who started the laundry if it might be done soon.

Thank you guys for the assistance!

It would be helpful to know how to get/show seconds, but this process is typically 44 min (and not always known if its 34 - 50 min) (some cycles are auto-dry and you don’t have an exact idea) so a margin of error of 60 seconds will not matter.

1 Like

configuration.yaml

counter:
  washing_timer:
    name: Wash Time
    initial: 0
    step: 1

automations.yaml

- id: '1578722127585'
  alias: Increment the Washing Machine Timer
  initial_state: false
  description: ''
  trigger:
  - minutes: /1
    platform: time_pattern
  condition: []
  action:
  - entity_id: counter.washing_timer
    service: counter.increment

- id: '1578723224483'
  alias: Washing Machine - Washing
  description: ''
  trigger:
  - entity_id: binary_sensor.washing_machine_door
    from: 'on'
    platform: state
    to: 'off'
  - entity_id: binary_sensor.washing_machine
    from: 'off'
    platform: state
    to: 'on'
  action:
  - entity_id: counter.washing_timer
    service: counter.reset
  - entity_id: automation.increment_the_washing_machine_timer
    service: automation.turn_on

- id: '1578723538631'
  alias: Washing Machine - Finished
  description: ''
  trigger:
  - entity_id: binary_sensor.washing_machine
    from: 'on'
    platform: state
    to: 'off'
  action:
  - entity_id: automation.increment_the_washing_machine_timer
    service: automation.turn_off
1 Like

Thanks, will give this a shot!

I suspect if I got good enough with templating I could count the time in seconds and then convert it to minutes:seconds but maybe this wouldn’t be worth the “noise”

it’s not about counting but about how often your counter increments.
if you increment it every second like

trigger:
  - seconds: /1
    platform: time_pattern

you’ll have seconds in your counter.
then you will probably need a template sensor that displays it in minutes:seconds and that’s exactly where you’ll need your tempting skills - have a look here and here.

Thanks. The above items have worked perfectly, but I realize now I do need minutes:seconds because otherwise the UI is terribly confusing as the user doesn’t really know its counting “up”

I’m going to work on templating now. Cheers!

You’re welcome.
Keep us updated :wink:

I’d be interested to know if and how you finally got this working. Any updates you are willing to share? What does using a counter look like in the UI?

1 Like

Bit late to the thread, but I recently drafted up something like this to monitor the runtime of a dryer.

I have a binary_sensor that tells me if my dryer is running or not (power monitoring zigbee switch).

I used this automation to count the minutes the dryer is on (ie binary_sensor is true):

- alias: Dryer Time Count
  initial_state: on
  trigger:
    platform: time_pattern     # every 1 minute
    minutes: '/1'
  condition:       
    condition: state
    entity_id: binary_sensor.dryer_active
    state: 'on'  
  action:
  - service: counter.increment                       # increment the counter by 1
    entity_id: counter.dryer_duration

Then I make a template sensor to convert the minutes to something more presentable in the UI:

    dryer_running_time:
      value_template: >
        {% set ct = states('counter.dryer_duration') | int %}
        {% if ct == 0 %}
          Not running
        {% elif ct > 60 %}
          {{ ct // 60 }} hr and {{ '{:0>2d}'.format(ct%60) }} minutes
        {% else %}
          {{ ct }} minutes
        {% endif %}

You will need another automation that calls counter.reset at some point, at the end of a cycle or when a new one starts.

Finally, in the UI, I display this (and other information) using custom:secondaryinfo-entity-row (which I use quite a lot to more efficiently display a lot of information):

              - entity: binary_sensor.dryer_active
                name: 'Dryer'
                icon: 'mdi:tumble-dryer'
                state_color: true
                type: "custom:secondaryinfo-entity-row"
                secondary_info: "[[ input_select.dryer_state.state ]]  -  [[ sensor.dryer_power.state ]] W  -  [[ sensor.dryer_running_time.state ]]"

Looks a bit like this (this is an older version):
dryer

6 Likes