Show tile card state content last_changed precisely

Is it possible to change the elapsed time from an “about” to a precise time? So if the change was 1 hour and 18 Minutes ago, the tile doesn’t say 1 hour? It is really nerving for the cards I use, as they should show me the elapsed time of running programmes.

Current code of the tile
type: conditional
conditions:
  - condition: state
    entity: binary_sensor.waschmaschine_lauft
    state: 'on'
card:
  type: tile
  entity: binary_sensor.waschmaschine_lauft
  vertical: true
  name: Waschmaschine
  color: blue
  state_content:
    - last-changed
    - sensor_value
  tap_action:
    action: none
  icon: mdi:washing-machine

Hey i hadnt forgotten about this I just have family staying over Christmas period so all my advice has been using my phone and from memory of mushroom card CSS. But i dont remember this stuff for the tile card so took a bit longer to figure out :slight_smile:

Below code will hide the normal secondary line and replace it with whatever you write in the content: ''; bit.

type: conditional
conditions:
  - condition: state
    entity: binary_sensor.waschmaschine_lauft
    state: 'on'
card:
  type: tile
  entity: binary_sensor.waschmaschine_lauft
  vertical: true
  name: Waschmaschine
  color: blue
  state_content:
    - last-changed
    - sensor_value
  tap_action:
    action: none
  icon: mdi:washing-machine
  card_mod:
    style:
      ha-tile-info$: |
        .secondary {
          color: transparent !important;
        }
        .secondary:before {
          content: 'Test';
          display: flex;
          justify-content: center;
          color: var(--secondary-text-color);
        }

Then you need a piece of code that figures out the time between last changes and now. This is my favourite version it isnt short, but its the most accurate i have found:

{%- set time = (as_timestamp(now()) - as_timestamp(states.binary_sensor.waschmaschine_lauft.last_changed)) | int  %}
  {%- set minutes = ((time % 3600) // 60) %}
  {%- set minutes = '{}m'.format(minutes) if minutes > 0 else '' %}
  {%- set hours = ((time % 86400) // 3600) %}
  {%- set hours = '{}h '.format(hours) if hours > 0 else '' %}
  {%- set days = (time // 86400) %}
  {%- set days = '{}d '.format(days) if days > 0 else '' %}
  {{ 'Less than 1 min' if time < 60 else days + hours + minutes }}

Combined with your card:

type: conditional
conditions:
  - condition: state
    entity: binary_sensor.waschmaschine_lauft
    state: 'on'
card:
  type: tile
  entity: binary_sensor.waschmaschine_lauft
  vertical: true
  name: Waschmaschine
  color: blue
  state_content:
    - last-changed
    - sensor_value
  tap_action:
    action: none
  icon: mdi:washing-machine
  card_mod:
    style:
      ha-tile-info$: |
        .secondary {
          color: transparent !important;
        }
        .secondary:before {
          content: '{%- set time = (as_timestamp(now()) - as_timestamp(states.binary_sensor.waschmaschine_lauft.last_changed)) | int  %} {%- set minutes = ((time % 3600) // 60) %} {%- set minutes = '{}m'.format(minutes) if minutes > 0 else '' %} {%- set hours = ((time % 86400) // 3600) %} {%- set hours = '{}h '.format(hours) if hours > 0 else '' %} {%- set days = (time // 86400) %} {%- set days = '{}d '.format(days) if days > 0 else '' %} {{ 'Less than 1 min' if time < 60 else days + hours + minutes }}';
          display: flex;
          justify-content: center;
          color: var(--secondary-text-color) !important;
        }

Of course translate whatever you need into German :slight_smile:

1 Like

Thank you! This helps us really much to follow up on possible overloads etc of our appliances.
Have a wonderful weekend and “guten Rutsch” into the new year!

1 Like