Plex Sensor error

My error log is showing the following when attempting to start the plex sensor…

16-06-22 08:36:23 homeassistant.components.sensor: Error while setting up platform plex
Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 142, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/srv/hass/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 91, in create_connection
    raise err
  File "/srv/hass/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 81, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 98, in _setup_platform
    discovery_info)
  File "/home/hass/.homeassistant/custom_components/sensor/plex.py", line 30, in setup_platform
    add_devices([PlexSensor('Plex', plex_user, plex_password, plex_url)])
  File "/home/hass/.homeassistant/custom_components/sensor/plex.py", line 40, in __init__
    self._auth_token = self.getAuthToken(plex_user, plex_password)
  File "/home/hass/.homeassistant/custom_components/sensor/plex.py", line 66, in getAuthToken
    response = requests.post(auth_url, data=auth_params, headers=headers)
  File "/srv/hass/lib/python3.4/site-packages/requests/api.py", line 111, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/srv/hass/lib/python3.4/site-packages/requests/api.py", line 57, in request
    return session.request(method=method, url=url, **kwargs)
  File "/srv/hass/lib/python3.4/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/srv/hass/lib/python3.4/site-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/srv/hass/lib/python3.4/site-packages/requests/adapters.py", line 421, in send
    low_conn.endheaders()
  File "/usr/lib/python3.4/http/client.py", line 1133, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 963, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 898, in send
    self.connect()
  File "/srv/hass/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 254, in connect
    conn = self._new_conn()
  File "/srv/hass/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 151, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f5cd4094550>: Failed to establish a new connection: [Errno 111] Connection refused

Is your Plex server running on port 32400? If not you’ll need to specify the port in the config.

it is running on 32400

Can you post your sensor config? I’m not using this so I’m not familiar with it but if you’re not running plex on the same machine as HA, it would seem to me that it would be considered a ‘remote server’ and so you’d have to specify the IP, username and password.

I am running it all on the same server

  - platform: plex
    name: Plex Spy
    host: 192.168.0.90
    port: 32400
    username: [redacted]
    password: [redacted]
    server: zeus

Everything looks correct; and most of it is optional since you’re running it on the same server. Sorry I can’t think of anything else; hopefully someone else will weigh on on the topic.

In your Plex Server settings, on Network, do you have secured connections activated? Maybe that’s the problem and the reason you get the connection refused error.

It was set to preferred, so I changed it to disabled. Still refusing connection.

Are you using some kind of cert for https connections? I see an HTTPS in the log.
Sorry not being so helpful, I don’t use plex sensor, just trying to help :wink:

I appreciate the help and I did at one point attempt to setup Let’s Encrpt but couldn’t get it working. Might be something left of that hanging around. Haaska did start working out of the blue.

When setting up Let’s Encrypt, did you redirect your port 443 to 8123? Maybe that’s still in the router?

443 is directed to 192.168.0.90:443

If you never got Let’s Encrypt working, then 443 shouldn’t be directed to anything. It should jsut be pass through on your router. If you got LE working, you would pass 443 to port 8123 on the device running your HA instance.

This might be part of your issue.

Bump! Getting the exact same thing. Nothing has changed my end, it’s been working ever since I started playing with Home Assistant, but today I restarted to reload some new automations, and am constantly getting this error.

2017-10-10 14:00:46 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform plex
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/util/connection.py", line 83, in create_connection
    raise err
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 844, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 284, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x73ca7b90>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 438, in send
    timeout=timeout
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='my.plexapp.com', port=443): Max retries exceeded with url: /users/sign_in.xml (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x73ca7b90>: Failed to establish a new connection: [Errno 111] Connection refused',))

My plex server says it’s seen homeassistant about 20 hours ago. I’ve restarted HA / rebooted the pi countless times.

Did you ever fix it?

  - platform: plex
    host: my.remote.plex.com
    port: 32400
    name: theserver
    username: myusername
    password: "password"

Fixed.

my.plexapp.com had started being blocked by pi-hole.

Not sure why they might do this, but it’s easy enough to get around. If you go to the Dashboard for Pi-hole, click on Query Log and then search for “plexapp”, you can then click on Whitelist. And you are done! You might have to wait a bit for it to become available, or simply restart Pi-hole.