Setting a Light Scene for watching Netflix with Home Assistant

Cyan Automation
3 min readAug 8, 2020

--

Photo by Samet Özer on Unsplash

In this guide, we’re going to set lights via an automation and script, to maximize our streaming experience. When setting down to watch some great anime on the large screen, I want to ensure that the lights are low or off, to reduce the glare and reflections onto the TV. We can do this via an automation to detect when the TV is on, and then trigger a script to set the lights just right.

Getting Started

The trigger will depend on your display/TV and whether you look for a direct sensor, or determine that it’s on/playing through an indirect method (e.g. gaining an IP address, having a ESP32 plugged into a USB port, etc.). For me, my Samsung TV has an OOTB integration that I’ve added via the Integrations GUI. To add this, just head over to your Configuration page in Home Assistant, select Integrations and click the Add/Plus icon in the bottom right corner. You’ll be presented with a search module where you can search for Samsung (or whatever brand) integration.

Making It Work

Now let’s create our automation: first give your automation a helpful and descriptive Name. We’ll also be classifying this to run in single mode, to prevent simultaneous triggers.

Next, we have to define the Trigger – which is the key part. Here I’m using the TV Sensor, and detecting when it turns from off to on. Alternatively, you could set it to trigger on moving from any state (leaving initial state blank), and this would include moving from states such as unknown to on – but this can lead to false positives. I’ve further protected against false triggers, by asking Home Assistant to only trigger when the TV is on consistently for 5 seconds. This delays the onset of the script, but that’s a trade-off that I think is worth it.

A false positive or false trigger is when the Trigger is actioned prematurely or erratically. As network connectivity is not always stable – with momentary drop-outs and re-connections, this can be a cause of false triggers. We can use the For/Duration part of the trigger to guard against these situations.

Now the final part is just setting the action to change/dim the lights. I’m dimming some lights and switching off others as part of this “scene”, so I’ve opted to put that into a separate script, but it’s also fine to define these actions within the automation too.

Home Assistant has both Scripts and Scenes. Generally, Scripts are preferred as they allow you to have more control over all kinds of Home Assistant aspects, where Scenes are more focused on the states of devices.

And here is what it looks like in YAML format:

--

--

Cyan Automation

Marc’s tips on building your Smart Home with Home Assistant, Shelly and ESPHome.