This has been bothering me, too.
Your question was just the push I needed to try and come up with a temporary solution - and I think I got something working.
I’d much prefer if the root cause got fixed, but let’s make this a learning experience.
It’s not the most elegant, but it does the job – hopefully.
Preview
Plex Recently Added Backup
Requirements
- Helper entity
- Template sensor
- Template select (change)
- Automation
- swipe-card (change)
- conditional_media (change)
Helper (Helper entity, to store the info)
Example: input_text.backup_plex_recently_added
I created one via the GUI:
Navigate using command: Press the letter C → Type: Helpers → Press enter
Or, browse here: Settings → Devices & Services → Helpers → Create Helper → Text
OBS: Maximum length should be 255
Template sensor (To make it easier with JavaScript later)
This is unnecessary, but it makes sense to me that we have a sensor with attributes.
I tried creating an attribute with a dict similar to the ‘Recently Added’ sensor, but jinja and the formatting got weird on me, so I just did this for now:
This sensor is grabbing the state of the input_text helper, and cleans it up.
Like this
Template select
Updated the select template to handle the new sensor.
Automation (To take backup of 1 item in the ‘Recently Added’ sensor)
Not tested properly yet…
Triggers
platform: state
entity_id:
- sensor.recently_added_mix
to: Online
Conditions
condition: template
value_template: >-
{{ trigger.to_state.state not in [trigger.from_state.state, 'cannot be
reached', 'unavailable', 'undefined','unknown','none','null'] }}
Actions
service: input_text.set_value
data:
value: >-
{% if not states('sensor.recently_added_mix') in
['unavailable','undefined','unknown','none','null','0'] %}
{% set state = namespace(return='') %}
{% set data = state_attr('sensor.recently_added_mix','data') %}
{%- for value in data %}
{%- if not loop.first and value is defined and state.return == '' %}
{%- if not value.number is defined %}
{% set state.return =
"aired:" + value.aired + "|" +
"title:" + value.title + "|" +
"fanart:" + value.fanart + "|" +
"poster:" + value.poster
%}
{%- else %}
{% set state.return =
"aired:" + value.aired + "|" +
"title:" + value.title + "|" +
"number:" + value.number + "|" +
"fanart:" + value.fanart + "|" +
"poster:" + value.poster
%}
{%- endif %}
{%- endif %}
{%- endfor %}
{{ state.return }}
{% endif %}
target:
entity_id: input_text.backup_plex_recently_added
lovelace.yaml – swipe-card update
button_card_templates.yaml – conditional_media update
(state_display and background-image)
Edit: Added a change in the text color.
This is optional, of course, but I wanted another indicator that something was wrong.
conditional_media:
- color: >
[[[
if (entity.state === "Active") {
return entity === undefined
? '#97989c'
: 'rgba(239, 239, 239, 0.5)';
}
else {
return entity === undefined
? '#97989c'
: '#efefef';
}
]]]
PS: I haven’t tested it fully yet, so try at your own risk