Philips Android TV component

Dear all,

I use the Philips Andoid TV component with a Philips PUS7304. Nearly everything works smoothly except detection of the ON and OFF state of the TV. While the TV is actually OFF, this is detected properly in Home Assistant.

However, when the TV is ON, there is some fluctuation between ON and OFF - see screenshot - even though the TV is ON continuously.

image

Moreover, it seems that whenever the TV state erroneously is detected as OFF there is also an error in the log file - see below.

2020-01-30 21:35:54 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
    self._async_write_ha_state()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 327, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/media_player/__init__.py", line 811, in state_attributes
    for attr in ATTR_TO_PROPERTY
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/media_player/__init__.py", line 812, in <dictcomp>
    if getattr(self, attr) is not None
  File "/home/homeassistant/.homeassistant/custom_components/philips_android_tv/media_player.py", line 125, in volume_level
    return self._volume / self._max_volume
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'type or paste code here

One of the things I want to do by including the TV into Home Assistant is an automation that automatically dims the room when the TV is playing, i.e. ON, and returns the room to regular brightness when the TV is switched OFF. With the intermittent ON and OFF states my Lights continuously change their brightness level.

Any advice is much appreciated.

With regards,
Airhead

@gyrga Awesome find. Will try to integrate this better method of powering on the TV. In the future please add such suggestions to the Github page, helps me keeping track.

@Airhead1234 There are definitly some errors here, which shouldn’t happen. Please also add this to the Github issues in the future.
Also funny my bad programming makes your lights go crazy :see_no_evil: Sorry for that

Also, in April I will be back and be able to try stuff out with my philips TV again.
Until then please bear with no updates (or make changes yourself!)

3 Likes

Since a few weeks my wake on lan isnt working anymore it is enabled on the tv but still get the error:
2020-02-07 08:37:03 WARNING (SyncWorker_2) [custom_components.philips_android_tv.media_player] TV WakeOnLan is not working. Check mac address and make sure TV WakeOnLan is activated. If running inside docker, make sure to use host network.

any idea how to fix this?

Nevermind apprently i changed from WIFI to LAN a few weeks ago. and i didnt change my mac adres in my configuration…

Dear all,

there is an option in the TV where I can turn off the screen (only the screen). How can I do it from this HA component? Is it possibile?

Thank you fow your answers! :slight_smile:

Very likely not possible.

If there is a key, you can sent that key to the TV.

If there is an option in the Philips App it could be possible, if there is not, no way.

FYI, I had to change the above, to get it working again.
(model is from 2015)

Not sure you got the answer on your question regarding the error [custom_components.philips_android_tv.media_player] TV is not returning JSON. Either the authentification failed or your TV does not support calling channeldb/tv/channelLists/all. I got the same and tried to add

hide_channels: true

to the configuration and that at least removed my errors in the logs

1 Like

Did you get far with using the API for the “55PUS6262/05” ? Did you ever try to pair it and if you did, was it worth it ? Any new features ? The inability to change the source is a pain for me.

Anyone any idea how i should get this working with model 50PUK6809/12 (from April 2015)?

Well try to get it working :wink:

You can start by using this:

1 Like

Thanks @pgreberg, that seems to work.

Is it also possible to see the component in home assistant?
Personally I did not have any succes, although it works flawlessly in home assistant itself

Problem now resolved for me. Thank you @nstrelow!

Hi everyone,
I have a 55POS9002 OLED TV bought in 2018.
I’m trying to pair the TV but I’m stuck : I get a “Connection refused” error.

Do you have some idea for me ? Thx

Model : 55POS9002
Firmware : TPM171E_R.107.001.101.002

Starting pairing request
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 171, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/connection.py", line 79, in create_connection
    raise err
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/connection.py", line 69, 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 "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 314, in connect
    conn = self._new_conn()
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 180, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0xb62f6d30>: 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 "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.0.55', port=1926): Max retries exceeded with url: /6/pair/request (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb62f6d30>: 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 "philips.py", line 123, in <module>
    main()
  File "philips.py", line 90, in main
    pair(config)
  File "philips.py", line 41, in pair
    r = requests.post("https://" + config['address'] + ":1926/6/pair/request", json=data, verify=False)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 513, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='192.168.0.55', port=1926): Max retries exceeded with url: /6/pair/request (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb62f6d30>: Failed to establish a new connection: [Errno 111] Connection refused',))
pi@raspberrypi:~ $ python3 philips.py --host 192.168.0.55 pair
Starting pairing request
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 171, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/connection.py", line 79, in create_connection
    raise err
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/connection.py", line 69, 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 "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 314, in connect
    conn = self._new_conn()
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 180, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0xb6300d30>: 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 "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.0.55', port=1926): Max retries exceeded with url: /6/pair/request (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb6300d30>: 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 "philips.py", line 123, in <module>
    main()
  File "philips.py", line 90, in main
    pair(config)
  File "philips.py", line 41, in pair
    r = requests.post("https://" + config['address'] + ":1926/6/pair/request", json=data, verify=False)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 513, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='192.168.0.55', port=1926): Max retries exceeded with url: /6/pair/request (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb6300d30>: Failed to establish a new connection: [Errno 111] Connection refused',))

Sorry to reply on an old comment, but I had some trouble myself too. During initial setup using https://github.com/suborb/philips_android_tv I got an error ‘connection refused 111’. Restarted the TV, no difference. Just before trying to do a factory reset, I realised I had also just installed the Android TV remote app on my phone, which I then disabled. And voilà: pairing succesful!

So, I seems that the API only accepts one connection at a time?

Anyway, I thought I would post this here for future reference…

Hi,
i have 55PUS6703 with same issue. Did you mange to solve your problem?

Sadly, I didn’t manage to make it work.
I’m still waiting for some help.

Hi Meyer,

I am still struggling but had the following two observations:

  1. By examining the network traffic from the “Philips Remote” app om my phone, I figured out that my tv runs on port 1925 instead of 1926. I replaced 1926 by 1925 the 4 places In the “philips.py” file and the connection error disappeared. So this might solve your problem.
  2. But I started facing other issues that I think are related to which version combination you are running: Python, OpenSSL, Requests and pycrypto. As I saw error regarding encryption, protocol etc. And post om the internet mentioning that you need specific combinations but these are now outdated as for example I couldn’t run python version 2.6 as it is not supported any mor. I hope someone can tell about a still running set up with which versions.

Even though I still can’t pair, I can for example use this address in a browser “http://192.168.0.61:1925/6/audio/volume” to fetch the volume from the TV. So I can communicate with the TV without pairing and using username and password. I am therefor trying to run the Philips_2014 custom component that runs without. I just saw that it seams to work but with very limited functionality, power on/off and controlling the volume.

I’ll continue my research and look forward to hear where changing the port number solved your issue.

I’ll post any progress and other observations :blush:

Hi Meyer,

Good news, I think i figured it out :blush:

This component is designed for android OS but not all Philips TVs run android and need pairing with username and password.

try the following: From a computer on the same network as your tv, in a browser go to

http://:192.168.0.55:1925/1/system and http://:192.168.0.55:1926/1/system

Hopefully one will return access denied and the other will return response with data.

if you get the response data, at the bottom you should see system feature. mine returns the following:

“pairing_type”: “none”,

“os_type”: “Linux”

therefor no need for username and password.

in this case you need to edit the medai_player.py file in the custom component in Hassio and replace all https by http and probably 1926 by 1926 depending on which url gave you a response with data

But make the first verification step and let me know, then I can guide you through the next steps

/Ghassan

1 Like