Timestamp template sensor still unavailable

Hello,
I’ve a template sensor like:

> template:
>   - sensor:
>       - name: "start_filtration"
>         state: >
>           {% set debfiltrationf= states('sensor.duree_filtration') | float %}
>           {% set hmed=(debfiltrationf/2) %}
>           {{ as_timedelta("PT14H") - timedelta( minutes = (hmed)|float(1)) }}
>         device_class: timestamp

This sensor still always unavailable since ha 2023.6.1

In developper tools, under model, all seems fine :

> {{states("sensor.duree_filtration")}}

result: 524

> 
> {% set debfiltrationf= states("sensor.duree_filtration") | float %}
> {% set hmed = 14 | multiply(60) | float  %}
> {% set hdeb= hmed - (debfiltrationf/2) %}
> {{ as_timedelta("PT14H") - as_timedelta(states("sensor.duree_filtration")) }}

result: 13:51:16

I don’t understand why “unavailable” ?
Thanks

timestamp sensors require a datetime as the output of your template. You’re providing it a timedelta.

datetime → is a date and time
timedelta → is a change in time (a duration)

Your template is outputting a duration of 13 hours or so.

Also there is no need to prefix every line with >. Using codeblocks will retain the spacing on the forum.

Thank you,
it looks better but it’s always unavailable :

template:
  - sensor:
      - name: "start_filtration"
        state: >
          {% set debfiltrationf= states("sensor.duree_filtration") | float %}
          {{ (today_at("14:00") + timedelta(days=1))-timedelta(minutes=(debfiltrationf/2))}}
        device_class: timestamp

Result in developer tools > Models : 2023-06-13 09:38:00+02:00

My date seems ok, but I think that missing the “T” separator, i try to fix it with enforcing the ISO conversion but it’s not working yet.

it’s seems to work with an availability template.
final version

template:
  - sensor:
      - name: "start_filtration"
        state: >
          {% set debfiltrationf= states("sensor.duree_filtration") | float %}
          {{(today_at("14:00") + timedelta(days=1))-timedelta(minutes=(debfiltrationf/2))}}
        availability: >-
          {{ states('sensor.max_piscine') not in ['none', 'unknown', 'unavailable'] }}
        device_class: timestamp

thanks