Circadian lighting is the concept that electric light can be used to support human health by minimizing the effect of electric light on the human circadian rhythm.
source: thelightingpractice.com/what-is-circadian-lighting/

The human body follows a circadian rhythm. A 24-hour cycle that’s part of our body’s internal clock, which on its turn regulates lots of processes in our body. One of the most important circadian rhythms is the sleep-wake cycle.

Our (overly) well-lit offices and houses can cause a desynchronisation of our body with its internal clock, which is tuned to the rising and setting of the sun. By changing the colour temperature and brightness of the lightbulbs to match the light we’d get from the sun, we re-sync our bodies. This results in more focus during the day and better sleep at night.

Circadian Rythm
Circadian Rythm

Adding IKEA TRÅDFRI lights to Home Assistant

The IKEA TRÅDFRI communicate over Zigbee. So you’ll need to have a zigbee controller connected with Home Assistant.

In a previous post I added some Aqara sensors using a ConBee II Zigbee controller and the DeCONZ add-on.
Nowadays I’m using the Zigbee Home Automation (ZHA) integration in Home Assistant to manage Zigbee devices.
However, the idea stays the same: use the integration/add-on to link Zigbee devices to our attached Zigbee controller.

Installing ZHA

This post isn’t about installing ZHA, so I’ll keep it short here.

  1. Attach your Zigbee controller (e.g. Dresden Elektronik ConBee II) to your Home Assistant system.
  2. Install the ZHA integration.
  3. Select the ConBee II device when asked

Adding the bulbs in ZHA

Make sure you do this setup with one bulb at a time.

  1. Install the lightbulb in its fitting and make sure it’s powered.
  2. Open the ZHA Integration page by clicking “Configure”
  3. Click “Add Device” in the bottom-right
  4. ZHA add-on is now searching for new devices. You can click “Show logs” at the top-right if you need to troubleshoot.
  5. With the lightbulb turned on, toggle it off-on 6 times (ending on the ‘on’ state again).
  6. The lightbulb is now reset and in pairing mode, which you’ll notice by the light flashing bright once and going in a heartbeat mode.
  7. Wait for ZHA to discover the bulb.
  8. Give the discovered device a name and a location.

You can now toggle the lights by calling the light.toggle service with the entity_id of the bulbs you just added.

Circadian Lighting in Home Assistant

As someone has already gone through the trouble of writing a circadian lighting script, it’s a piece of cake to install circadian lighting in Home Assistant.

Installation via HACS

If you haven’t already, you’ll want to installs HACS.
While you could install the script yourself, HACS will give you easier update functionality and access to much more custom extensions to Home Assistant.

  1. Open HACS via the sidebar and go to the Integrations section.
  2. Click the big “Explore & add repositories” button at the bottom-right.
  3. Search for and install the “Circadian Lighting” repository.
  4. Check your configuration and reboot Home Assistant

Activating the component

  1. Open configuration.yaml in an editor (e.g. using the Visual Studio Code add-on) and add the following line: circadian_lighting:
  2. Check your configuration and reboot Home Assistant

Adding circadian lights

Under the switch section of your configuration, add the lights you want to add circadian lighting to.

switch:
  - platform: circadian_lighting
    name: IKEA circadian lighting
    lights_ct:
      - light.tradfri_bulb

Make sure to check the documentation and set the correct attributes here.
For example, you’ll need to check whether your lights' colour is controlled in CT, RGB or XY mode, or if you only want to/can change the brightness.

  • lights_ct (Optional): array: List of light entities which should be set in mireds.
  • lights_rgb (Optional): array: List of light entities which should be set in RGB.
  • lights_xy (Optional): array: List of light entities which should be set in XY.
  • lights_brightness (Optional): array: List of light entities which should only have brightness adjusted.

Check the attributes of your lights in the Developer Tools. This will give you some useful input.
Below are the attributes of my IKEA TRÅDFRI LED bulbs:

min_mireds: 250
max_mireds: 454
off_brightness: null
friendly_name: 'TRADFRI LED bulb E27 1000 lumen'
supported_features: 43

After a reboot of Home Assistant, the Circadian Lighting integration will monitor the lights you configured.
Once those lights are turned on, the integration will automatically adjust their colour temperature and brightness to match the current state in the circadian cycle.

If you want to, you can make additional changes to the module and the individual light groups.
See the Advanced Configuration Wiki page for more info.

Extra: Pairing 5-button TRÅDFRI remote to Home Assistant

Since Zigbee devices can only be controlled by 1 controller at a time, you’ll need to connect the 5-button remote to ZHA if you want to use it in parallel with HA to control the TRÅDFRI bulbs.

To pair the remote with ZHA, you follow the same steps as when you connected the lightbulbs.

  1. Put the battery in the back of the remote.
  2. Open the ZHA Integration page by clicking “Configure”
  3. Click “Add Device” in the bottom-right
  4. ZHA add-on is now searching for new devices. You can click “Show logs” at the top-right if you need to troubleshoot.
  5. Press the small button at the back of the remote 4 times within 5 seconds.
  6. A tiny red LED will flash shortly at the front of the remote to indicate it’s in pairing mode.
  7. Wait for ZHA to discover the remote.
  8. Give the discovered device a name and a location.

To perform actions with the remote, you can make use of the blueprint provided by Frenck.

  1. In Home Assistant, go to Configuration > Blueprints.
  2. Click the “Import Blueprint” button.
  3. Copy and paste the following URL: https://community.home-assistant.io/t/zha-ikea-five-button-remote-for-lights/253804 and click “Preview blueprint”
  4. You don’t have to change anyting in the next screen, so click “Import Blueprint”.
  5. With the blueprint imported, click “Create Automation”.
  6. Now configure the automation by adding your remote and light bulbs and optionally adding actions to the left/right buttons.
    1. Give the automation a name and description of your choosing.
    2. Select your TRÅDFRI remote in the “Remote” section.
    3. Select the lightbulbs you want to control with the remote in the “Light(s)” section.
    4. Optionally turn on the “Force turn on brightness” to set a default brightness when turning on the lights.
      Without this option checked, the lightbulbs will turn on at the brightness they had when they were turned off.
    5. You can also add actions to the short/long press of the left/right button.
      Note that these buttons won’t control the colour temperature of the bulbs anymore. You could write a script that mimicks this behaviour and call that from the automation.
  7. Save the automation
  8. Check your config and reboot Home Assistant

Pressing the power button on the remote will now toggle your lights and the up/down buttons can be used to dim them.

Extra: Adding physical light switches via Shelly

Before installing the IKEA TRÅDFRI lightbulbs, I had regular lightbulbs which I could turn on/off using physical switches.
I had already installed Shelly relays (integrated into Home Assistant) behind them to also add the ability to toggle my lights via Home Assistant.

We can now repurpose these Shelly’s to also control the TRÅDFRI bulbs.

You have 2 options to keep the lightbulbs continuously powered in order to be able to control them via the IKEA remote or Home Assistant:

  1. Bypass the switch (and Shelly) with your Live wire and connect it directly to the feed of the bulbs.
  2. Keep the feed of the bulbs connected to the Shelly but make sure to configure it to keep the lightbulbs powered:
    1. Set the “Power on Default Mode” to “On”.
    2. Set the “Button Mode” to Detached.
    3. Optionally set an “Auto On” timer that turns the output on again if it was turned of for any reason.

In both cases, we attach the physical switch to the Shelly.

I already had a Shelly 2.5 in place, so I’ll use that one. If you don’t have any smart controls on your switch yet, I’d advise using a Shelly i3 to sense the switch state.
The Shelly 2.5 does give me the ability to monitor the power consumption of the lightbulbs.

  1. Connect the Live wire to a Wago.
  2. From this Wago, run a live wire to the Shelly L-terminal and another to Live/Common terminal of the switch.
  3. Connect the Neutral wire to the Shelly N-terminal (via a Wago if this wire also continues to e.g. the lightbulbs).
  4. Connect the output of the switch to the Shelly SW-terminal.
  5. Connect the feed for the lightbulbs to the Shelly O-terminal.

In Home Assistant we now follow the state change of the switch and toggle the lights when the switch is toggled.

There are multiple methods to achieve this goal. You can integrate the Shelly via the Shelly Integration or ShellyForHass, but I’ll be using MQTT. I’m also not using Home Assistant Automations but Node-RED as all my home automation scripts are in there.

I have a quick-and-easy flow that listens to the MQTT topic for the switch input.
Since the Shelly by default repeats it’s state every 30 seconds*, I need to make sure I only toggle the lights when the switch’s state changes. If it does, I call the light.toggle service to toggle the lightbulbs on or off.

Node-RED flow to toggle TRÅDFRI bulbs with Shelly
Node-RED flow
[{"id":"50cf247.4a249dc","type":"comment","z":"35de3eaf.51455a","name":"TRADFRI","info":"See my blog post on sequr.be for more info","x":80,"y":40,"wires":[]},{"id":"52bb2344.cb92f4","type":"api-call-service","z":"35de3eaf.51455a","name":"Toggle Tradfri bulbs","server":"2ce15169.23b9de","version":1,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.tradfri_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":660,"y":100,"wires":[[]]},{"id":"2114dd82.4a51c2","type":"mqtt in","z":"35de3eaf.51455a","name":"","topic":"shellies/shellyswitch25-xxxx/input/0","qos":"0","datatype":"auto","broker":"6d8018f0.c514b","x":160,"y":160,"wires":[["ddb41302.2e3a"]]},{"id":"ddb41302.2e3a","type":"rbe","z":"35de3eaf.51455a","name":"Ignore repeats","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":420,"y":160,"wires":[["52bb2344.cb92f4"]]},{"id":"bec3321d.688e28","type":"mqtt in","z":"35de3eaf.51455a","name":"","topic":"shellies/shellyix3-xxxx/input/0","qos":"0","datatype":"auto","broker":"6d8018f0.c514b","x":140,"y":100,"wires":[["48c79dde.1cc034"]]},{"id":"48c79dde.1cc034","type":"rbe","z":"35de3eaf.51455a","name":"Ignore repeats","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":420,"y":100,"wires":[["52bb2344.cb92f4"]]},{"id":"e8a3452c.cb2a6","type":"comment","z":"35de3eaf.51455a","name":"sequr.be","info":"","x":700,"y":160,"wires":[]},{"id":"2ce15169.23b9de","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"6d8018f0.c514b","type":"mqtt-broker","name":"Mosquitto","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

* You can turn this behaviour off but I decided not to. Having the Shelly’s resend their state every so often helps in making sure HA is in sync with the Shelly’s and speeds up the syncing after a reboot of HA.
However, if you want to disable this behaviour, you can turn this off using the HTTP API of the Shelly’s. Simply make a call to http://<IP of the Shelly>/settings?mqtt_update_period=0.