Philips Android TV Ambilights (Light) component

Yea, sorry, that was what I tried first. But I think I solved it already. I uploaded the manifest.json file too into the folder and now it doesn’t give the error anymore. I now have the light component in Home Assistant, I’ll test it when I get home later today.

Hi guys, I have just pushed an update to the (now) 3 components on GitHub.

- Philips TV Ambilight (Light) Component for Home Assistant

New in this Version:

  • All components updated for the ‘Great Migration’ thanks to @hutchinsane
  • There is apparently an issue for setting the ambilight brightness on some TV’s where the colour is always changed, even when in manual mode, I have implemented a potential workaround for this using a method highlighted by @gyrga, but it is commented out by default. See Line 130 in light.py

- Phillips TV Ambilight+Yeelight (Switch) Component

(Work in Progress)

Potential Epilepsy Warning:

At times when testing this component (usually when the TV is displaying an ambient light / no colour), the bulb is still updated rapidly and can cause a noticeable (but reducible) flicker - if you have Epilepsy this may not be for you. (Yet)

Bug Bounty: If anyone can find a solution to this, while there will be no financial reward, you will have my eternal gratitude :slight_smile: (see Lines 83, 314, 316 etc).

This new (and pretty unrefined) component mimics surprisingly well the funtionality of Amilight+Hue with all Yeelight bulbs/lights using the Music Mode function from their API. The colour of the bulb is read constantly from the TV (jointspace), processed on the Home Assistant machine, and updates are pushed to the bulb in a loop until turned off. I’m sure it could be improved, so the code is commented, I encourage you to have a play with the values and check the links for more custom changes, if something else works better, or adds more features ill be happy to add them in for everyone. The values I’ve chosen are simply through trial and error.

Installation

If you have already set up the Ambilight component, installing this component is very simple, copy the philips_ambilight+yeelight directory into your config/custom_components/ directory,
enter the same username and password as for the ambilight component in the configuration.yaml, along with both the IP of the TV, and the IP of the bulb as follows, and restart home assistant:

switch:
  - platform: philips_ambilight+yeelight
    name: Lounge Lamp (Top Right) # (Name in Front-End)
    host: 192.168.1.XXX # (the TV)
    username: !secret philips_username
    password: !secret philips_password
    address: 192.168.1.XXX # (The Bulb)
    display_options: right-top

The per-bulb positions I have added (defined by display_options) are as follows:

Note:

  • I have not tested each and every one of these positions manually, if one of them doesn’t seem right, assume it’s my fault and let me know :slight_smile:
  • As I do not have a TV with bottom ambilight LED’s, I have not been able to test this part at all, although it should work in theory, please let me know if you have any success.

For a more custom position, different value calculations, or perhaps something different entirely, see the links in the code’s comments. Understanding the ‘topology’ section (JointSpace API) will go a long way to explaining how this part works.

Resources

This component works by combining (or using features from) the following resources with a custom python script, if you would like to understand or improve different parts of this component, this is a good place to start:

4 Likes

@jomwells Great, are you planning to add support for HACS in future?

I’ve (hopefully) added HACS support for all the components now, they have therefore been separated into three repos:

For now, try adding the following as custom repositories:
jomwells/ambilights
jomwells/ambihue
jomwells/ambilight-yeelight

Please let me know if you have any problems, my HACS test environment is acting very slow/buggy and I’m not sure if it is these components, the environment, or hacs in general :slight_smile:

2 Likes

Found one issue

See
https://github.com/jomwells/ambilights/issues/3#issuecomment-505591338

2 Likes

Hi, I have a question. regarding how to use the jointSPACE simulator demo for no Philips TV. I am trying to install the Component (philips_ambilight+yeelight) into Homeassistant . I run the demo simulator with the WMware player following the indications from the jointPSPACE page, but I am stuck there.Any body can help? thanks in advance

As another person with a new philips tv without android tv, I’m interested in what url you used specifically. I’ve tried guessing, but no luck so far.

EDIT

I’ve used this url: http://{0}:1925/1/{1} and changed line 81(57) from https to http. The light still shows as unavailable.

my config:

  - platform: philips_ambilight
    name: Lyset Bag Fjernsynet
    host: 10.0.0.119
#    username: !secret philips_username
#    password: !secret philips_password

This is the error message I get:

Update for light.lyset_bag_fjernsynet fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 380, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  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/philips_ambilight/light.py", line 227, in update
    self.getState()
  File "/config/custom_components/philips_ambilight/light.py", line 161, in getState
    fullstate = self._getReq('ambilight/currentconfiguration')
  File "/config/custom_components/philips_ambilight/light.py", line 273, in _getReq
    return json.loads(resp.text)
  File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Did you manage to get this to work yet? Unfortunately if the default address is not working they could have changed it to anything, if you have experience with python, I would say your best bet would be to play around with the Pylips Library (see resources above) until you find a way to control it manually (that was my first step in creating this component) then you could change the component accordingly. Please let me know if you have any success :slight_smile:

Sorry, I missed your message. I also changed the /1/ to /6/ (API v6) in the url, but that depends on your TV…

I have one of the newly-released OLED804s and it’s failing at the pair.

The TV is not listening on port 1926, although it is on 1925, and using HTTP rather than HTTPS.

I’ve tried updating the paths in philips.py, but it throws an exception from line 123:

No JSON object could be decoded

POSTing the payload { 'scope' : [ "read", "write", "control"] } to http://x.x.x.x/6/pair/request just receives a 500.

I’m guessing things have changed sufficiently in the new series. Is there anything I can do to debug?

I got it to work by changing the API in the url to 6 like signaleleven suggested. Thanks signaleleven!

So a quick recap for other people who might have the problem of having a new Philips TV with ambilight, but with SAPHI instead of Android:

I changed line 20 in light.py to

BASE_URL = 'http://{0}:1925/6/{1}' # for older philps tv's, try changing this to 'http://{0}:1925/1/{1}'

and line 81 to

        self._session.mount('http://', HTTPAdapter(pool_connections=1))

and my configuration.yaml only has this code, with no password or username:

  - platform: philips_ambilight
    name: Lyset Bag Fjernsynet
    host: 10.0.0.XXX
4 Likes

Ah that’s concerning - I’m about to pull the trigger on an 804.

(Not to go too far off topic, but in a sentence, how are you finding it otherwise?)

I have the 65OLED804 and it’s stunning. As with most Smart TV devices, the Android TV is a little bit sluggish, but I have an Nvidia Shield TV connected and I’m seldom out of that. It’s my first OLED and I’m very worried about screen burn. I’ve noticed that when opening the Prime Video app for example, on the grey background during loading, you can still see the outlines of all the Android TV desktop icons! I’m sure this is more of an OLED issue rather than one specifically with this model, though.

Still, I love it and I’m really pleased with the purchase. It would just be even better if I could get this component working!

1 Like

Has anyone else tried this with the 2019 (804 etc) models yet?

1 Like

hi, tried to get password etc using the philips.py script and getting this error
Traceback (most recent call last):
File “philips.py”, line 9, in
from Crypto.Hash import SHA, HMAC
ImportError: No module named Crypto.Hash

any one know how to overcome this?
thanks

I have a Philips Ambilight 55pus7504 and after I installed the component using HACS it says that it is unavailable. Any ideas why?
I paired the device successfully and this is my configuration:

- platform: philips_ambilight
    host: 192.168.100.32
    username: !secret philips_username
    password: !secret philips_password

I can confirm that this works with at least one of the latest 2019 models. Specifically my 65OLED804/12.

I was getting 500 Internal Server Errors when attempting to make any request, on any port, http or https, using the /1 or /6 endpoints.

It turned out that all I needed to do was a factory reset on the TV itself. I haven’t had time to perform any of the calibrations yet, so I haven’t lost much.

The system endpoint is now working on https://{IP Address}:1926/6/system and the pairing using philips.py worked first time around.

Thanks for this! I got it working with my 2019 65PUS7304/12 TV.

However, sometimes the TV does not reconnect with HA when powering it on after sleep so HA still reports the Ambilight as unavailable.

Is it maybe possible to create a script that tries to reconnect to the TV from HA? Then I could trigger the reconnect from HA instead of completely relying on the TV to reconnect properly.

cool!
hope todo this myself for my tv.
What was the final order of actions you had to do to get it all setup?

I get this warning all the time. Does someone know how to avoid this?

custom_components/philips_android_tv/media_player.py (WARNING) - message first occurred at 12:04 and shows up 1768 times
Favorites not supported for this TV