Philips Android TV component

An ambilight+hue toggle would be great! I would happily test an updated component with my PUS7101/12 :slight_smile:

Glad to test this too on a POS9002.

I have a 9002. Would love to have it in home assistant.

Does anyone here have a 9002 and the a working ambilight component.

I would be glad to test.

Hey guys, I’ve decided to document all API endpoints and to create a better python tool to control Philips TVs. You can find an unofficial API reference and the tool (both are ‘work-in-progress’) here: https://github.com/eslavnov/Pylips (comments are welcome!)

It’s far from being done and it’s not a home assistant component (yet), but it already supports turning ‘Ambilight + Hue’ on and off:
python pylips.py --host %ip_address% --user %username% --pass %password% --command ambihue_on
python pylips.py --host %ip_address% --user %username% --pass %password% --command ambihue_off

You can use it through a script/switch entity in Home Assistant…

If this works for you, please share your TV model! Thank you in advance!

4 Likes

great module, reminds me a lot of the one from suborb, just cleaner and with more amilight options.
When I find the time I will build a python module, which can be extended on for ambilight and media player components.

@nstrelow i get this error:
python3 philips_2016.py --host 192.168.1.28 pair
Traceback (most recent call last):
File “philips_2016.py”, line 2, in
import homeassistant.helpers.config_validation as cv
ModuleNotFoundError: No module named ‘homeassistant’
tilen-4:~ tilenmatejcervek$ python3 philips.py --host 192.168.1.28 pair
Starting pairing request
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/connection.py”, line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/util/connection.py”, line 83, in create_connection
raise err
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/util/connection.py”, line 73, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/connectionpool.py”, line 600, in urlopen
chunked=chunked)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/connectionpool.py”, line 345, in _make_request
self._validate_conn(conn)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/connectionpool.py”, line 844, in _validate_conn
conn.connect()
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/connection.py”, line 284, in connect
conn = self._new_conn()
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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 0x10631fa90>: Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py”, line 423, in send
timeout=timeout
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/connectionpool.py”, line 649, in urlopen
_stacktrace=sys.exc_info()[2])
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/packages/urllib3/util/retry.py”, line 376, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘192.168.1.28’, port=1926): Max retries exceeded with url: /6/pair/request (Caused by NewConnectionError(’<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x10631fa90>: Failed to establish a new connection: [Errno 61] Connection refused’))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “philips.py”, line 123, in
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 “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py”, line 110, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py”, line 56, in request
return session.request(method=method, url=url, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py”, line 488, in request
resp = self.send(prep, **send_kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py”, line 609, in send
r = adapter.send(request, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py”, line 487, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘192.168.1.28’, port=1926): Max retries exceeded with url: /6/pair/request (Caused by NewConnectionError(’<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x10631fa90>: Failed to establish a new connection: [Errno 61] Connection refused’))

or this in hassio:
core-ssh:~# /config/custom_components/media_player/philips_2016.py --host 192.168.1.28 pair

/config/custom_components/media_player/philips_2016.py: line 1: Philips TV: command not found

/config/custom_components/media_player/philips_2016.py: line 2: import: command not found

/config/custom_components/media_player/philips_2016.py: line 3: import: command not found

/config/custom_components/media_player/philips_2016.py: line 4: import: command not found

/config/custom_components/media_player/philips_2016.py: line 5: import: command not found

/config/custom_components/media_player/philips_2016.py: line 6: import: command not found

/config/custom_components/media_player/philips_2016.py: line 7: import: command not found

/config/custom_components/media_player/philips_2016.py: line 8: import: command not found

/config/custom_components/media_player/philips_2016.py: line 9: import: command not found

/config/custom_components/media_player/philips_2016.py: line 10: import: command not found

/config/custom_components/media_player/philips_2016.py: line 11: import: command not found

/config/custom_components/media_player/philips_2016.py: line 13: from: command not found

/config/custom_components/media_player/philips_2016.py: line 14: from: command not found

/config/custom_components/media_player/philips_2016.py: line 15: syntax error near unexpected token `(’

/config/custom_components/media_player/philips_2016.py: line 15: `from homeassistant.components.media_player import (SUPPORT_STOP, SUPPORT_PLAY, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE,’

core-ssh:~# /config/custom_components/media_player/philips.py --host 192.168.1.28 pair

/config/custom_components/media_player/philips.py: line 1: from: command not found

/config/custom_components/media_player/philips.py: line 2: from: command not found

/config/custom_components/media_player/philips.py: line 3: from: command not found

/config/custom_components/media_player/philips.py: line 4: import: command not found

/config/custom_components/media_player/philips.py: line 5: import: command not found

/config/custom_components/media_player/philips.py: line 6: import: command not found

/config/custom_components/media_player/philips.py: line 7: import: command not found

/config/custom_components/media_player/philips.py: line 8: import: command not found

/config/custom_components/media_player/philips.py: line 9: from: command not found

/config/custom_components/media_player/philips.py: line 10: from: command not found

/config/custom_components/media_player/philips.py: line 11: import: command not found

/config/custom_components/media_player/philips.py: line 20: syntax error near unexpected token `def’

/config/custom_components/media_player/philips.py: line 20: `def createDeviceId():’

core-ssh:~#

Since the API does not support switching input sources anymore, I’ve made a small script that utilizes ADB to do it: https://github.com/eslavnov/android-tv-remote

python3 pylips.py --host 192.168.1.28

Would you like to pair with your TV? [Y/n]y

Starting pairing request

resending pair request

resending pair request

resending pair request

resending pair request

resending pair request

resending pair request

resending pair request

resending pair request

resending pair request

The API is unreachable. Try restarting your TV and pairing again

Can you please copy and paste what you see if you go to https://192.168.1.28:1926/6/system in your browser?

If you don’t see anything in the browser then either the ip address is wrong or your TV does not support this API. What’s your TV model?

safari can not connect to server, tv is: 55PUS6262

This model should be supported, but if you see nothing in the browser it means the API is not working for some reason… Could it be a mistake in the ip address? What happens if you try to ping it?

@gyrga

ping 192.168.1.28

PING 192.168.1.28 (192.168.1.28): 56 data bytes

64 bytes from 192.168.1.28: icmp_seq=0 ttl=64 time=2.621 ms

64 bytes from 192.168.1.28: icmp_seq=1 ttl=64 time=7.420 ms

64 bytes from 192.168.1.28: icmp_seq=2 ttl=64 time=23.769 ms

64 bytes from 192.168.1.28: icmp_seq=3 ttl=64 time=54.842 ms

64 bytes from 192.168.1.28: icmp_seq=4 ttl=64 time=3.243 ms

64 bytes from 192.168.1.28: icmp_seq=5 ttl=64 time=2.541 ms

64 bytes from 192.168.1.28: icmp_seq=6 ttl=64 time=3.975 ms

64 bytes from 192.168.1.28: icmp_seq=7 ttl=64 time=4.487 ms

^C

— 192.168.1.28 ping statistics —

8 packets transmitted, 8 packets received, 0.0% packet loss

round-trip min/avg/max/stddev = 2.541/12.862/54.842/17.190 ms

P.S.
I get forbbiden tex on site if open 192.168.1.28:1925 in browser

That’s very strange, hmmm…

What happens if you go to http://192.168.1.28:1925/system ? (notice it’s a bit different that the last link and it’s http this time, not httpS)

Again just this tex on blank site: Forbbiden

That’s extremely weird: your TV’s API does not seem to behave like the others… Does the official iOS/Android Philips Remote app work for you? It uses the same API, so if it works it’s likely a problem with your network config… If it does not work, then I am afraid your TV does not support this API (which would be surprising to me) or it’s somehow broken…

Also, (you’ve probably tried this before) you could try unplugging your TV for 30 seconds, then plugging it in again: sometimes the API just hangs for no reason and this helps to restart it.

@gyrga sorry for late answer, the ios app find the tv in moment, remote works and light options also in ios app. So the API must work!? Have also restarted the tv

Yeah, if the Philips app works it means the API is working too, but I don’t get why you can not access it through browser or python tools… I am really lost at this point, sorry!

@gyrga i got something with ip:1925/1/system:
{
“menulanguage”: “Slovenian”,
“name”: “55PUS6262/12”,
“country”: “Slovenia”,
“serialnumber_encrypted”: “xxxx”,
“softwareversion_encrypted”: “xxxx”,
“model_encrypted”: “xxxx”,
“deviceid_encrypted”: “xxxx”,
“nettvversion”: “4.6.0”,
“epgsource”: “broadcast”,
“api_version”: {
“Major”: 6,
“Minor”: 1,
“Patch”: 0
},
“featuring”: {
“jsonfeatures”: {
“recordings”: [
“List”,
“Schedule”,
“Manage”
],
“ambilight”: [
“LoungeLight”
],
“textentry”: [
“context_based”,
“initial_string_available”
],
“inputkey”: [
“key”,
“unicode”
],
“pointer”: [
“context_based”
],
“activities”: [
“browser”
]
},
“systemfeatures”: {
“tvtype”: “consumer”,
“content”: [
“dmr”
],
“pairing_type”: “none”,
“os_type”: “Linux”
}
}
}

Thanks, this is useful! I see two major differences from my output:

  1. You are running API version 6.1, while I have a version 6.2. I would expect that since the major version is the same (6), everything should work, but it does not seem to be the case.
  2. Your “pairing_type” is “none”, while mine is “digest_auth_pairing” - that’s probably why the pairing script does not work for you.

So, right now it seems that your API behaves differently from the others. I have a theory to test: could you please go to http://ip:1925/1/audio and share the output? This does not work on API 6.2, but might work for you - then I will be able to help you…

Isn’t there a setting to enable the use of the API?

@warcanoid What did you to to set up the Philips TV Remote App? Did you press Pair, and there was a PIN on the TV, which you put in the app?