Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto-entities card that shows my motion sensors ordered
type: custom:auto-entities
card:
type: entities
filter:
include:
- entity_id: /last_detected/
exclude:
- entity_id: "*0x*"
sort:
method: attribute
attribute: order
reverse: true
- platform: template
sensors:
office_motion_last_detected:
friendly_name: "Office motion"
value_template: >-
{% if states.binary_sensor.office_motion_sensor.state == 'on' %}
Detected {{ relative_time(strptime(as_timestamp(states.sensor.office_motion_query.state) | timestamp_local, "%Y-%m-%d %H:%M:%S")) }} ago
{% else %}
Cleared {{ relative_time(strptime(as_timestamp(states.sensor.office_motion_query.state) | timestamp_local, "%Y-%m-%d %H:%M:%S")) }} ago
{% endif %}
- platform: sql
scan_interval: 120
db_url: !secret mariadb_url
queries:
- name: Office motion query
query: "SELECT last_changed FROM states where entity_id = 'binary_sensor.office_motion_sensor' and state = 'on' order by last_changed DESC LIMIT 1"
column: 'last_changed'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment