Estimated completion time from time remaining

Hi,

I’m trying to create a notification with the estimated completion time of my washing machine… however I cant figure out how to add the remaining time to the current time
the remaining time is in the format H:MM as an attribute to sensor.washer
Ive tried loads of different combos of as_timestamp or .timestamp() but always resulting in type errors

{{ now() + strptime(state_attr('sensor.washer', 'remain_time'),  '%H:%M') | timestamp_custom('%H:%M') }}

ive had a good read through the EPIC time conversion topic, but still cant make this work. There are several other topics asking for similar things but cant find a working solution

Try this:

{{ now() + timedelta(hours=state_attr('sensor.washer', 'remain_time').split(':')[0]|int(0)), minutes=state_attr('sensor.washer', 'remain_time').split(':')[1]int(0) }}
{% set t = strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M', today_at()).time() %}
{{ now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second) }}

EDIT

Correction. Overlooked to include the attribute.

Removed unnecessary argument for today_at (see tom_l’s post below).

1 Like

Can you not just use: today_at() instead of today_at('00:00:00')?

Also it’s an attribute of sensor.washer, not the state.

1 Like

My mistake: I copy-pasted it from a nearby identical post I made elsewhere. Fixed.

1 Like

Also since when does strptime() take 3 arguments?

The third argument is the default in case the conversion fails.

You’re right; today_at() returns today at zero-hour so the argument I supplied is unnecessary (I have removed it).

Ah of course it is. Thanks.

Thanks both for your help, I hadn’t seen the timedelta thing…

    {% set t = strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M', today_at()).time() %}
    {{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}

To get a nice looking time for the notification I had to convert it back to a timestamp to be able to use the timestamp custom format.

Next fun task will be to use the initial time and the remain time to calculate how many % through the wash it is.

Hello,
That’s nice !
Could you share your code for the timestamp value as a notification:

  - service: notify.mobile_app
    data_template:
      title: Washing machine time remaining
      data:
        chronometer: true
        when: "{% set t = strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M', today_at()).time() %}
    {{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}"

Here you go,

service: notify.mobile_app_chris
data:
  message: >-
    {% set t = strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M:%S',
    today_at()).time() %} Cycle {{ states('sensor.washer_current_course') }}
    <br> Currently {{ states('sensor.washer_run_state') }} <br> Estimated
    completion time: {{ as_timestamp(now() + timedelta(hours=t.hour,
    minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}
  title: Washing Machine Running
  data:
    tag: washing_machine
    notification_icon: mdi:washing-machine
1 Like

Hello there. I’m digging this up, with the same usecase - dishwasher (SmartThings) time remaining. Unfortunately the code does note seem to work for me - it spills the following log:

ValueError: Sensor sensor.custom_dishwasher_time_remaining has device class ‘None’, state class ‘None’ unit ‘minutes’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘“20:58”’ (<class ‘str’>)

My sensor definition in yaml:

#dishwasher remaining time
- platform: template
  sensors:
    custom_dishwasher_time_remaining:
      friendly_name: "Pozostały czas programu"
      value_template: >
        {% set t = strptime(states('sensor.zmywarka_dishwasher_completion_time'), '%H:%M', today_at()).time() %}
        "{{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}"
      icon_template: mdi:clock

I tried with " " and without it - effect is the same…

The error you have quoted does not match the configuration you have posted. Either this is not the actual configuration you are using, or you have erroneously pasted YAML configuration in the Template Helper editor’s “State template” field.

The output of the timestamp_custom() filter will cause the state value to be returned in the string format “HH:MM”, so you cannot specify a value for the unit_of_measurement. Sensors using unit_of_measurement are required to return a purely numeric state.

Regardless, the quotes on the last line should not be there, since they will cause the final expression to be returned in its entirety as a string and you will end up with a state like: {{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }} instead of 10:15.

Thank you. The truth is that it actually was a log message that appeared when I tried to add this template sensor (just without the “”). And it blew my mind, as I have no clue why would it appear in the first place… The funny thing is though, that I have not restarted the HA, but just reloaded the config yesterday.

When I resterted completely HA today, it went without any hiccup. Anyhow, thanks again for the effort of replying to me! :slight_smile: