Lovelace: Upcoming Media Card


#247

Good idea, will work on it


#248

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


#249

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?


#250

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’


#251

well, after another reboot, it started working again… go figure…


#252

Later today I’ll add a manual config for IP and port that doesnt rely on the plex servers.


#253

That would be great, should fix my problem!


#254

@IoTmessenger @M203

Added the ability to configure host and port manually for Plex component.


#255

Confirmed working! That was indeed the solution for my problem.
Thanks for the quick fix!
:slight_smile:


#256

I’m getting the below error. I tried with both the token and setting the IP/port manually.

2018-11-13 20:39:49 ERROR (MainThread) [homeassistant.components.sensor] plex_recently_added: Error on device update! Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 251, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update await self.hass.async_add_executor_job(self.update) 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 201, in update self.api_json += sub_sec.json()['MediaContainer']['Metadata'] KeyError: 'Metadata' 2018-11-13 20:39:49 INFO (MainThread) [homeassistant.setup] Setup of domain group took 3.6 seconds. 2018-11-13 20:39:49 INFO (MainThread) [homeassistant.setup] Setting up light 2018-11-13 20:39:49 INFO (MainThread) [homeassistant.setup] Setup of domain light took 0.0 seconds. 2018-11-13 20:39:49 INFO (MainThread) [homeassistant.loader] Loaded light.mqtt_json from homeassistant.components.light.mqtt_json 2018-11-13 20:39:50 INFO (MainThread) [homeassistant.components.light] Setting up light.mqtt_json 2018-11-13 20:39:50 INFO (MainThread) [homeassistant.components.light] Setting up light.mqtt_json 2018-11-13 20:39:51 INFO (SyncWorker_3) [plexapi] Testing 4 resource connections.. 2018-11-13 20:39:51 INFO (SyncWorker_3) [plexapi] Resource connection OK (0s): https://192-168-1-17.170a0bb840e34000a1f97a582442389e.plex.direct:32400?X-Plex-Token=&lt;hidden&gt; 2018-11-13 20:39:51 INFO (SyncWorker_3) [plexapi] Resource connection OK (0s): https://99-249-82-50.170a0bb840e34000a1f97a582442389e.plex.direct:32413?X-Plex-Token=&lt;hidden&gt; 2018-11-13 20:39:51 INFO (SyncWorker_3) [plexapi] Resource connection OK (0s): http://192.168.1.17:32400?X-Plex-Token=&lt;hidden&gt; 2018-11-13 20:39:51 INFO (SyncWorker_3) [plexapi] Resource connection OK (0s): http://99.249.82.50:32413?X-Plex-Token=&lt;hidden&gt; 2018-11-13 20:39:51 INFO (SyncWorker_3) [plexapi] Connecting to Resource: https://192-168-1-17.170a0bb840e34000a1f97a582442389e.plex.direct:32400?X-Plex-Token=&lt;hidden&gt;


#257

Do you see anything if you go here in a browser:

https://[plex_ip]:[plex_port]/library/sections?X-Plex-Token=[plex_token]


#258

No the page is blank


#260

Can’t connect to the api. Go here and make sure you see the address of your “Plex Media Server”. Is it the same address and port you’re using?

https://plex.tv/pms/resources.xml?includeHttps=1&X-Plex-Token=[plex_token]

Is the default HA plex component able to connect okay?


#261

Also, is your plex server accessible outside your network?


#262

I get the following error: What could it be?

https://ip/local/custom-lovelace/upcoming-media-card/upcoming-media-card.js?v=0.2.9:19:45 TypeError: undefined is not an object (evaluating 'json[0]['icon']')

my config:

      - type: custom:card-modder
        card:
          type: custom:upcoming-media-card
          service: radarr
          image_style: fanart
          locale: he-IL
          clock: 24
          max: 2

        style:
          background-image: url("/local/lovelace/background/cardbackK.png")
          background-repeat: no-repeat
          background-color: rgba(50,50,50,0.3)
          background-size: 100%
          border-radius: 15px
          border: solid 1px rgba(100,100,100,0.3)
          box-shadow: 3px 3px rgba(0,0,0,0.4)

#263

Does it work outside of card-modder? Also, locale is automatically detected now, you can remove that bit.


#264

I just started using this! Great work, a really awesome addition. I’m using it with the plex component, and am a bit confused about the $release. All of the movies show 25/01 and the tv episodes show 18/01. Is this because of something in Plex’s api? Some of the tv episodes I know got downloaded this week.
Also, care to shre the api documentation for plex that you used? Was thinking it would be nice to have a sensor for On deck as well, not only recently added.


#265

Sure, so release is a line item that is formatted by the component so for radarr it changes dynamically like: “In Theaters Mon, 10/31” if it’s a theater release and more than a week away or “Available Monday” if it’s a physical release and within a week.

For Plex it should just show you something like “Monday, 10/31 10:00 PM” as the date of download. Unsure why your’s shows the wrong date, but we can investigate by getting your api info with:

https://[plex_ip]:[plex_port]/library/recentlyAdded?X-Plex-Token=[plex_token]

I actually have to do a fair few api calls to Plex. Each library (TV, Movies) has its own section number so I grab

https://[plex_ip]:[plex_port]/library/sections?X-Plex-Token=[plex_token]

to get all the sections on your server as Plex gives more info if you look at recently added for the sections separately. Then I grab the info for each sections recently downloaded:

https://[plex_ip]:[plex_port]/library/sections/[section_number]/recentlyAdded?X-Plex-Token=[plex_token]

I get these with a request for a json response in the headers (normally it’s xml and I find json easier to work with).

Unfortunately, there is no official api documentation. I mainly just scoured the plex forums, found similar projects on github, and the Unofficial Plex API Documentation is a huge help.


#266

If your plex server is available remotely, i call:

https://plex.tv/api/servers.xml?X-Plex-Token=[token]

to find your server IP, local IP, and port

I will eventually have to make separate API calls for each TV episode as even the TV sections recently added response is lacking in info like: genres, rating, and studio


#267

I also tried the plex and the same error.