Philips Android TV component

Copy philips.py from here on your Raspberrry Pi in a folder (i did it while i was logged with homeassistant user)
Run the script
A code will appear on the TV, write it in the console
After that, username and password will be displayed in the console

I’ll do that tonight…
Do I need first to make the script executable?

No, .py extension is from a python script. Just copy the file to the raspberry pi and run the following command (make sure that before running the command you are in the same location where you put the file):

python philips.py --host 192.168.xx.xx pair

(change your ip address with your TV IP address)

You will see a 4digit code on your TV, insert it in the console and after that you should see the username and password

Awesome that people are working on it. I started on a component, but got frustrated the with the API.
It’s such a bummer that it apparently has less functionality and no documentation at all.

Starting apps is possible judging from the Android TV remote app.
GET activities/current
returns
{‘component’: {‘className’: ‘com.google.android.apps.youtube.tv.cobalt.activity.ShellActivity’, ‘packageName’: ‘com.google.android.youtube.tv’}}

POST activities/launch
That payload needs to be send to the TV.
The TV should then execute the following code:
intent.setComponent(new ComponentName(pkgName, classPathToActivity)
So exactly the same thing the get is returning.

But I get a Bad Request 400, when posting it like this.
Source: https://github.com/suborb/philips_android_tv/issues/5

Thanks @an20dei. It’s working now, but it this all it provides out of the box?

grafik

Can it be enhanced / customized somehow?

yeah its pretty limit what you can pull out with the current knowlegde of the API.
lets hope someone are skilled enough to find fix a proper working component :wink:

Hi guys,

Is there anyone who managed to make any progress here?
I manage to pair 55POS9002 and set up the component. It can change the volume and mute/unmute the tv.
However, my biggest disappointment is that it’s not even possible to get correct on/off state of the tv. Does anyone know if it’s possible to at least fix the state?
I read in the manual that it’s possible to request API from the manufacturer. Would someone here be able to implement it?

1 Like

I will put tonight my file (i have modified it a little even i don t know python at all). What is improved:

  • state is retrieved correctly
  • turn off / turn on (because in the initial script if the tv was off there was no button to turn it on)
    Thanks.
3 Likes

Such good news! Where will be possible to find your fIle? Will you post here?

Very good news, so i am also interested in the update Python file … Because the current Philips support in HA isn’t working well with my TV.

Seconding the @Molodax with the same question… Would you be so kind as to share the location you’re going to post / you’e posted your version? Thanks in advance!

Sorry guys,

I was busy and i didn t have time to upload it till now. You can find the file attached, please modify the extension of the file from .xml to .py (i am not able to upload directly .py files here).

This is how it looks for me:

image

image

philips_2016.xml (7.8 KB)

2 Likes

thanks, Andrei!

you are welcome, hope it works for all (i have 55PUS6561 model). I don t have python knowledge, but i think that it can be improved by someone who knows, there are more APIs available in the Philips TV that can be used, i think …

Hi to all! I’ve good news…no very good news, but good news :slight_smile:

After try and retry to pair my android tv (philips 49pus7100/12) with the tools of suborb without success. I’download the iOS app “PhilipsTVRemote” and in the help section, said the uses: JSON: 5.

I’ve modified the suborb python:

r = requests.post(“https://” + config[‘address’] + “:1926/6/pair/request”, json=data, verify=False)

to

r = requests.post(“https://” + config[‘address’] + “:1926/5/pair/request”, json=data, verify=False)

and when I try to pair, the code appear in the TV!!! :slight_smile:

But when I type the code, the pair process ended with the error:

air:philips_android_tv-master kulo4$ python3 philips.py --host 192.168.66.110 pair
Starting pairing request
Enter onscreen passcode: 5611
Attempting to pair
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 60, in pair
print(r.json())
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/models.py”, line 885, in json
return complexjson.loads(self.text, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/init.py”, line 319, in loads
return _default_decoder.decode(s)
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py”, line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py”, line 357, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Any help? Thanks!!!

I’ve change too:

r = requests.post(“https://” + config[‘address’] +":1926/6/pair/grant", json=grant_request, verify=False,auth=HTTPDigestAuth(config[‘device_id’], config[‘auth_key’]))

to

r = requests.post(“https://” + config[‘address’] +":1926/5/pair/grant", json=grant_request, verify=False,auth=HTTPDigestAuth(config[‘device_id’], config[‘auth_key’]))

and now it’s works!!! I can pair the TV!!! :slight_smile:

I’ve my usr and pass to use it with hass/plugin!!

I needed to change int philips_2016.py:

BASE_URL = ‘https://{0}:1926/6/{1}’

to

BASE_URL = ‘https://{0}:1926/5/{1}’

and it’s working in hass!! I can power on and power off the tv and volume up and down.47

Any possibility to add BASE_URL as a configurarle variable in philips_2016.py? thanks!

Thanks to @an20dei the state (on/off) works correctly with my 55POS9002 when I use the component to control my TV. Though, I noticed that if I turn off my TV with the remote control, then the component shows status as unknown and it is impossible to turn on the TV again with the component. Have anyone else noticed the same behaviour?

Maybe this is of interest for some of you:
The current implementation for Philips TVs was hardcoded to use the old API. This will become customizable with the next Home Assistant release. So maybe it might make sense to let the progress you guys are making here flow into the module: https://github.com/danielperna84/ha-philipsjs
Additionally I want to ask if someone would like to become the new maintainer of the module since I don’t own any Philips TVs anymore. Hence I’m probably not the best option to have control of the module.

1 Like

Hey,

thanks for sharing! I was able to connect to my PUS7101/12 w/o problems. This is what I experienced:

  • @Molodax Off-State is displayed correctly for me, independent of how the TV was turned off.
  • switching on does not work reliable. I have my TV connected via Wifi to my network and activated Wake On Wifi, anyway I can see that when off the TV only connects to my network from time to time. Will try if it works with a cable connection.
  • I cannot set the volume using the input slider in the UI, but the state is received.
  • The service media_player.volume_mute does not work from the developer tools, but the mute button of the UI does work.

Is anyone else observing the same behavior?

I’m still quite new to HA and even more to Pi’s, so this might be a noob question:
How can I call a function defined in the custom component (e.g. sendkey) from an automation or switch?
I would like to try adding some functions (especially basic ambilight control) to the component and have a working (proof-of-concept) py-script for that, but struggle on calling it from HA (Hassbian).