I’m working on integration of my movies library into HA. I have script runnin on my NAS that outputs list of available movies with selected attributes and TV shows into large json file. Now I want to display this information in UI, but it impractical as is, due to size of library. So I want to limit what is displayed to 100 entries per page + filter content by library (in my case HD or SD or Music or TV) and/or genre and then apply sort order that would make searching for specific movie easier. Sorting would need to be applied by some attributes (movie original title, Polish title, releaase date, IMDB rating etc. when movie was added to library and would be done in ascending or descending order. And sorting is what troubles me, as I can’t make it configurable. So what I’m seeking for is how to dynamically replace these sort attribute and order in follwong code:
{% set movies_all = state_attr('sensor.movies_list', 'list') | sort(attribute='Release Year', reverse=false) %}
I tried simple replacemnt with states of corresponding helpers:
{% set movies_all = state_attr('sensor.movies_list', 'list') | sort(attribute=states('input_select.sort_by'), reverse=states('input_boolean.sort_order')) %}
or to use variables for this:
{% set attr=states('input_select.sort_by')|string %} # this contains name off attribute to sort by
{% set ord=is_state('input_boolean.sort_order', 'on')|string %} # this should change the order of sorting from nnormal to reverse
{% set movies_all = state_attr('sensor.movies_list', 'list') | sort(attribute='attr', reverse='ord') %}
but neither of these works (OK, I understand that input_boolean gives on/off states instead of true/false, but this is for fixing later). At the moment the only solution I can think off that would work is to check the state of these 2 helpers using if elseif else
conditions and put proper sorting command inside, but this would create 10 different cases (5 attributes * 2 sort orders)… not elegant solution for sure.
Any idea how to implement it properly?