Format of time stamps as relative value - i.e. for a last changed value

Using the entities card, I get the relative time since last change, as I want to see the value:

When I use i.e. the bignumber-card or the picture-elements-card, the value is display like:

How would I get the relative output?

I believe you need to template a value to a input_string.

Just remove that topic and raised a new try :wink:

Might you give an example?

Not sure about the timestamp format.
But if you try this: open the template tool in developer tools and paste

{{ as_timestamp(“the sensor/entity date time”) }}

does it display a long float value?

{{ as_timestamp(docker_mosquitto_up_time) }}
UndefinedError: 'docker_mosquitto_up_time' is undefined

I assume that is a sensor?

{{ as_timestamp(states.sensor.docker_mosquitto_up_time.state) }}

Yes, it’s a sensor. I also have some template sensors.

{{ as_timestamp(states.sensor.docker_mosquitto_up_time.state) }}
1611441182.26375

Ok…

I realized a sensor is probably better.

Try this:

sensor:
  - platform: template
    sensors:
      name_of_entity:
        friendly_name: "Friendly name of entity"
        value_template: {{ ((as_timestamp(now()) - as_timestamp(states.sensor.docker_mosquitto_up_time.state))/60/60) | int }} minutes ago

This will give you a sensor with minutes.

Konfiguration check:

Error loading /config/configuration.yaml: while parsing a block mapping
  in "/config/sensors/systeminfo_sensors.yaml", line 35, column 7
expected <block end>, but found '<block mapping start>'
  in "/config/sensors/systeminfo_sensors.yaml", line 36, column 9

Line 36 is the value template

Add " " around the value_template

1 Like

I took your hints and combined it with another post I found. That’s my solution:

- platform: template
  sensors:
    rpi_online:
      icon_template: mdi:raspberry-pi
      value_template: >-
        {%- set last_boot = states('sensor.last_boot') %}
          {%- if last_boot in ['unavailable', 'unknown'] or last_boot is none %}
            unknown
          {%- else %}
            {%- set uptime = now().timestamp() - as_timestamp(last_boot) %}
            {%- set time = uptime | int %}
            {%- set minutes = ((time % 3600) // 60) %}
            {%- set minutes = '{}min'.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 }}
          {%- endif %}