Creating a Smart Bedtime Light Automation for Kids Using Home Assistant
Table of Contents
Creating a Smart Bedtime Light Automation for Kids Using Home Assistant #
I often find my children turning their lights on during the night when they wake up. I started off by having an automation which checked every hour if the light was on then switch it off then I had the bright idea 💡 that instead of constantly checking and turning off lights, I could create an automation that gradually dims and turns off their bedside lamps automatically after they have been turned on.
The Solution #
We’ll create a Home Assistant automation that:
- Detects when a bedside lamp is turned on during nighttime hours
- Automatically dims the light to 50% immediately
- Gradually dims the light over 10 minutes
- Finally turns the light off completely
Prerequisites #
- Home Assistant installed and running
- Smart bulbs or lamps that support dimming
- The lights already configured in Home Assistant
The Automation Code #
Here’s the YAML code for the automation:
alias: Dim Light Overnight
description: "Automatic dimming of bedside lights during night time hours."
triggers:
- entity_id:
- light.childs_bedside_lamp
from: "off"
to: "on"
trigger: state
conditions:
- condition: time
after: "00:00:00"
before: "06:00:00"
actions:
- data:
brightness_pct: 50
action: light.turn_on
target:
entity_id:
- light.childs_bedside_lamp
- repeat:
count: 10
sequence:
- data:
entity_id:
- light.childs_bedside_lamp
brightness_step_pct: -5
action: light.turn_on
- delay:
minutes: 1
- data: {}
action: light.turn_off
target:
entity_id:
- light.childs_bedside_lamp
mode: single
How It Works #
Let’s break down each section of the automation:
Trigger #
triggers:
- entity_id:
- light.childs_bedside_lamp
from: "off"
to: "on"
trigger: state
This trigger activates when the specified light changes from off to on.
Conditions #
conditions:
- condition: time
after: "00:00:00"
before: "06:00:00"
The automation only runs between midnight and 6 AM.
Actions #
The automation performs three main actions:
- Initial Dim:
- data:
brightness_pct: 50
action: light.turn_on
Immediately dims the light to 50% brightness when turned on.
- Gradual Dimming:
- repeat:
count: 10
sequence:
- data:
brightness_step_pct: -5
action: light.turn_on
- delay:
minutes: 1
Reduces brightness by 5% every minute for 10 minutes.
- Final Turn Off:
- data: {}
action: light.turn_off
Completely turns off the light after the dimming sequence.
Installation #
- In Home Assistant, navigate to Configuration > Automations
- Click the + button to create a new automation
- Click the three dots in the upper right corner and select “Edit in YAML”
- Copy and paste the above code
- Replace
light.childs_bedside_lamp
with your light entity ID - Save the automation
Customization Options #
You can modify this automation by:
- Adjusting the time window in the conditions
- Changing the initial brightness percentage
- Modifying the dimming duration and steps
- Adding multiple lights to the automation
Conclusion #
This automation provides a gentle way to help children return to sleep when they wake up at night. Instead of an abrupt light-off experience, the gradual dimming helps ease them back to sleep naturally.
Remember to test the automation during the day first by temporarily modifying the time condition to make sure it works as expected.