For anyone interested, I have successfully set up an automation which sets the Ambilights of a 2016+ Philips Android TV to follow (copy) the colour of another light from Home Assistant, say you have RGB LED strips around the room, and want the TV ambilights, at certain times, to automatically match the colour of the target lights.
Things to note:
- This method uses Hue and Saturation to set the colour of the ambilights, so the ‘hs_color’ attribute of the light component is used to update the parameters, this may be labelled differently for your lights
- The scaling of the Hue and Saturation within home assistant will probably be different to the scale used within the Phillips API, and thus, a scaling factor is needed
Through experimenting with the Jointspace API, I could set all the Ambilight LED’s to one colour via the terminal command:
shell_command:
name_of_shell_command:
curl -X POST --digest --insecure -u XXXXX https://192.168.X.XXX(TVs_local_IP):1926/6/ambilight/currentconfiguration -d ‘{“styleName”:“FOLLOW_COLOR”,“isExpert”:true,“algorithm”:“MANUAL_HUE”,“colorSettings”:{“color”:{“hue”:{{ ((state_attr(‘light.[enitity_id of target light]’, ‘hs_color’)[0]) * ([Scaling Factor]) |int }},“saturation”:{{ ((state_attr(‘light.[enitity_id of target light]’, ‘hs_color’)[1]) ([Scaling Factor])) |int }},“brightness”:{{ state_attr(‘light.[enitity_id of target light]’, ‘brightness’) |int }}},“colorDelta”:{“hue”:0,“saturation”:0,“brightness”:0},“speed”:255}}’
As this is very messy, I will give an example:
- The IP of the TV being 192.168.1.101
- The entity_id of the light I want the tv to copy is light.bedroom_light
- The scaling of the HS(&B) values within home assistant are:
Hue:(0-360)
Saturation:(0-100),
Brightness:(0-255) - The scaling of the HS(&B) values for the Philips TV (yours will most likely be the same) are:
Hue:(0-255),
Saturation:(0-255),
Brightness:(0-255)
The following shell_command will be added to config.yaml:
curl -X POST --digest --insecure -u XXXXXXXXXXXX https://192.168.1.101:1926/6/ambilight/currentconfiguration -d '{“styleName”:“FOLLOW_COLOR”,“isExpert”:true,“algorithm”:“MANUAL_HUE”,“colorSettings”:{“color”:{“hue”:{{ ((state_attr('light.bedroom_light, ‘hs_color’)[0]) * (255/360)) |int }},“saturation”:{{ ((state_attr('light.bedroom_light, ‘hs_color’)[1]) * (255/100)) |int }},“brightness”:{{ state_attr(‘light.bedroom_light, ‘brightness’) |int }}},“colorDelta”:{“hue”:0,“saturation”:0,“brightness”:0},“speed”:255}}’
Then, an automation can be created to run the shell command any time the state of the target light is changed, thus keeping the ambilights in sync:
– alias: Follow Room Colour
trigger:
– entity_id: light.bedroom_light
platform: state
condition:
– condition: state
entity_id: switch.ambilight
state: ‘on’
action:
– service: shell_command.set_ambilights_to_strips
This automation can be turned on and off, to allow the ambilights to continue following video or audio if this function is not needed. I did look into expanding this into a fully functional RGB light from within Home Assistant, but could not find any shell_command light component that would work (although there seems to be an MQTT light component which may be similar), if anyone knows of a more elegant solution to this I would love to hear it, otherwise, this is a very nice way of tying in your TV to your current RGB lights, controlled by Home Assistant