Need help creating a sensor after I confirm a template works in dev tools

My Samsung washer and dryer only show completion time and no remaining time.
I found how to get this data and successfully tested in dev tools template:

Now, my stupid problem is that I have no clue how to add this correctly in the sensors.yaml, the syntax…
sensor

This was how I tried but isn’t right:

> #Template for washer and dryer
>   - platform: template
>     sensors:
>       remainingtime_laveuse:
>         value_template: {% set ct = states('sensor.laveuse_washer_completion_time') | as_datetime %}
>         {{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}

Thanks in advance :slight_smile:

Wrong formatting at a guess:

template:
  - sensor:
    - name: your sensors name
      state: >
        {% set ct = states('sensor.laveuse_washer_completion_time') | as_datetime %}
        {{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}

Example can be found here:

EDiT: adding missing colon from “state: >”

Still is not valid when trying to add this in my sensors.yaml…

template:
  - sensor:
    - name: Laveuse temps restant
      state >
        {% set ct = states('sensor.laveuse_washer_completion_time') | as_datetime %}
        {{ '00:00' if now() > ct else (ct - now()).total_seconds() | timestamp_custom('%H:%M', false) }}

You’re adding it to the wrong place.

If you have the following line in configuration.yaml

template: !include templates.yaml

then the suggested example goes in templates.yaml but without including the first line containing template:

If you do not have that line in configuration.yaml, then put the suggested example directly in configuration.yaml.

ok tried adding this directly in configuration.yaml (I don’t have the templates.yaml link) but HA showing me this error:
2023-03-29 12_21_39-NVIDIA GeForce Overlay DT

My lines in configuration.yaml:

The error message says it was expecting to find a colon but it was missing.

You’re missing a colon here:

      state >

Change it to this:

      state: >

Thank you so much for this it works!
Very sorry, I always mess up in yaml syntax when I need to jump back in it after months…