And Now – HA TV Lighting Automation

Living Room Home Assistant Panel

Just a quick one – Having set up all the lighting in Home Assistant including the living room with the TV – my wife had the great idea of moving everything around and I find our chandelier and cupboard lighting totally destroys my TV viewing at night – SO the next step – adaptive lighting.

You’ll see in the image above I have full phone control over all lights in the living room along with colour control. Every light is smart in one way or another and hence are assigned to an HA group. I have all-on and all-off buttons (replicated in Google Echo for voice control) but the last challenge was to adapt the lighting for TV viewing – just finished.

I am of course still learning about HA and the tool itself keeps mutating – the 2024-06 release added a ton of new features and the 2024-07 (out today – I’m using the beta) promises even more. So for me, making a single button which would switch between full-on warm white for all lights – and a dim version with the chandelier and cabinet lights OFF caused me pause for thought. See that yellow control above left.

Off I went to my new favourite toy Claude.AI for help. In the end, I ended up doing more tweaking than automation – however the end result is here, hopefully it might inspire someone as an example – there are two lots of YAML code, one for the button and one for an automation. Why YAML and not the visual interface? Well, I usually want some custom styling you can’t (yet) do in the easy visual panel – so I just switch to YAML view – I find that easiest (I don’t particularly like YAML but that’s where the AI tools can come in handy.

Firstly after initially providing old code which simply didn’t work, Claude.AI told me to create an input helper in Home Assistant – under settings – devices and services – helpers.

I was to click on “create helper” – and choose the “toggle” option – call it “patio light mode” – done.

Now for the button:

type: custom:button-card
entity: input_boolean.patio_light_mode
show_name: true
show_icon: true
show_state: false
name: Full brilliance lighting
layout: icon_name
tap_action:
  action: toggle
styles:
  grid:
    - grid-template-columns: 30% 70% auto
  card:
    - height: 66px
  name:
    - font-size: 16px
state:
  - value: 'on'
    name: <b>Full lighting</b>
    icon: mdi:brightness-7
    styles:
      card:
        - background-color: '#775500'
  - value: 'off'
    name: <b>TV lighting</b>
    icon: mdi:brightness-5
    styles:
      card:
        - background-color: '#265264'
card_mod:
  style: |
    ha-card {
      border: 1px solid darkcyan;
    }
layout_options:
  grid_columns: 2
  grid_rows: 1

And the automation:

alias: Control Patio Lights and Chandelier
trigger:
  - platform: state
    entity_id: input_boolean.patio_light_mode
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.patio_light_mode
            state: "on"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.patio_lights
            data:
              brightness: 255
      - conditions:
          - condition: state
            entity_id: input_boolean.patio_light_mode
            state: "off"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.patio_lights
            data:
              brightness: 128
          - service: light.turn_off
            target:
              entity_id: light.1chzigbee
            data: {}
          - service: light.turn_off
            target:
              entity_id: light.cabinet
            data: {}

The button and automation above are not QUITE what Claude.AI pushed out and I spent ages tweaking them… but the AI got the general idea right. The above should be usable in many situations – just change the entity names to suit your own setup. With th grid styling I manage to change the button from icon with text underneath to icon on the left and text on the right – that took me some doing.

Example entities:

light.1chzigbee is my chandelier light, light.patio_lights is my group of ALL the living room lights including the ones I want off for TV viewing, light.cabinet is obviously my cabinet light. Your setup will be different. The styles in the button I basically guessed until I got what I wanted. You’ll see a reference in the button to card-mod… that’s a farly standard integration in HA – you’ll likely have that already – if not, I guggest you grab it. That’s how many of my buttons and tiles get styled.

I hope someone finds this useful. Ooh, almost made the mistake others do, of ASSUMING a certain setup -my HA is running on a Raspberry Pi under Docker (sitting on the latest 64 bit RPi operating system). Why keep the underlying Pi OS? rpi-clone, that’s why.

One thought on “And Now – HA TV Lighting Automation

  1. I did one that talks to my TV and can tell when stuff is playing, and dims/undims the lights when you play or pause. It’s one of my favorites, it’s really nice once you get used to it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Leave the field below empty!

The maximum upload file size: 512 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here