Setting a Light Scene for watching Netflix with Home Assistant

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:

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Open the Gate for Healthy Apps with Cloud Performance Testing

5 keys of Nearshoring success

Strapi and Motiv Announce Partnership

Our product demos suck

CodeRiders is Among Best Software Development Companies

List of the top offshore software development companies by TopDevelopers

3 Wishes for My Future Code-Reviewers

Use OneDrive Excel file as an external source for your Public Web Form fields

HTB Cyber Apocalypse CTF 2022 — Puppeteer Write up

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cyan Automation

Cyan Automation

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

More from Medium

The Dilly Duck Shop — Russ & Phyllis Zappala

Do You Really Need A $1,000 Smartphone?

DIY Smart Water Control

How to restore iPhone after forgetting your password