Add timestamp to binary sensor

One of my doorsensors works perfect with the code below but I want to add a timestamp so the last time the status changed is shown in my card. As a Hassio newbie I do need some help, is someone willing to guide me?

binary_sensor Door:
  - platform: mqtt
    name: 'Door'
    state_topic: 'tele/SonoffRF1/RESULT'
    value_template: >-
      {% if value_json.RfReceived.Data == '005B2E' %}
        {{'ON'}}
      {% elif value_json.RfReceived.Data == '005B27' %}
        {{'OFF'}}
      {% else %}
        {{states('binary_sensor.Door') | upper}}
      {% endif %}
    device_class: Door 

There is already an existing last-changed attribute for all entities.

All you need to do is create an entities card and add the option for the entity:

Thanks for the link Finity. Just visited, I need to make an extra entity am I right? In that case I really don’t know how to use the code for my config, can you be more specific?

Adding the line

    show_last_changed: true

in above acode generates an error so any help is welcome!

Search for “last_updated” in the link from @finity. In lovelace you need to add:
secondary-info: last_changed

Please post the code of your lovelace config for this card if you still have problens.

Thanks for helping! With the code below (after adding secondary-info: last_changed) the Hassio validator shows this error:

Invalid config for [binary_sensor.mqtt]: [secondary-info] is an invalid option for [binary_sensor.mqtt]. Check: binary_sensor.mqtt->secondary-info. (See ?, line ?). Please check the docs at https://home-assistant.io/integrations/binary_sensor.mqtt/

# HalDeur
binary_sensor Haldeur:
  - platform: mqtt
    name: 'Haldeur'
    state_topic: 'tele/SonoffRF1/RESULT'
    value_template: >-
      {% if value_json.RfReceived.Data == '005B2E' %}
        {{'ON'}}
      {% elif value_json.RfReceived.Data == '005B27' %}
        {{'OFF'}}
      {% else %}
        {{states('binary_sensor.Haldeur') | upper}}
      {% endif %}
    device_class: Door
    secondary-info: last_changed

Hi Hans

You need to put the secondary info into your Lovelace card config, not in the binary_sensor configuration. Like so:

entities:
  - entity: binary_sensor.0x00158d00028ab3b7_occupancy
    name: Living beweging
    secondary_info: last-changed

image

Thanks, I’ll try.

BTW: I’m afraid it is no longer a secret I’m new with Hassio :wink:

FYI, in the answers above, they say both last-changed and last_changed. The documentation says last-changed and that seems to work.

The documentation also allows last-updated, but that does not work for me.