Closed daloki83 closed 1 year ago
Probably this is same as https://github.com/thomasloven/lovelace-auto-entities/issues/363 - i.e. about 2nd sort method.
You may use more than 1 sorting method when using a template
option.
Okay, but I cannot find and example or explanation for that. Could you provide a sample please?
For instance:
filter:
template: >-
{{ states.binary_sensor |
selectattr('entity_id','search','battery_charging') |
sort(reverse=false,attribute='entity_id') |
sort(reverse=false,attribute='state') |
map(attribute='entity_id') | list }}
Hmm not really working for me. I added:
filter:
template: >-
{{ states.sensor | selectattr('entity_id','search','_power') |
sort(reverse=true,attribute='entity_id') |
sort(reverse=false,attribute='state') | map(attribute='entity_id') | list }}
and he added every sensor with a power attribute to the rest of my sensors. I think i could exclude unwanted sensors, but how could i than bring back the Power-Switch button
Made it now this way for all devices so....can be closed here
type: custom:auto-entities
card:
type: entities
state_color: false
entities:
- entity: sensor.arbeit_energy_power
name: Arbeit
type: custom:multiple-entity-row
entities:
- entity: switch.arbeit
name: ' '
toggle: true
state_color: true
I am trying to achieve this as well. I would like to sort my sensors first by state (`display "on" at the top), then by either friendly_name or last_changed (so "on" still on top, but sorted by 2nd sort, then "off" underneath, also sorted by 2nd sort).
This is my code; what would I have to add / change to get the results I need?
type: vertical-stack
cards:
- type: custom:auto-entities
card:
type: entities
state_color: true
filter:
include:
- entity_id: binary_sensor.draussen_einfahrt_motion_3
options:
secondary_info: last-changed
- entity_id: binary_sensor.draussen_einfahrt_motion_2
options:
secondary_info: last-changed
- entity_id: binary_sensor.oben_bad_occupancy_aqara_presence
options:
secondary_info: last-changed
- entity_id: binary_sensor.*_presence_presence
options:
secondary_info: last-changed
- entity_id: '*_occupancy'
options:
secondary_info: last-changed
- entity_id: '*motion'
options:
secondary_info: last-changed
- entity_id: binary_sensor.blink_keller_motion_detected
options:
secondary_info: last-changed
exclude:
- entity_id: '*global*'
- entity_id: switch.*
- state: unavailable
- entity_id: automation.*
sort:
method: state
reverse: true
- type: custom:auto-entities
card:
type: entities
state_color: true
filter:
include:
- entity_id: '*tuer_contact'
state: 'on'
options:
secondary_info: last-changed
- entity_id: '*fenster_contact'
state: 'on'
options:
secondary_info: last-changed
exclude: []
Screenshot
As you can see, these are sorted by state. But other than that, it seems randomly. They are neither sorted by alphabet, nor by last_changed.
As you can see, these are sorted by state. But other than that, it seems randomly
No, they ARE sorted by state: first on
, then off
.
What you can see is a side effect of your chosen device_class
.
No, they ARE sorted by state: first
on
, thenoff
. What you can see is a side effect of your chosendevice_class
.
Yes. I wrote that.
As you can see, these are sorted by state.
But... I would like them to be sorted by state and then by last_change; so the correct order from the screenshot that I am trying to generate would be like this:
Minuten
= minutes, Stunde
= hour; so smallest value minute to highest value minute, then smallest value hour to highest value hour.
Is this possible? And if so, could you please explain to me, how I can achieve this? Ideally based on the yaml I pasted in my initial post? Thanks :)
be sorted by state and then by last_change
Let's go step by step.
sort:
method: state
your rows are properly sorted by state "on" -> "off". As expected.
Ok, I don't know if this has anything to do with this not working, but...
{{ states.binary_sensor.gruppe_arbeitszimmer_fenster.last_changed }}
> 2024-01-06 07:08:22.594679+00:00
{{ state_attr("binary_sensor.gruppe_arbeitszimmer_fenster", "last_changed") }}
> None
I tried changing the template you linked using what I know. Nothing. Eventually I just messed around with random values. Of course, nothing.
Then I realized that there is no last_changed attribute. I had troubles with that before (community.home-assistant.io).
Do you know if there is a way to utilize this in order to sort my entities the way I need them to be sorted?
Check this example:
{% set OBJECTS = states.input_boolean |
selectattr('entity_id','search','test.*boolean') |
sort(reverse=false,attribute='last_changed') |
sort(reverse=false,attribute='state') %}
{% for object in OBJECTS %}
entity_id: {{object.entity_id}}
state: {{object.state}}
state: {{object.last_changed|as_local}}
{% endfor %}
Thank you.
I changed it to this, which seems to present the desired output in developer tools.
{% set OBJECTS = states.binary_sensor |
selectattr('entity_id','search','.*presence*|.*occupancy*') |
sort(reverse=false,attribute='state') |
sort(reverse=false,attribute='last_changed')
%}
{% for object in OBJECTS %}
entity_id: {{object.entity_id}}
state: {{object.state}}
state: {{object.last_changed|as_local}}
{% endfor %}
But this won't display in auto-entities:
Because the template is wrong. It must represent a list of dictionaries. Suggest to go to the Community auto-entities thread for examples of using "template".
IMPORTANT: compare my
sort(reverse=false,attribute='last_changed') |
sort(reverse=false,attribute='state') %}
with yours, order of filters is crucial.
I created this config with all of my sensors for power meassurements including a switch to turn them on/off. But what ever i try, i'm not able to sort by the "power"-entitie/value. It always uses the state from the switch. Is there any way to do this or if not to implement?