Hi all!
I stack with as I supposed very trivial task: I have a number of vibration sensors and I want a card, showing me last 10 vibration detection events with timestamp.
I’ve got last 10 changed this way - it was easy, but it shows me last change to “not detected” - may be from “not available” or “unknown” and I have no idea how to get here only cases change from “not detected” to “detected” and how to get timestamps? Perfect solution would be: left part “friendly_name vibration detected”, right part - timestamp with date. Please help!
Filtering by a state may be done by custom:logbook-card.
But actually for showing an only state (assuming “off”) with a customized “state” label may be achieved with an Entities card (instead of Logbook) + template-entity-row (for showing a timestamp instead of a state).
ChatGPT gave me several variants, using templates, none of them working:
type: custom:auto-entities
card:
type: entities
title: Вибрационные датчики с состоянием "Обнаружено"
filter:
include:
- domain: binary_sensor
attributes:
device_class: vibration
state: "on" # Показываем только датчики, которые находятся в состоянии "on" (вибрация обнаружена)
sort:
method: last_changed
reverse: true # Сортировка по времени, начиная с последнего изменения
count: 10 # Показываем только 10 последних датчиков
type: custom:auto-entities
card:
type: entities
title: Вибрационные датчики, которые срабатывали
filter:
include:
- domain: binary_sensor
attributes:
device_class: vibration
state: "on" # Показываем только датчики, которые когда-либо были в состоянии "on"
options:
type: custom:template
template: >
{% set last_changed = states[entity.entity_id].last_changed %}
{% set time_diff = (as_timestamp(now()) - as_timestamp(last_changed)) %}
{% if time_diff < 43200 %}
{{ true }}
{% else %}
{{ false }}
{% endif %}
name: "{{ state_attr(entity.entity_id, 'friendly_name') }} - {{ states[entity.entity_id].last_changed.strftime('%Y-%m-%d %H:%M:%S') }}"
secondary_info: last-changed
sort:
method: last_changed
reverse: true
count: 10
Perhaps I shoul use “exclude”? Then what to exclude?
type: custom:auto-entities
card:
type: logbook
title: Вибрация
filter:
include:
- domain: binary_sensor
attributes:
device_class: vibration
sort:
method: last_changed
reverse: true
```/
but it gives all changes of state for all recorded time, but I need only "from off to on" and for last 12 hrs.
You mean “target selector is included”, right?
The person says they need particular states in UI. That is why I think they need not a Logbook but a simple Entities card.
Never ever mention chatgpt here ))). Avoid posting code it usually proposes because in many cases it is wrong and distracts users.
Normal YAML syntax (each setting optional)
sections: # see explanation further up
- volumes
- groups
- grouping
- media browser
- player
- queue
Tried:
Not working at all (breaks)
'sections': [
{'- player',}
]
'sections' : [
{'player'},
]
'sections' : {
'- player'
}
No effect
'sections' : [player]
Changes to 'volumes" section
'sections' : ['- player'],
'sections' : ['- player',]