Dim Philips Hue lights at sunset with Home Assistant

19 April, 2025
Home Assistant

This post describes how to set up a couple of Home Assistant automations to dim Philips Hue lights at sunset.

A standard Home Assistant installation includes the Sun integration, which we can use to determine a) when the sun sets, and b) if the sun is currently below the horizon (i.e., it has set). It may not be immediately obvious why we need to keep track of both those things, but if you don't have smart switches, they're both important!

The first automation is simple: When the sun sets, dim the lights. For this, I've set up two Philips Hue scenes. These can be created via Settings / Automations and scenes / Scenes / Add scene. Choose an area or a specific device. My example scenes are called scene.bedroom_dim and scene.bedroom_bright.

Create the automations via Settings / Automations and scenes / Automations / Create automation. The YAML for this is pretty self-explanatory: When the sun sets (based on the sunset event), and the light is on (light.bedroom state is "on"), activate the scene.bedroom_dim scene, i.e., dim the lights.

alias: Dim bedroom lights at sunset 1/2
description: ""
triggers:
  - trigger: sun
    event: sunset
conditions:
  - condition: state
    entity_id: light.bedroom
    state: "on"
actions:
  - action: scene.turn_on
    metadata: {}
    target:
      entity_id: scene.bedroom_dim
mode: single

If, like me, you aren't using smart switches, it gets a bit more complicated here. When the light is off at the wall switch, the light isn't "off" to Home Assistant, it's unavailable. And you can't do anything with an unavailable device.

I would like the light to be dimmed regardless of whether it's on or off at the wall switch; that is, if the light was set to bright before being turned off, and later that day (after sunset) I turn it back on again, I want it to recognise that the sun has set and that therefore it should be dim.

So, we need one more automation. This one has two triggers, both looking at the state of the light.bedroom entity: if it switches from unavailable OR from "off" to "on". This means it'll trigger if the light is off at the wall and you flick the switch on (i.e., it was unavailable to Home Assistant and then becomes available), or if it's "off" to Home Assistant and gets turned on (i.e., if it's "on" at the switch but you've turned it off via Home Assistant or Hue).

There's a condition that then checks whether the sun is below the horizon (again using the Sun integration); this is the state below_horizon. If that condition is true, then we activate the light.bedroom_dim scene. And that's basically it.

alias: Dim bedroom lights at sunset 2/2
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.bedroom
    from: unavailable
    to: "on"
  - trigger: state
    entity_id:
      - light.bedroom
    from: "off"
    to: "on"
conditions:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
actions:
  - action: scene.turn_on
    metadata: {}
    target:
      entity_id: scene.bedroom_dim
mode: single