❱ Plex Assistant

Wasn’t the grey screen stuff in the readme regarding the cast delay??
https://github.com/maykar/plex_assistant#cast-delay

Oh yes, I forgot to mention I’ve adjusted the cast delay all the way up to 60 seconds and it still exhibits the same behavior.

Sharing any errors is always helpful and when you share code blocks (here on the forums, github, discord, etc) always use three backquotes ``` before and after your code so that it is formatted correctly and any errors are easier to see.

The amount of delay needed is typically the time it takes from when the screen turns black after calling the service to when you see the show info on screen.

Does your system take 60 seconds to get to this point? Typically I would say you’d never need over 10 and you can start a zero.

The instructions seem fairly straight forward yet still having issues?
Running Hass docker (non hass.io/hacs)
went to /config and create /custom_components/plex_assistant and then git clone https://github.com/maykar/plex_assistant.git
Was this correct? Is there perms issue?
now my file structure is homeassistant/config/custom_components/plex_assistant/custom_components/plex_assistant?
My PMS is set on secure connections only is that a problem?
when i try to goto https:ip:32400 plex asks if authorize but I assume your component is passing the token)

plex_assistant:
  url: !secret plex_url
  token: !secret plex_token
  default_cast: 'Living Room Chromecast'
  language: 'en'
  tts_errors: true


Keep getting this in my sensor.yaml file:
Platform error sensor.plex_assistant - Integration ‘plex_assistant’ not found.
Component error: plex_assistant - Integration ‘plex_assistant’ not found.Preformatted text

Thanks for the tip, I’m new here…obviously :slight_smile: . Any idea what I might be doing wrong?

Does your system take 60 seconds to get to this point? Typically I would say you’d never need over 10 and you can start a zero.

Thanks, that worked. I started with 6 seconds and went up incrementally 1s until I got to 30 then 10s intervals after. I never though to try fewer seconds… 3s is the sweet spot for me.

Now I just have the problem of it always playing S1E1 of Ozark instead of what I ask for.

Add the code below to your configuration.yaml and restart. Then look at your full logs for the debug info. Might help diagnose what’s going on.

logger:
  logs:
    custom_components.plex_assistant: debug
  2020-07-13 11:22:12 ERROR (MainThread) [homeassistant.setup] Error during setup of component plex_assistant
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 976, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 396, in connect
    _match_hostname(cert, self.assert_hostname or server_hostname)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 406, in _match_hostname
    match_hostname(cert, asserted_hostname)
  File "/usr/local/lib/python3.7/ssl.py", line 338, in match_hostname
    % (hostname, dnsnames[0]))
ssl.SSLCertVerificationError: ("hostname 'x.x.x.x' doesn't match '*.876efxxb17fxxxxxxxxaf8.plex.direct'",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='x.x.x.x', port=32400): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError("hostname 'x.x.x.x' doesn't match '*.876ef40xxxxxxxxx8499e13062d0baf8.plex.direct'")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 193, in _async_setup_component
    result = await asyncio.wait_for(task, SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/plex_assistant/__init__.py", line 83, in setup
    PA.server = PlexServer(base_url, token)
  File "/usr/local/lib/python3.7/site-packages/plexapi/server.py", line 110, in __init__
    data = self.query(self.key, timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/plexapi/server.py", line 432, in query
    response = method(url, headers=headers, timeout=timeout, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='x.x.x.x', port=32400): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError("hostname 'x.x.x.x' doesn't match '*.876ef40bxxxxxe13062d0baf8.plex.direct'")))

@kilroyma You say that it “just errors out”, but you don’t provide any error for me to diagnose, which is why I asked for the error in my previous post (check your HA logs).

@vulcanjedi You’ve enabled SSL in plex and are trying to access it using a different address than is specified in the certificate. Either use the address that the certificate is for in your Plex Assistant config or “Allow insecure connections” in Plex’s settings and use http not https.

I actually have Ombi setup.
From its config I recall there was another URL
so i managed to get to load the component with
'https://xxx-xxx-xxx-xxx.876eadsafasdfadadsfasfdsfasfd33d20ahash.plex.direct:32400"
The logs show all my cast devices but the sensor only shows one.

Even after updating the sensor? It can sometimes take 10-20 seconds for it to update after you call it. Are these chromecast devices or plex devices?

@mayker
Sorry again. Here are the error logs:

2020-07-13 08:43:39 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for plex_assistant which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-07-13 08:43:41 ERROR (MainThread) [homeassistant.setup] Error during setup of component plex_assistant
Traceback (most recent call last):
  File "c:\program files (x86)\python38-32\lib\site-packages\homeassistant\setup.py", line 193, in _async_setup_component
    result = await asyncio.wait_for(task, SLOW_SETUP_MAX_WAIT)
  File "c:\program files (x86)\python38-32\lib\asyncio\tasks.py", line 483, in wait_for
    return fut.result()
  File "c:\program files (x86)\python38-32\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\mattb\AppData\Roaming\.homeassistant\custom_components\plex_assistant\__init__.py", line 83, in setup
    PA.server = PlexServer(base_url, token)
  File "C:\Users\mattb\AppData\Roaming\.homeassistant\deps\Python38\site-packages\plexapi\server.py", line 110, in __init__
    data = self.query(self.key, timeout=timeout)
  File "C:\Users\mattb\AppData\Roaming\.homeassistant\deps\Python38\site-packages\plexapi\server.py", line 440, in query
    raise NotFound(message)
plexapi.exceptions.NotFound: (404) not_found; http://127.0.0.1/:32400/ <html>
 <head><title>404 Not Found</title></head>
 <body bgcolor="white">
 <center><h1>404 Not Found</h1></center>
 <hr><center>nginx/1.6.2</center>
 </body>
 </html>
 
2020-07-13 08:43:41 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform plex_assistant.sensor: Unable to set up component. 

Look like sensor pulling in more now, but the google command doesnt do anything. Just checked the log and getting this;

Logger: homeassistant.components.automation
Source: custom_components/plex_assistant/helpers.py:42
Integration: Automation (documentation, issues)
First occurred: 12:21:21 PM (2 occurrences)
Last logged: 12:23:00 PM

Plex Assistant Automation: Error executing script. Unexpected error for call_service at pos 1: generator raised StopIteration
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/fuzzywuzzy/process.py", line 93, in extractWithoutOrder
    raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 153, in _async_step
    self, f"_async_{cv.determine_script_action(self._action)}_step"
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 656, in _async_call_service_step
    *self._prep_call_service_step(), blocking=True, context=self._context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1299, in _execute_service
    await self._hass.async_add_executor_job(handler.func, service_call)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/plex_assistant/__init__.py", line 127, in handle_input
    command = process_speech(command_string, localize, default_cast, PA)
  File "/config/custom_components/plex_assistant/process_speech.py", line 25, in process_speech
    fuzz_client = fuzzy(control_check, devices)
  File "/config/custom_components/plex_assistant/helpers.py", line 42, in fuzzy
    return fw.extractOne(media, lib, scorer=scorer)
  File "/usr/local/lib/python3.7/site-packages/fuzzywuzzy/process.py", line 245, in extractOne
    return max(best_list, key=lambda i: i[1])
RuntimeError: generator raised StopIteration

@kilroyma Did your config change from what you posted before? You posted that you’re using the url http://192.168.1.75:32400, but the error shows that you are using http://127.0.0.1/:32400/, which has a typo in it, there should be no slash before the colon.

@vulcanjedi Will look into it when I can

Oops, I was just messing around with stuff and changed it. It was giving the same error regardless. Here it is with the url fixed.

2020-07-13 10:30:44 WARNING (MainThread) [homeassistant.setup] Setup of plex_assistant is taking over 10 seconds.
2020-07-13 10:31:26 ERROR (MainThread) [homeassistant.setup] Error during setup of component plex_assistant
Traceback (most recent call last):
  File "c:\program files (x86)\python38-32\lib\site-packages\homeassistant\setup.py", line 193, in _async_setup_component
    result = await asyncio.wait_for(task, SLOW_SETUP_MAX_WAIT)
  File "c:\program files (x86)\python38-32\lib\asyncio\tasks.py", line 483, in wait_for
    return fut.result()
  File "c:\program files (x86)\python38-32\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\mattb\AppData\Roaming\.homeassistant\custom_components\plex_assistant\__init__.py", line 85, in setup
    PA.lib = get_libraries(PA.plex)
  File "C:\Users\mattb\AppData\Roaming\.homeassistant\custom_components\plex_assistant\helpers.py", line 27, in get_libraries
    movies.sort(key=lambda x: x.addedAt)
TypeError: '<' not supported between instances of 'NoneType' and 'datetime.datetime'
2020-07-13 10:31:26 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform plex_assistant.sensor: Unable to set up component.

but that’s a completely different error…

Either way, it looks like there is a movie in your collection that doesn’t have an addedAt attribute. This is confusing as everything added to plex gets this attribute, but this is something that I can fix or at least put a band-aid on. Will see about getting it in the next release.

Thank you. Sorry I’m dumb :slight_smile:

I’m having a little trouble with my Plex Clients. I have one running on 192.168.0.10 (as in my config) however, it only shows me the Galaxy S6 edge (which is no longer running).

Any Ideas?

Also how do I do the ‘update sensor’ in HASSIO ? (Might save me a reboot or 2)

Thanks. :slight_smile:

  Cast Devices:
    - Kitchen Magic
    - Cellar mini
    - Bathroom speaker
    - Bedroom TV
    - Cellar speaker
    - Kitchen display
    - Living room Home
    - Ground Floor
    - The whole house
    - Magic TV
    - Melissa's abode speaker
    - Bedroom speaker
  Plex Clients:
    - Galaxy S6 Edge:
        ID: 8dd349727c529d1b-com-plexapp-android
        type: Plex for Android (Mobile)
friendly_name: Plex Assistant Devices

and

plex_assistant:
  url: 'http://192.168.0.10:32400'
  token: !secret plex_key
  default_cast: 'Magic TV'
  language: 'en'
  tts_errors: true
  aliases:
    Magic TV: magic_tv
    Kitchen Display: kitchen_display
  cast_delay:
    Magic TV: 8

OK, now the Samsung has gone and I’m left with no Clients at all :frowning:

Clients are grabbed from Plex’s API, you can see what Plex is reporting by going to PLEX-IP-AND-PORT/clients?X-Plex-Token=YOUR-PLEX-TOKEN

Plex, unfortunately, doesn’t update this quickly. As you’ve seen, it takes some time for something to clear the list after it’s disconnected and it also takes some time for it to show up. To update your sensor use your Google Assistant phrase followed by “update sensor”. Example "Hey, Google, tell plex to update sensor."