Using a standard Tile card and a Trigger sensor, we get a card that updates the time since the trigger was tripped, first every second, then every minute, then hour, etc.
Trigger:
# Test Contact Sensor Last Opened
- trigger:
- platform: state
entity_id:
- binary_sensor.test_contact_sensor_contact
to:
- "on"
sensor:
- name: "Test_Contact_Sensor_Last_Open"
device_class: timestamp
state: "{{ now() }}"
Yaml Card:
- type: tile
entity: sensor.test_contact_sensor_last_open
icon: mdi:exit-run
name: Test Contact Sensor
card_mod:
style: |
ha-state-icon {
{% if is_state('binary_sensor.test_contact_sensor_contact','off') %}
color: green;
{% elif is_state('binary_sensor.test_contact_sensor_contact','on') %}
color: red;
{% else %}
color: yellow;
{% endif %}
}
Dashboard display:
I wanted to add more data to the Tile card, so used a sensor template with attribute_templates to roll all the data up into a single sensor:
Sensor Template:
- platform: template
sensors:
my_test_contact:
friendly_name: "My Test Contact"
value_template: "{{ states('sensor.test_contact_sensor_last_open') }}"
device_class: timestamp
attribute_templates:
battery: "{{ states('sensor.test_contact_sensor_battery')+'%' }}"
open: "{{ states('binary_sensor.test_contact_sensor_contact') }}"
link_quality: "{{ states('sensor.test_contact_sensor_linkquality')+'i' }}"
last_open: >-
{% with mytime = (as_timestamp(now()) - as_timestamp(states('sensor.test_contact_sensor_last_open'))) | int %}
{% if (mytime // 2592000) > 0 %}
{{ '{} mth ago '.format(((mytime / 2592000) | float) | round(1)) }}
{% elif (mytime // 604800) > 0 %}
{{ '{} wks ago'.format(((mytime / 604800) | float) | round(1)) }}
{% elif (mytime // 86400) > 0 %}
{{ '{} dys ago'.format(((mytime / 86400) | float) | round(1)) }}
{% elif (mytime // 3600) > 0 %}
{{ '{} hrs ago'.format(((mytime / 3600) | float) | round(1)) }}
{% elif (mytime // 60) > 0 %}
{{ '{} min ago'.format(((mytime / 60) | float) | round(1)) }}
{% elif (mytime // 1) >= 0 %}
{{ '{} sec ago'.format(mytime // 1) }}
{% else %}
{{ 'Unknown' }}
{% endif %}
{% endwith %}
And used the Tile card with state_content for the additional data (thanks @reste_narquois) :
- type: tile
entity: sensor.my_test_contact
icon: mdi:exit-run
name: Test Contact Sensor
state_content:
- last_open
- battery
- link_quality
card_mod:
style: |
ha-state-icon {
{% if is_state_attr('sensor.my_test_contact', 'open','off') %}
color: green;
{% elif is_state_attr('sensor.my_test_contact', 'open','on') %}
color: red;
{% else %}
color: yellow;
{% endif %}
}
This breaks the auto-update feature of the standard Tile card with ‘time since triggered’ reporting, so I had to roll my own output in the template sensor (above).
The problem now is that the new Tile card (on right) only updates every minute, instead of the default of evey second for the first minute, every minute for the first hour, every hour for the first day, etc…(you get the idea).
A while this isn’t an issue if its been hours since the trigger was tripped, its annoying for the first hour
Any ideas on how the change the update interval of the Tile Card so it better matching the default ‘since last tripped’ configuration?
Even having it update every 10 seconds would be nice.
Thanks!