Hi.
I’m new here and would really like to know, how to put the completion time sensor data of my Samsung washer into a template.
Tried different approaches, but nothing really works.
{% set t = strptime(state_attr('sensor.washer_washer_completion_time', 'CompletionTime'), '%H:%M', today_at()).time() %}
{{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}
(shows current time instead)
Or
{% set ct = state_attr('sensor.washer_washer_completion_time', 'CompletionTime') | as_datetime %}
{{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}
(shows: ValueError: Template error: as_datetime got invalid input ‘None’ when rendering template ‘{% set ct = state_attr(‘sensor.washer_washer_completion_time’, ‘CompletionTime’) | as_datetime %} {{ ‘00:00’ if now() > ct else (ct - now()).total_seconds() | timestamp_custom(’%H:%M’, false) }}’ but no default was specified)
I’m guessing that your washer is not running so
state_attr('sensor.washer_washer_completion_time', 'CompletionTime')
Is returning ‘None’ which is failing to cast to the datetime that you are asking for
I’m on mobile and hard to code, but I think you want to do a format like
{% if state_attr('sensor.washer_washer_completion_time', 'CompletionTime') != 'None' %}
....
{% else %}
None
{% endif %}
remember that case matters in the compare… check to see what it’s actually returning when not running
The machine was definitely turned on and also kept reporting the correct time when clicking on the entity itself. Just wondering how I can make this info into a template so I can use it on the dashboard ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=12)
The error you are getting for this
{% set ct = state_attr('sensor.washer_washer_completion_time', 'CompletionTime') | as_datetime %}
{{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}
indicates the state_attr call is returning. ‘None’. are you sure that’s not happening?
when you put {{ state_attr('sensor.washer_washer_completion_time', 'CompletionTime') }}
in dev tools → templates you get a valid time?
btw, even if you do, i’d still do what i wrote above so that when it’s not running, you’re not generating errors