Calculate timer duration on known completion time

Hello,
apparently a bit of math. I have a sensor provided by my washing machine that returns the completion time. How can I start a timer with a duration based on this sensor?

  - service: timer.start
    target:
      entity_id: timer.your_timer
    data:
      duration: >
        {% set t = states('sensor.your_sensor') | as_datetime | as_local %}
        {{ (t - now()).total_seconds() }}

Replace timer.your_timer and sensor.your_sensor with the entity_id of your actual timer and sensor.


NOTE

If the sensor’s device_class is timestamp, it can be used directly by a Time Trigger.

trigger:
  - platform: time
    at: sensor.your_sensor

Reference:
Time Trigger

1 Like

Great, works like a sharm. It would be great to have a text book for such a simple solutions of home assistant or templating in general.

THANKS!

2 Likes