I’m trying to create a card that shows when motion is detected (via a motion sensor in my office), and want to show when last updated as a secondary row, formatted relatively.
By default when triggered the sensor shows ‘0 seconds’, and I want to reformat ‘0 seconds’ to ‘Now’ and then after that show the relative time with the ’ ago’ string added (e.g. 10 minutes ago).
- type: custom:mushroom-template-card
entity: sensor.office_motion
primary: |
{% if is_state('sensor.office_motion', 'Detected') %}
Motion Detected
{% else %}
None Detected
{% endif %}
secondary: |
{% if is_state('relative_time(states.binary_sensor.office_sensor_occupancy.last_updated)', '0 seconds') %}
Now
{% else %}
{{ (relative_time(states.binary_sensor.office_sensor_occupancy.last_updated)) }} ago
{% endif %}
icon: |
{% if is_state('sensor.office_motion', 'Detected') %}
mdi:human-handsup
{% else %}
mdi:human-male
{% endif %}
I’ve been trying for quite a while but it still keeps showing ‘0 seconds ago’ when triggered instead of ‘Now’.
Any help would be greatly appreciated