Is Plex integration broken?

I literally just had the same thing happen, had some sensors that were unavailable and the integration wasn’t finding a second plex server so I removed it, removed the authorized device and tried to reinstall and ran into the same problem getting a token from plex. Updated, restarted, but still doesn’t work. Haven’t tried the manual setup yet.

Hi, is there any news on this? it was working fine on 0.116, this is the plex sensor was always notifying 0 if it was off or no one playing, and now when the server is off the sensor does not even exist so If you request state it return “UNKNOWN” this has broken some automations on my side…

Please Help!!!

Cheers

Same issue here, would love an update.

Sounds like a bug - maybe enter an issue for it.

Issue reported https://github.com/home-assistant/core/issues/42912

1 Like

I haven’t looked at this in a long time but my solution to plex I think was to use

I dug around in my setup and I can’t figure out how its working but I know it changes the lights based on the type of content being watched and the time of day. It works in real time based on pause/play. I have the above URL in my notes so and I’m pretty sure I remember that the plex integration was not real-time which is why MQTT was needed.

EDIT. Oops. Looks like the newer plex integration fixes the real-time issue according to Plex + Webhooks (WIP) - #28 by jjlawren

  1. The authentication issue seems to be caused by a change on the Plex side. I’m working to find out what changed and how we can fix it.
  2. The sensor will show “unavailable” when the Plex server is unreachable. Since 0.116 the behavior is to unload the integration while we try to reconnect. Once the Plex server comes back online it will reconnect automatically.

If your Plex server is running but you’re still seeing the sensor is “unavailable”, please create a Github issue and I’ll investigate further. It should always show a count if the server is running.

I’m pretty sure I remember that the plex integration was not real-time

The Plex integration has used realtime updates via websockets for about a year now, since 0.101.

hi, but in the past if it was unavailable (server down) and I request the state of sensor.plex the returned value was 0 and this was OK.

The problem is that if the server is down now the returned value is Unknown.

Thanks for your help.

Cheers

Correct, that has changed.

I assume this is breaking some template entities or automations. Share what you have and I can try to help fix them.

Ok I Have an automation to run after midnight to turn off my NAS, the conditions are:
Shield must be off
Backups server must be off
and no one should be playing anything from plex ( so in the past it was as easy just to check that Plex.sensor state was cero “0”)

if this 3 conditions were true then the server can safely shut down and if not it will keep checking every 15 minutes.

this automation is not working now because if plex is down or plex is up but no player is connected it returns “Unknown”, it only returns state 0 if a player is connected but not playing anything.

I hope this makes sense

Cheers

Yep, make sense. You should be able to add the ‘unavailable’ state into the condition check for the Plex sensor. This will then match when the Plex server is down, or when there are zero active playback sessions:

- condition: state
  entity_id: sensor.plex
  state:
    - 0
    - unavailable

Mmmm Interestting, will try that.

Thx

Fix for the auth issue is available in 0.117.6.

I was having same issue with <0.117 not accepting the auth token. I just updated to 0.118.3 this week and now I’m getting this in the logs when I hit the big red ‘reconfigure’ button in the Integrations page:

2020-11-27 11:51:38 INFO (SyncWorker_9) [plexapi] Testing 6 resource connections..
2020-11-27 11:51:38 ERROR (Thread-6) [plexapi] https://<my_address_1>.plex.direct:32400: HTTPSConnectionPool(host='<my_address_1>.plex.direct', port=32400): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f64a820b580>: Failed to establish a new connection: [Errno -2] Name does not resolve'))
2020-11-27 11:51:38 ERROR (Thread-11) [plexapi] http://<my_address_3>:8443: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
2020-11-27 11:51:41 INFO (SyncWorker_9) [plexapi] Resource connection ERR (0s): https://<my_address_1>.plex.direct:32400?X-Plex-Token=<hidden>
2020-11-27 11:51:41 INFO (SyncWorker_9) [plexapi] Resource connection OK (0s): https://<my_address_2>.plex.direct:32400?X-Plex-Token=<hidden>
2020-11-27 11:51:41 INFO (SyncWorker_9) [plexapi] Resource connection OK (3s): https://<my_address_3>.plex.direct:8443?X-Plex-Token=<hidden>
2020-11-27 11:51:41 INFO (SyncWorker_9) [plexapi] Resource connection OK (0s): http://<my_address_1>:32400?X-Plex-Token=<hidden>
2020-11-27 11:51:41 INFO (SyncWorker_9) [plexapi] Resource connection OK (0s): http://<my_address_2>:32400?X-Plex-Token=<hidden>
2020-11-27 11:51:41 INFO (SyncWorker_9) [plexapi] Resource connection ERR (0s): http://<my_address_3>:8443?X-Plex-Token=<hidden>
2020-11-27 11:51:41 INFO (SyncWorker_9) [plexapi] Connecting to Resource: https://<my_address_2>.plex.direct:32400?X-Plex-Token=<hidden>
2020-11-27 11:51:41 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 160, in get
    return await super().get(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 92, in get
    result = await self._flow_mgr.async_configure(flow_id)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 155, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 213, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/plex/config_flow.py", line 327, in async_step_use_external_token
    return await self.async_step_server_validate(server_config)
  File "/usr/src/homeassistant/homeassistant/components/plex/config_flow.py", line 237, in async_step_server_validate
    self.hass.config_entries.async_update_entry(entry, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 788, in async_update_entry
    if data is not _UNDEF and entry.data != data:  # type: ignore
AttributeError: 'NoneType' object has no attribute 'data'

It tried hitting my plex server using its private internal address, my public IP, and a public IP I assume is owned by Plex. But then it just poos itself. Over in the UI, it says “Please wait while the integration is being installed” and then just hung in a swirling circle.

I figure if I remove the integration and put it back, that might help. But I can’t remove the integration because of the big red ‘reconfigure’ button.

I just updated from 0.118.3 to 0.118.4 and tried again.

The first time I tried hitting ‘reconfigure’, it attempts to connect to plex.tv to pull a token and then redirect a page on my local server to finish the auth. The problem at this point is that it gets the IP address of my local server wrong (it’s putting in an IP for a docker container that is unrelated to plex, which is unsurprisingly not answering on the plex port.)

Subsequent attempts after that throw the above python error.

Have you customized your http: config?

As a workaround you can edit the URL that fails to connect to the docker IP and put in your locally connectable IP. Keep the rest of the path as-is. This should work automatically but something is not working as expected.

I haven’t customized http: config, but have in Plex -> Settings -> Network set server to respond to a specific interface and in Server -> Remote Access have forced the port. Both of those were to ensure Plex remote access worked.

I had tried changing that IP embedded in the URL and it never takes. I’ve pulled the target url from the redirect out, changed the IP, and then gone there, and my plex server tells me it authenticated.

Another thing I noticed (stupid user error) was the big red ‘reconfigure’ button over the plex integration was not the only plex integration tile in the page of Integrations. I didn’t notice it was in there twice. Using the other one I was able to delete the integration, restart HA, and then add it back in. It still tried to send the token to the wrong IP address, but this time when I changed the IP address in the redirect url and hit it again it appears to have accepted the token and is adding entities back in as they turn on.

None of those should make a difference here, unless the port is forwarded from a different port externally.

If I read the rest of your post correctly you’re up and running again?

you’re up and running again?

Yes. It appears to be.

When I installed the integration from scratch, it still tried to go to the wrong IP address. When I changed the IP embedded in the URL, it accepted the token and seems to have linked up correctly. The entities for a couple of key players seems to have changed names, which was just a minor update to the lovelace card to get them back to where they were. Part of me really wants to track down where it is getting the wrong IP from, but now that it is working it a lower priority under other stuff that is still broke.

A couple things to check:

  1. Is the docker instance running in host mode? I believe it must be to be a supported HA installation.
  2. Are you running a reverse proxy?