TV Ambient Lighting, with Node-RED

I have a Hue LED strip mounted to the back of my 65″ TV, and I like to have it change color, according to input and activity on screen. It’s a pretty straight forward and easy setup, but one that people really enjoy.

Listed below is my setup and config, but I will try to show how to do this in the simplest way possible, in the hopes that it will work with whatever your setup is.

Hardware, and related integrations and addons:

(Amazon links are affiliate links, where I get a small commission of purchased item)

Software

  • Home Assistant
    • Node-RED addon
      • Built in nodes – (Nodes that are included with Node-RED)
        1. function node
        2. event: state (server-state-changed) node
        3. switch node
        4. call service (api-call-service) node

Don’t worry if you do not have this exact configuration, since we’ll be using all generic nodes, this should work with virtually all configurations.


To start, we’re going to need to get the status of the TV. To do that, we’re going to use the Activities from the Harmony Hub and remote. The Harmony Hub integration will automatically pull all the activities you created when you first setup your Harmony Hub. The names of those activities are located in the harmony config file located at the root of the Home Assistant config directory. Using the file manager of your choice (I use the Visual Studio Code addon) navigate to this directory and take note of the activity names. Case is important, so make sure to note them exactly as they are.

Now that we know the activity names, we need to figure out how to filter them and use them to kick off flows. To do that, we’re going to grab an “events: state” node, and configure it like so:

Then we’re going to grab a debug node, and configure like so:

And then we are going to connect the two, open the debug window and then start an activity on your TV remote. You’ll see the debug output on the right. This shows all of the information passed on by the state node

If you drill down to “data.new_state.attributes.current_activity”, you’ll see the name of the current Activity, in this example it is “Google TV”. We now need to take this path, plug it into a switch node, and filter the activities. Start by copying the path by clicking the little > emblem.

This will copy the path to your clipboard.

Next, grab a switch node, and paste the path that you copied into the Property field. Then, in the fields below make sure == is selected and then enter the Activity names. This will filter everything that comes in through “data.new_state.attributes.current_activity” to the corresponding output. Nothing else will get passed through. Now, connect the event state node you created earlier to the switch node, and connect properly labeled debug nodes to each output on the switch node. Don’t forget the PowerOff activity!

Switch node configuration

With them all connected, when you start an activity from your remote, you can hover over the debug output and it will highlight the debug node that it came from. Doing this, you can verify that the switch node is routing the payload correctly.

Now that we know when we press Google TV on the remote, it will route through the Google TV output of the switch (along with all the other activities routing through the correct output), we can start programming the lighting per output.

Grab a “call service” node node, and we’re going to program it to turn on the light when PS5 is selected. I like to Google the RGB code of whatever service it is that I’m working with. For example, I would Google “Netflix logo RGB color” and it will give me the RGB code for Netflix Red. Same with Playstation Blue, etc. With that info, the call service node to turn the light Playstation Blue, would look like this:

Domain is light, service is “turn_on. Click the three dots to open the JSON editor to program the settings for the light. “brightness_pct”: 55 will set the light to 55% brightness. “transition”:1.5 means that the light will reach 55% brightness when turned on in one and a half seconds. “rgb_color”:102, 92, 190 is the RGB color for PlayStation Blue. “entity_id” is the name of the light you want to control. You will need to repeat this until you have all the outputs done. One for TV, one for Nintendo Switch, etc.

Lastly, don’t forget about the PowerOff activity, to turn the lights off when you turn off the TV. It’s the same setup, different service. Grab another “call service node”, and program similar to before, except the only thing you need to worry about is the service, which is now “turn_off, and the entity_id of course. It will look like this:

The completed flow will look like this:

Here is a video showing how it can look. Keep in mind, in the video, I’m using a more advanced version of the flow to change colors based on the currently selected app in my Google TV, but the effect is the same. I may do a part two later to show how to do that. Also, don’t mind the creepy whispering at the end of the video, I was lightly bullying my buddy cause his TV isn’t this awesome.

Finally, here is the code.

2 thoughts on “TV Ambient Lighting, with Node-RED

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s