Creating a Master Dark Mode Override and Media-Aware Lighting Automations in Home Assistant

Isometric architectural blueprint schematic of a home theater living room with media bias lighting and gated sensor cones

A smart home lighting setup that relies strictly on presence sensors works well during ordinary daytime routines, but quickly becomes annoying during an evening film. Shifting your position on the sofa or reaching across the coffee table for popcorn trips an overhead motion sensor, turning a dim movie screening into an interrogation room. If you manually turn the lights off, the next motion event turns them right back on, and when you finally want your normal room lighting back, simple automations fail to remember where your dimmers were set.

In this guide, you will configure a centralized Dark Mode override helper in Home Assistant, capture active lighting states dynamically with on-the-fly scene creation before shutting down illumination, gate room motion automations behind both television playback state and the dark mode switch, and smoothly dim accent bias lighting during video playback. To read the weekend homelab story where hyperactive living room sensors collided with a mountain of stalled automated reviews, check out Fifty-Eight Blocked AI Tasks and a Living Room That Refuses to Go Dark on Frizzle Tech Blog.

Prerequisites

You need a functioning Home Assistant installation, smart dimmer switches or bulbs in your living area, and a media player reporting playback status for your television. Everything is built in the Home Assistant web UI with no configuration.yaml edits and no restarts.

  • Home Assistant 2024.1 or newer running on dedicated hardware or a Proxmox virtual machine.
  • Dimmable living room smart switches or smart bulbs grouped under light.living_room_ceiling and light.tv_backlight.
  • A media player entity (such as Apple TV, Android TV, Roku, or Kodi) reporting playing, paused, and idle states under media_player.living_room_tv.
  • A PIR or mmWave motion detector mapped to binary_sensor.living_room_motion.

Step 1: Create the Master Dark Mode Helper in the Home Assistant UI

Rather than scattering individual boolean toggles across multiple rooms, create a single centralized helper that represents the household Dark Mode state. Open Settings -> Devices & services -> Helpers, click Create helper -> Toggle, enter the name Dark Mode (which produces input_boolean.dark_mode), pick the icon mdi:weather-night, and click Create. When input_boolean.dark_mode is on, automated lighting triggers yield to total darkness. No YAML and no reload are required.

Step 2: Build Dynamic Scene Snapshot and Restore Scripts in the UI Script Editor

Restoring previous brightness levels when Dark Mode turns off requires saving your state first. Home Assistant provides scene.create with the snapshot_entities parameter, which generates an ephemeral scene in memory right before lights shut down. Open Settings -> Automations & scenes -> Scripts, click Create script -> Create new script, open the three-dot menu, choose Edit in YAML, and paste the first snippet below. It holds only the inner script definition with no outer script: key. Save it with the script ID enable_dark_mode:

alias: "Enable Dark Mode with State Snapshot"
mode: single
sequence:
  - action: scene.create
    data:
      scene_id: before_dark_mode
      snapshot_entities:
        - light.living_room_ceiling
        - light.tv_backlight
  - action: input_boolean.turn_on
    target:
      entity_id: input_boolean.dark_mode
  - action: light.turn_off
    target:
      entity_id:
        - light.living_room_ceiling
        - light.tv_backlight
    data:
      transition: 2

Create a second script the same way, save it with the ID disable_dark_mode, and paste this definition:

alias: "Disable Dark Mode and Restore State"
mode: single
sequence:
  - action: input_boolean.turn_off
    target:
      entity_id: input_boolean.dark_mode
  - if:
      - condition: template
        value_template: "{{ states.scene.before_dark_mode is not none }}"
    then:
      - action: scene.turn_on
        target:
          entity_id: scene.before_dark_mode
        data:
          transition: 2
    else:
      - action: light.turn_on
        target:
          entity_id: light.living_room_ceiling
        data:
          brightness_pct: 40
          transition: 2

This structure guarantees that if you toggle Dark Mode while reading at 60 percent warm white, turning Dark Mode off returns your lamps to 60 percent rather than snapping to a generic default.

Step 3: Gate Motion-Activated Lighting Behind Dark Mode and Media States in the UI Automation Editor

Standard motion lighting blueprints fail because they only check sunset times. Open Settings -> Automations & scenes -> Automations, click Create automation -> Create new automation, open the three-dot menu, choose Edit in YAML, and paste the snippet below. It contains only the automation itself with no outer automation: key, and requires that Dark Mode is off and the television is not playing:

alias: "Living Room Motion Lighting Control"
mode: restart
triggers:
  - trigger: state
    entity_id: binary_sensor.living_room_motion
    to: "on"
conditions:
  - condition: state
    entity_id: input_boolean.dark_mode
    state: "off"
  - condition: template
    value_template: >
      {{ not is_state('media_player.living_room_tv', 'playing') }}
  - condition: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: 4
actions:
  - action: light.turn_on
    target:
      entity_id: light.living_room_ceiling
    data:
      brightness_pct: 35
      transition: 1

With these two condition gates in place, walking past the living room couch while a movie is running will never trigger the overhead ceiling bulbs.

Step 4: Automate Playback-Aware Media Transitions for Bias Lighting in the UI Automation Editor

Television bias lighting behind your screen improves perceived contrast and reduces eye strain in a dark room. Instead of leaving backlights at a constant intensity, link them to the media player state so they dim down when you press play and brighten slightly when you pause to grab a snack. Create a new automation in the YAML editor and paste the first definition:

alias: "TV Playback Dim Bias Lighting"
mode: restart
triggers:
  - trigger: state
    entity_id: media_player.living_room_tv
    to: "playing"
conditions:
  - condition: state
    entity_id: input_boolean.dark_mode
    state: "off"
actions:
  - action: light.turn_off
    target:
      entity_id: light.living_room_ceiling
    data:
      transition: 3
  - action: light.turn_on
    target:
      entity_id: light.tv_backlight
    data:
      brightness_pct: 12
      transition: 2

Then create a second automation for the pause state:

alias: "TV Playback Pause Soft Lighting"
mode: restart
triggers:
  - trigger: state
    entity_id: media_player.living_room_tv
    from: "playing"
    to: "paused"
conditions:
  - condition: state
    entity_id: input_boolean.dark_mode
    state: "off"
actions:
  - action: light.turn_on
    target:
      entity_id: light.tv_backlight
    data:
      brightness_pct: 45
      transition: 2

Automations in the UI go live the moment you save them. When a show begins, your main lights fade down smoothly and the backlight settles to a gentle 12 percent. Pausing the movie lifts the backlight to 45 percent, providing enough visibility to navigate the room safely without disturbing the cinematic atmosphere.

Replicate This Build with AI

If you would rather have an AI coding agent audit your Home Assistant instance and build this for you, paste the prompt below into Antigravity, Claude Code, Codex, or Gemini CLI. Fill in the placeholders first.

You are helping me build a master Dark Mode override with media-aware lighting in Home Assistant.

Step A: Inspect my setup.
- List my light.* entities and ask which are the main ceiling lights (<ceiling-lights>) and which is the TV bias light (<bias-light>).
- List my media_player.* entities and ask which is the living room TV (<tv-player>).
- List my motion binary_sensor.* entities and ask which one covers the living room (<motion-sensor>).

Step B: Choose the output mode.
Mode 1 (UI): Output paste-ready YAML for the Home Assistant UI editors, with NO outer "script:" or "automation:" keys. Tell me to create a Toggle helper named "Dark Mode" (input_boolean.dark_mode) first.
- Script enable_dark_mode: scene.create scene_id before_dark_mode snapshotting <ceiling-lights> and <bias-light>, turn on input_boolean.dark_mode, then turn the lights off with a 2 second transition.
- Script disable_dark_mode: turn off input_boolean.dark_mode, restore scene.before_dark_mode if it exists, otherwise set <ceiling-lights> to 40 percent.
- Automation: <motion-sensor> turns <ceiling-lights> on at 35 percent only when dark mode is off, <tv-player> is not playing, and sun elevation is below 4.
- Two automations: bias light to 12 percent when <tv-player> starts playing, 45 percent when it pauses, both only when dark mode is off.

Mode 2 (Git-tracked config): Write one file at <config-repo>/packages/dark_mode_lighting.yaml with the helper, both scripts, and all three automations. Confirm that <config-repo>/configuration.yaml has "homeassistant: packages: !include_dir_named packages", then validate with "ha core check" and report any errors.

Rules: use only entity IDs you actually found. Never invent entities. Do not print tokens, hostnames, or IP addresses. Show me the final YAML before changing anything.

Hardware & Gear Used in This Guide

  • Smart wall switch: Z-Wave 800 series or Zigbee 3.0 in-wall dimmer switch with neutral wire connection controlling overhead LED fixtures
  • Bias lighting strip: Addressable or warm-white 24V LED strip installed along the perimeter of the television back panel
  • Media player: Streaming console running Apple tvOS or Android TV integrated into Home Assistant via local network protocols
  • Motion sensor: Ceiling-mounted PIR or 24GHz mmWave radar presence detector communicating over local Zigbee or Z-Wave

Taking It to the Next Level

  • Optional Git-Ops tip: if you prefer to manage your whole Home Assistant instance as code in Git, you can define the same helper, scripts, and automations in a YAML package instead. Add homeassistant: with packages: !include_dir_named packages to your configuration.yaml, drop everything into packages/dark_mode_lighting.yaml, and let the AI prompt above write and validate it. Treat this as a power-user alternative, not a prerequisite.
  • Bind the script.enable_dark_mode and script.disable_dark_mode sequences to a physical double-tap event on your wall switch so anyone in the family can engage theater mode without opening a phone dashboard.
  • Add an automatic curfew automation that engages Master Dark Mode at midnight if the living room TV is off, ensuring that middle-of-the-night kitchen runs use low floorboard illumination rather than standard daytime circuits.
  • Read Fifty-Eight Blocked AI Tasks and a Living Room That Refuses to Go Dark on Frizzle Tech Blog for the full narrative breakdown of how local smart home overrides intersect with autonomous homelab fleets.

How do you handle movie night overrides in your own smart home, and what would you add to a Dark Mode switch?

Later,
     SteveO