Figure out time remaining

To calculate percentage you have to know the maximum duration. You gave an example of a “1hour timer” but how can the template determine it’s 1 hour? Where can it get that value?

sorry! this is the sensor + attribute i get the time from.

entity - sensor.living_room_echo_next_timer
state - 2021-09-26T10:57:34-05:00
attribute -
prior_value: 2021-09-26T10:57:34-05:00

and this is the code you provided :slight_smile:

{% set ct = state_attr('sensor.living_room_echo_next_timer', 'prior_value') | as_datetime %}
{{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}

I get the feeling that we are no longer discussing what you described in your first post, namely an entity, representing a washing machine, containing an attribute named CompletionTime'.

What is sensor.living_room_echo_next_timer and what do its state and prior_value attribute represent?

Had to modify a little as its not actually an attribute it is its own sensor but looking good thanks!

{% set ct = states('sensor.tumble_dryer_dryer_completion_time') | as_datetime %}
{{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}

So next I guess I just need to create a text helper and an automation that whenever a minute changes to update the text helper?

1 Like

I can’t answer that question because you overlooked to explain why you even need an input_text. The only thing anyone knows is:

That’s been resolved so what else were you planning to do?

sorry, i am not the OP. thanks for trying to help anyways

Sorry missed that part.

I have a picture elements card and I want to show the time remaining on that.

I have managed to do it just frustrating me that I cannot get the text white now…

  - type: state-label
    entity: input_text.dryer_finished_in
    style:
      top: 4%
      left: 77%
      width: 80%
      '--primary-text-color': '#ffffff'

That’s a separate discussion from the question in your first post. Ideally, keep each topic focused on one issue. It makes it easier for others to find answers to questions. Your Picture Elements question is now buried in a thread whose topic and original question have nothing to do with it.

replace primary color with this
color: ‘#FFA500

Thank you, I figured it out literally the same time you posted!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. It will also place a link below your first post that leads to the solution post. All of this helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

I have tried to edit this to my washing machine but I just get an error:
TypeError: float() argument must be a string or a real number, not 'NoneType'

My code is:

{% set ct = state_attr('sensor.tvattmaskin_remaining_program_time', 'CompletionTime') | as_datetime %}
{{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}

What am I doing wrong here?

Based on the error message, I believe the value produced by the state_attr function cannot be converted by the as_datetime filter into a datetime object.

This can happen if the entity sensor.tvattmaskin_remaining_program_time doesn’t exist, or its attribute CompletionTime doesn’t exist or it has a value that cannot be converted to a datetime object.

Copy-paste this into the Template Editor and see what is produced:

{{ state_attr('sensor.tvattmaskin_remaining_program_time', 'CompletionTime') }}

I get null for that one.
Here are the attributes for that one:

That explains why you got the error message. The attribute doesn’t exist.

Perhaps what you want is the state value of sensor.tvattmaskin_remaining_program_time?

{% set ct = states('sensor.tvattmaskin_remaining_program_time') | as_datetime %}
{{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}

Thank you! That works.

Now i just need to perfect it.
I use google to read this with Text to speech, and now the response is 1and55.

How could I get this to say ”1hour and 55 minutes”?

This might interest you: Human spoken time - Share your Projects! - Home Assistant Community (home-assistant.io)

Hello,
I am trying to put this in configuration.yaml but i am getting nowhere.
Could you please show me what the sensor would look like in configuration.yaml?
THNX, Henk.

Template - Home Assistant (home-assistant.io)

# HUMAN SPOKEN TIME
template:
  - sensor:
      - name: Human spoken time
        unique_id: human_spoken_time
        state: >

etc., etc., etc., etc.

OR…

Add this template: !include_dir_merge_list includes/templates/ (Splitting up the configuration) to your configuration.yaml and copy/paste the code from Human spoken time into a new yaml file located in includes/template (includes/template/humanspokentime.yaml for example).

This sensor only says the current time, you can adopt it though to say the time remaining. Unfortunately I haven’t found a way for a way to translate every given time into a nicely spoken one.