Philips Android TV Ambilights (Light) component

Hey there!

Would love to install this component to control my Philips 55PUS7502/12 Ambilight, but I always fail at the first step, to pair my TV and get the username/password:

As far as I understand I have to download the philips.py and copy in configcustom_components/media_player

but then? Do I have to restart to get the username/password? Or do I have to run this file manualy, but if so, how do I do that?

Thanks in advance

You need to download philips.py from repository https://github.com/suborb/philips_android_tv/blob/master/philips.py and run it on local environment. So you need to instal Python and some other python components required by this script. When you try to run it everything required will be displayed in console. I don’t remember exactly every step :confused:

1 Like

Hey thanks for your reply! Sorry I´m absolutely not into Python or Coding in general, but does it mean I can start the philips.py from my Mac for example with this program here ? And what are the other python components?

Yes, you need to instal for example the newest version of python and run command “python philips.py --host 192.168.x.x pair” in folder where you downloaded. I’m using windows, so I’m not sure how exactly run it on Mac.
For sure you will be needed to instal some component required by this script, don’t remember what was that. If you don’t known how to instal correct component just google python component name install and instruction should be in the first position.

2 Likes

@Nizm0 has given the command you’ll need, it is the same on Mac OS, you’ll need to download and install python on your Mac from the link you provided if you have yet to do so, then open a terminal window in the folder with the philips.py file inside.

cd /path/to/folder

then run the command

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

As you will be installing python afresh, there may be some dependencies you need to install, for example, this was posted on the GitHub issues page for the philips.py script:

Requests is not a built in module (does not come with the default python installation), so you will have to install it

Use:
$ sudo pip install requests
if you have pip installed

Alternatively you can also use:
$ sudo easy_install -U requests
if you have easy_install installed.

Once you have your username and password, and they are in your home assistant configuration, you are done with the philips.py script, from then on all that is needed is the ambilights.py in your /config/custom_components/light/ folder

Awesome! That was pretty much my exact motive for making the component, I wanted it to match my RGB LED strips in the same room, making it a full light component also means you can use light groups to have the ambilights integrated into the rooms lighting controls without an automation (although you do forgo the ease of a toggle switch to disable it)

An interesting automation I have built on top of this is one that uses both this light component, and an updated version of the philips_2016.py media_player component (which adds the ability to detect what TV Channel or App is currently on the TV), I have it so that if the source changes at all, the Ambilights will be automatically set to the “Standard” effect (Follow Video), meaning that if I have previously set the lights to a certain colour, but then say, open Netflix with the remote, the ambilights will automatically default back to follow the video on the screen, it works brilliantly!

- alias: Amiblights Auto-Standard
  trigger:
  - entity_id: sensor.tv_source
    platform: state
  condition:
  - condition: state
    entity_id: media_player.philips_tv
    state: 'on'
  action:
  - data:
      effect: Standard
      entity_id: light.bedroom_ambilights
    service: light.turn_on

Thanks for your reply! Did all the steps to install Python and components, and after I typed in the command

python philips.py --host 192.168.x.x pair in the folder where the philips.py file is, I got this here:

Starting pairing request
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 "/Library/Python/2.7/site-packages/requests-2.19.1-py2.7.egg/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.19.1-py2.7.egg/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.19.1-py2.7.egg/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.19.1-py2.7.egg/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.19.1-py2.7.egg/requests/adapters.py", line 513, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='192.168.178.41', port=1926): Max retries exceeded with url: /6/pair/request (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x102f939d0>: Failed to establish a new connection: [Errno 60] Operation timed out',))

What does it mean, Can anybody help?

Are you sure that you write correct IP address for your TV? It’s look like your TV is not responding, and the script can’t connect to it to display data required do generate user.

2 Likes

I can get the same errors by putting in the wrong IP, so thats very likely the case, remember you can easily see the TV’s IP from the Android Settings :slight_smile:

1 Like

Hm, don’t know. Maybe you have no access to internet on the TV or your tv is on different sub net and you have no access to it from your PC/Laptop. Verify if your PC IP have the same 3 thirst part of IP address as the one on TV. Maybe you have set on router isolate Wireless devices that they have no access to each other.
Try to ping your tv to verify if you have access to it.

1 Like

Ha! It finally worked!! you were right, I used the wrong IP adress, but now everything works fine, thanks so much for your help and this component! One last question: Is it possible to control also the Ambilight+Hue function with this component or with a command line switch?

1 Like

Unfortunately I have no hue lights to test that functionality with, so cannot add it myself. I would guess it is possible though, if you find the command needed to be sent to the tv, and test that it works, it should be simple to add to the component.

Hi!

I have a problem with this component. It really changes the color of the LED strip behind the TV. I cannot seem to be able to change the brightness with automation.

I can set brightness from the light manually. With automation it does not work. Here is the code:
####################################################
# Philips Ambilight leds low on TV off #
####################################################
- id: ambilight-low-brightness-when-tv-off # <-- Required for editor to work.
alias: Amiblights at low brightness when TV off
trigger:
- entity_id: media_player.philips_tv
platform: state
condition:
- condition: state
entity_id: media_player.philips_tv
state: ‘off’
action:
- service: light.turn_on
entity_id: light.philips_ambilight
data:
brightness: 30
effect: Manual
transition: 2
rgb_color: [‘255’,‘105’,‘180’]

It does change the color to pink, but brightness stays at 255. What’s wrong?

Hi,

I would like to read the rgb values from the ambilight TV, so that I can send this value to other RGB ligts in the same room. Is that possible?

1 Like

@jan.lanner try this:

- alias: Room Lights follow Ambilight TV
  trigger:
  - entity_id: light.philips_ambilight
    platform: state
  condition:
  - condition: state
    entity_id: light.room_1
    state: 'on'
  action:
  - alias: ''
    service: light.turn_on
    entity_id: light.room_1
    data_template:
      brightness: '{{ light.philips_ambilight.attributes.brightness }}'
      transition: 2
      xy_color: ['{{states.light.philips_ambilight.attributes.xy_color[0]|float}}','{{states.light.philips_ambilight.attributes.xy_color[1]|float}}']
2 Likes

Thanks!

Will try it as soon as my orderd RGBw-light strips arrive. Installed your component today and it works great!

I’ve tried this code but, unfortunately, it doesn’t work for me.

It actually would work if to find a way how to pull current colours from the tv ambilight (the component doesn’t do it currently).

1 Like

@Molodax , Yes. If you are using Manual method for changing colors it can pull the current colors. But if you have follow video or follow audio mode, it can’t. I think that it’s not even supported by API.

Which API do you mean? As for ‘manual’ method, it is possible to put all RGB lights including the TV ambilight in one group and have the same effect of manually changed colours without automation.