Lovelace: Upcoming Media Card

I get that with all my media players not just radarr.

But this is not a media player. But you do get it with the upcoming media card for radarr?

Addressing this in the next update, should help. It’s because the radarr component uses themoviedb’s api to supplement what radarrs api supplies. I imagine you may still get the error occasionally, but not nearly as frequent.

Updates:

Be sure to restart after updating components and read the readme’s of the updated and new components on their github pages!

New component Plex!!!

Displays recent additions to your Plex library. Be sure to check out the readme on this one, there is some important information on how images are handled with this component.

Radarr

  • Added max item config
  • Check’s api data against last updated to only update when needed.
  • Calculation of days between now and airdate is now time zone aware.

The first 2 changes should help with the “taking over 10 seconds” errors. I suggest setting max in the components configuration to the amount of items you show in the card.

Sonarr

  • Added max item config
  • Calculation of days between now and airdate is now time zone aware.
2 Likes

tried to configure it but got:

plex_recently_added: Error on device update!
    Traceback (most recent call last):
      File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 251, in _async_add_entity
        await entity.async_device_update(warning=False)
      File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
        await self.hass.async_add_executor_job(self.update)
      File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
        yield self  # This tells Task to wait for completion.
      File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
        future.result()
      File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
        raise self._exception
      File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/home/homeassistant/.homeassistant/custom_components/sensor/plex_recently_added.py", line 201, in update
        os.makedirs(directory)
      File "/usr/lib/python3.5/os.py", line 231, in makedirs
        makedirs(head, mode, exist_ok)
      File "/usr/lib/python3.5/os.py", line 231, in makedirs
        makedirs(head, mode, exist_ok)
      File "/usr/lib/python3.5/os.py", line 231, in makedirs
        makedirs(head, mode, exist_ok)
      File "/usr/lib/python3.5/os.py", line 231, in makedirs
        makedirs(head, mode, exist_ok)
      File "/usr/lib/python3.5/os.py", line 241, in makedirs
        mkdir(name, mode)
    PermissionError: [Errno 13] Permission denied: 'www' 

I was surprised not find a field option for server/IP, just the “server name”

@sfnetwork

The component automatically gets the network info it needs from Plex. Your issue is that HA doesn’t have permission to create the folder. Check out this link.

Alternatively, you can try the download_images: false option, follow the instructions on the github readme

where do it need it? I thought all related folders had 777 permisisons…

The www folder or folders within. The component creates the directory in /www/custom-lovelace/upcoming-media-card/

just checked, has full permission set…
I guess I’ll try to other way

could also try just creating the folder structure yourself. /www/custom-lovelace/upcoming-media-card/images/plex

just tried it, doesn’t work…

The other method seems to work better though… keeping testing…

1 Like

ok, it looks like so far, it’s not working when setting download to true.

When setting it up to false with ssl, it works bu I get a bunch of:

http://192.168.1.9:8123/lovelace/0:0:0 Uncaught

Althought, this may not be this at all, I’ll look into it…

also, even if I set it to 10, I get only 4…
And, anyway to disable shadow in font?

Just updated plex with a dir permission setting that may help, might want to try it again.

in upcoming media cards lovelace config set text_shadows: false

looking into why you’re only seeing 4

thanks for the shadow (didn’t see this kind of option in doc for it, I thought it wasn’t available)

I updated to 1.0 and tried the image download (after reboot af course); still same problem:

plex_recently_added: Error on device update!
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 251, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/plex_recently_added.py", line 201, in update
    os.makedirs(directory, mode=0o777)
  File "/usr/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/usr/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/usr/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/usr/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/usr/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: 'www'

would it be possible in the future to be able to separate TV episodes and movies? (to be able to create two cards)
Episodes overtake movies logically (much much more recently added than movies)…

1 Like

Good idea, will work on it

1 Like

I don’t use Plex myself but great to see you added this. This card is great. Thanks for your efforts.

Love the Sonarr and Radarr components, they both work well. Delighted to see an additional Plex component, great work!

But I do seem to have an issue getting the plex_recently_added.py custom sensor to work. Upon initializing after a reboot, it generates the following error:

Log Details (ERROR)
Tue Nov 13 2018 10:22:21 GMT+0100 (Central European Standard Time)

Error while setting up platform plex_recently_added
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/sensor/plex_recently_added.py", line 41, in setup_platform
    add_devices([PlexRecentlyAddedSensor(hass, config)], True)
  File "/config/custom_components/sensor/plex_recently_added.py", line 58, in __init__
    self.server_name, self.token)
TypeError: 'NoneType' object is not iterable

It seems to return ‘none’ when the script runs the get_server_ip(name, token) part.
When I manually go to the following url in my browser:

https://plex.tv/api/servers.xml?X-Plex-Token=<redacted>

The output does not show any server info in the XML:

<MediaContainer friendlyName="myPlex" identifier="com.plexapp.plugins.myplex" machineIdentifier="<redacted>" size="0"> </MediaContainer>

I am sure both the server name and token are correct (they work correct for other usage cases in my config). Also, when I use another (incorrect) token, I get an invalid token error in the output:

<errors>
<error>Invalid authentication token.</error>
</errors>

My sensor config:

platform: plex_recently_added
token: !secret plex_token
server_name: myplex
ssl: false
ssl_cert: false
download_images: false
max: 5

Already tried to set ssl: to true but that did not make any difference.
I run Hass.io with HA v0.82.0 on an Intel NUC running Ubuntu server 18.04LTS in a docker environment.
Plex server Version 3.67.1

I do not use the Hass.io Plex add-on but run it in a separate Docker container (if that matters) using Docker Compose. My Sonarr and Radarr servers run the same way and your other custom components do not have any problem connecting to them.

Any idea what is wrong? Is there a way to add the server definition in the Python script myself, without it trying to auto-resolve?

For me, today, it just doesn’t work anymore (worked fine yesterday)

I get:

http://192.168.1.9:8123/local/custom-lovelace/upcoming-media-card/upcoming-media-card.js:16:49 Uncaught TypeError: Cannot read property ‘attributes’ of undefined

and

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 240, in async_update_ha_state
device_attr = self.device_state_attributes
File “/home/homeassistant/.homeassistant/custom_components/sensor/plex_recently_added.py”, line 137, in device_state_attributes
poster = media[‘grandparentThumb’]
KeyError: ‘grandparentThumb’