I am building a dashboard for my utility room which has my Samsung Smarthings washing machine and tumble dryer on as an image of the actual device. What I would love to do is where the screen is on the picture is to display the remaining time of the current job however I have no idea how to convert the CompletionTime attribute to a hours and minutes remaining.
Example of the attribute: 2021-09-25T19:58:48Z
Is anyone able to help me to convert this datetime string into a time remaining (using current time as comparison).
I guess this would set this into a string helper and then have a conditional element on my picture element that if machine state = run show the remaining time?
If the value of CompletionTime is in the future then it should indicate the number of hours and minutes remaining. If itâs in the past, itâs hard-coded to report 00:00.
If that works, it can be used to create a Template Sensor that reports the remaining time.
NOTE
Itâs possible that the as_datetime filter isnât needed if Home Assistant already understands that CompletionTime is a datetime object (as opposed to the datetime string).
This works! Is there anyway you can convert the hours:minutes remaining into a percentage remaining? eg, 1 hour timer at 30 mins left reports 50%. at 10 minutes remaining in timer = 83%
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?
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?
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.
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.
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: