How to calculate / subtract two date.time from eachother?

You’ll wanna convert to timestamps. Those are like Unix seconds-since-epoch times. Here’s a snippet where I look at the end time of a calendar event for use in a template sensor. 900 seconds = 15 minutes

  {% if states.calendar.nathan_tech_shop %}
      {% if is_state("calendar.nathan_tech_shop", "on") and as_timestamp(states.calendar.nathan_tech_shop.attributes.end_time) - as_timestamp(now()) < 900  %}on{% else %}off{% endif %}
  {% else %}off{% endif %}
1 Like