Modify a time to show how many minutes it is to that time

I use a flex-table-card to display the departure times for buses (as below) but I would like to change and instead show how many minutes it is to departure (“Leaves in”).

image

I tried but cannot really figure out how to do it…my assumption is that I would be able to do something like this below…

type: custom:flex-table-card
sort_by: state+
title: To Radiomotet & Frölunda torg
columns:
  - name: From
    attr: friendly_name
    modify: x.split(' mot')[0]
  - name: Bus
    attr: line
  - name: Direction
    attr: direction
    modify: x.split(',')[0]
  - name: Depart
    prop: state
  - name: Leaves in
    data: state
    modify:
      <<< SOMETHING HERE TO MODIFY THE DISPLAYED VALUE, WHICH IS THE "STATE VALUE" OF THE SENSOR  >>>
entities:
  include:
    - sensor.eklanda_torg_mot_f*
    - sensor.eklanda_skola_mot_f*

Anyone that could guide me? :slight_smile:

I’ve created some template sensors to calculate the difference between two times and then format them in a more friendly manner.

        {% set elapsed = (as_timestamp(states('sensor.date_time').replace(',','')) - state_attr('variable.device_on_time','anthem_avm60') | float ) %}
        {% if elapsed < 0 %}{% set elapsed = 0 %}{% endif %}
        {% set days = (elapsed / 86400) | int %}
        {% set hours= ((elapsed  % 86400) / 3600) | int %}
        {% set mins = ((elapsed  % 3600) / 60) | int %}
        {% set secs = elapsed | int % 60 %}
        {% if days > 0 %} {{days}}d {%if hours < 10 %}0{%endif%}{{hours}}:{%if mins< 10 %}0{%endif%}{{mins}}
        {% elif hours > 0 %} {% if hours < 10 %}0{%endif%}{{hours}}:{%if mins< 10 %}0{%endif%}{{mins}}
        {% elif mins > 0 %} {{mins}}m
        {% else %} {{secs}}s {% endif %}

Result examples:
image