Recently I started using Home Assistant (HA) as a tool to control the lights in my home. My previous system was based on Homekit and, while working fairly good, lacked tools to further customize the automations. To get more control I switched to HA.
One of the first things I created using HA was a room wake-up light. I do own a Philips wake-up light but this doesn’t light up my whole room so that left room fore improvement. The automation I built using Home Assistant slowly lights my room every morning. The system works with any smart lamp that is compatible with HA, this includes Philips Hue] and IKEA Tradfri lamps. I use it with a few GU10 bulbs (like the Hue GU10 lights).
In this post I’ll show you how to build this system. The automation will be configurable (on/off, time) and has a switch to disable it on weekends.
More interested in Node-RED? Please read my post titled “Node-RED based custom full-room wake-up light”.
Example hardware
I’ve used the following components for my Wake-up light:
- Home Assistant running on a Raspberry 3B+
- Conbee Zigbee hub; there is a USB version and a PI version. (More info here)
- Three GU10 Zigbee smart lights. I use 3 Innr GU10 lights (not available in the US) but you could also use something like the lights from Philips Hue.
These components are just an example. A minimum requirement is a device that runs Home Assistant and a smart light that you can control.
My Home Automation hardware setup
Time sensor
First step is to add a new sensor that measures time. This sensor will trigger the automation at the correct time. Add the following to sensors.yaml
:
# sensors.yaml
- platform: time_date
display_options:
- 'time'
Make sure that this file is included in your configuration.yaml
file, if not add the following:
# configuration.yaml
sensor: !include sensors.yaml
Create dashboard widget
Next we build the dashboard widget. The widget consists of three controls: (1) a time input to control when the lights should go on, (2) an on/off switch and (3) a switch to enable the system on weekends.
We start with the two switches which are implemented as an input_boolean
. Add the following to configuration.yaml
:
# configuration.yaml
input_boolean :
wakeup_enabled:
name: "Wake-up lights"
initial: on
icon: mdi:theme-light-dark
wakeup_weekend:
name: "Enable Wake-up on weekends"
initial: off # I disable the system on default on weekends
icon: mdi:calendar-blank
The icons can be customized, see Material Design Icons for more options.
The third input controls the time of the wakeup light. For this we use input_datetime
with the date component disabled as we are only interested in time.
# configuration.yaml
input_datetime:
wakeup_time:
name: "Start lights at"
has_time: true
has_date: false
initial: "07:20"
To group the controls together in a single card on the dasboard we need to make a new group. Add the following to the groups.yaml
file. Again make sure that this file is included in configuration.yaml
.
# groups.yaml
alarm_clock:
name: "Wake-up Lights"
entities: # Add all entities here that should be part of the widget
- input_datetime.wakeup_time
- input_boolean.wakeup_enabled
- input_boolean.wakeup_weekend
Note: As someone pointed out in the comments, if you want to persist the values between restarts of Home Assistant remove the ‘initial’ value from the configuration.
Create the automation
With all controls defined we can make the automation itself. The automation consists of three components: the trigger, the condition and the action. Add the following to automations.yaml
:
# automations.yaml
- alias: "Wake-me up using bedroom lights"
trigger:
# Something that triggers the automation
condition:
# A list of conditions that need to be met
action:
# The action we want to perform.
The trigger is based on the time sensor we just created. It gets the state of the sensor and checks whether this value matches the value of our datetime input.
trigger:
platform: template
value_template: "{{ states('sensor.time') == (states.input_datetime.wakeup_time.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
The trigger we defined above will fire regardless of the on/off switches. To include the switches in the automation we have to create a list of conditions. The first condition checks whether the wake-up light is enabled, if not the automation is not executed at all. Then we add an or
condition that checks whether it is a weekday (a condition on time) or that the weekend switch is enabled. Only one of the or
conditions has to be met.
condition:
- condition: state
entity_id: input_boolean.wakeup_enabled
state: 'on'
- condition: or # One of the conditions below must be true
conditions:
- condition: state # Will be true when the switch is 'on'
entity_id: input_boolean.wakeup_weekend
state: 'on'
- condition: time # Will be true on weekdays
weekday:
- mon
- tue
- wed
- thu
- fri
Last we define what to do when all conditions are met. In my case I slowly fade in all the lights in the group.bedroom
group. You can add your own lights here.
action:
- service: light.turn_on
entity_id: group.bedroom # Put the entity of your light or your group here
data:
transition: 600 # Transition time in seconds
brightness: 255
The full automation with everything filled in, this should be placed in automations.yaml
.
# automations.yaml
- alias: "Wake me up with bedroom light transition for weekdays"
trigger:
platform: template
value_template: "{{ states('sensor.time') == (states.input_datetime.wakeup_time.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
condition:
- condition: state
entity_id: input_boolean.wakeup_enabled
state: 'on'
- condition: or
conditions:
- condition: state
entity_id: input_boolean.wakeup_weekend
state: 'on'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: light.turn_on
entity_id: group.bedroom
data:
transition: 600
brightness: 255
Enable the automation
With everything filled in restart HA. The widget should be available on your dashboard. From there you can enable the widget and set a custom time. Your lights should now go on at the defined time 💡.
Series on Home Automation
This post is part of a series of posts on Home Automation. These posts usually cover a part of my own smart home or a project I worked on. I make heavy use of Home Assistant, Node-RED and AppDaemon to control my home; these posts are examples of this.
Interested in my setup?
Home Automation hardware setupOther posts in this series
Interested in Home Automation, Home Assistant or Node-RED? I have a few other posts that might be of interest:
Home Automation / Home Assistant setup with recommended hardware: The four-year update
Overview of my current hardware for my smart home powered by Home Assistant. An update on my previous post of four years ago (!) when I had just started with home automation.
Automatically turn on tv when streaming to a Chromecast
Quick Node-RED tutorial on automatically turning on a TV when streaming media.
Automatic dark mode for Home Assistant
Quick tutorial on setting up an automatic dark mode for Home Assistant.
Gary on
Checked your automation and is looking great.
However, using Ikea's Tradfri, it sadly seems not to work.
Is this automation stille working for you and any idea how I could troubleshoot please?