How to make lights flash around the house when a sensor is triggered

This automation will flash specific lights around your house when a sensor is triggered to visually notify you about it without relying on push notifications or audible messages.

This is useful to silently notify you if a door or window has been opened, a motion sensor triggered or any other trigger you can think of in Home Assistant! This can help you increase your home security by making you aware of what is going on.

One use case that I've seen this work well for is flashing lights red in the living room and kitchen when a child's bedroom door is opened after bedtime. This can alert you if your child has gotten out of bed and left their room because they need to go to the bathroom or have had a bad dream, then you can go over to them and help them out.

You could use this same automation for other reasons too, such as telling you that the garage door has been opened, a water leak is detected by a leak sensor, or if motion was detected by your security cameras.

To make this automation work you’ll need the following:

  1. A working Home Assistant installation

  2. Some Contact Sensors (or other sensors) paired with Home Assistant

  3. Some Lights paired with Home Assistant. I am using Philips Hue LED strips which have a built in flashing function.

Trigger

This automation is triggered by a simple state trigger when a sensor that you have access to in Home Assistant changes state.

In this example we're using a contact sensor to check if a door is opened, but you could easily adapt it to use a motion sensor, water leak sensor or even a wireless button. The state trigger is triggered when the contact sensor state goes from off to on.

Contact Sensors are really confusing, their state is set to on when the door is opened. You can validate this yourself by opening one of the doors and then looking at that contact sensor in the developer tools.

Sonoff Contact Sensor for an open door showing on state, but contact is false.

Sonoff Contact Sensor for an open door showing on state, but contact is false.

Here is the trigger block in YAML:

platform: state
entity_id: binary_sensor.bedroom_door_contact_sensor_contact
from: 'off'
to: 'on'

Conditions

In my example, where we want to be notified if a child has opened their bedroom door after bedtime, I want to make sure that the lights only flash red after they've gone to bed. You don't want the lights flashing red randomly throughout the day as people go in and out of the bedroom.

To achieve this I'm using a time condition to make sure that the automation only completes if it's currently between 8pm and 1am.

Screenshot showing time condition in Home Assistant

A more advanced version of this automation would be to create a binary sensor called "Bed Time" in Home Assistant that you can turn on and off when the child goes to bed. This would allow you to replace the time condition with a state condition and allow you to arm this automation any time the child goes to bed - regardless of the time of day. You could even put a wireless button near the child's bedroom door that toggles this sensor on and off.

If you want to always be notified of a sensor changing state, you can remove the condition altogether.

Here is the condition block in YAML:

condition: time
after: '20:00'
before: '01:00'

Action

This automation uses a complex, multi-step action that performs the following steps:

Firstly, we create a dynamic scene that captures the current state of the Kitchen and Living Room lights. This will allow us to set the lights back to their original state once the flashing stops. If we don't do this the lights will flash red, and then stay on solid red until you change them to another colour.

To achieve this we're using the scene.create service to save all the attributes like brightness, colour, on/off state etc to a temporary scene called TheBeforeTimes.

Screenshot showing the action for the scene.create service in Home Assistant

Next, we use the light.turn_on service to set the TV and Kitchen lights to flash red. I'm using the long flash function of the Philips Hue lights that I have mounted behind my TV and under my kitchen cabinets.

Screenshot from Action of Home Assistant showing the light.turn_on service and how to flash the lights red

The next part of the action simply waits for 16 seconds. This is the amount of time it takes for my Hue lights to finish their flashing effect - I simply timed it with a stopwatch to get this figure.

I use a delay action type for this.

After 16 seconds the lights will have stopped flashing and we can re-apply whatever settings the lights previously had set by re-applying the dynamic scene that we saved at the start of the automation.

I use the activate scene action to re-apply the scene we created at the start of the automation called TheBeforeTimes.

Screenshot showing automation action which turns on a scene.

This will now set the lights back to how they were before the flashing started.

Full Automation in YAML

Here is the full automation in YAML format:

alias: 'Light: Flash light when bedroom door is opened'
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.bedroom_door_contact_sensor_contact
    from: 'off'
    to: 'on'
condition:
  - condition: time
    after: '20:00'
    before: '01:00'
action:
  - service: scene.create
    data:
      scene_id: thebeforetimes
      snapshot_entities:
        - light.kitchen_lights
        - light.tv_lights_group
  - service: light.turn_on
    data:
      flash: long
      color_name: red
    target:
      device_id:
        - ad84a1f65afae779089a4abb9f10db1c
        - db71bf3671ad4b17b57408c25e35cd6a
  - delay:
      hours: 0
      minutes: 0
      seconds: 16
      milliseconds: 0
  - scene: scene.thebeforetimes
mode: single

More information about these concepts

Video showing the flashing lights in action

More information about Dynamic Scenes in Home Assistant

Previous
Previous

Door and Window Sensor Automation Ideas - Using Contact Sensors in Home Automation

Next
Next

Get notified when your Washing Machine has finished it's wash cycle using Smart Switches and Contact Sensors