Flash light red when motion detected

Hi there,

I’m trying to flash my Philips Hue Playbars red one time when a motion detector detects motion.
I’ve been searching around a bit but can’t find a way to get it working.
I’ve tried to put the following code in automation.yaml but I think I’m missing something.

#automation:
- alias: 'Flash Lights'
  trigger:
    platform: state
    entity_id: binary_sensor.0x00158d00031cd4ef_contact
    to: 'on'
  action:
    service: light.turn_on
    entity_id: light.playbar_links
      data:
        entity_id: light.playbar_links
        flash: short
        rgb_color: [252,3,3]

Any help is really appreciated :slight_smile:

1 Like

At the very least change it to this:

#automation:
- alias: 'Flash Lights'
  trigger:
    platform: state
    entity_id: binary_sensor.0x00158d00031cd4ef_contact
    to: 'on'
  action:
    service: light.turn_on
    entity_id: light.playbar_links
    data:
      flash: short
      rgb_color: [252,3,3]

have a look here

Found that one already :).
It’s way more than I want. The code get’s me a bit confused.

I only want a playbar to flash red once when a doorsensor opens.

Thanks.
This works :).

But now it stays red. Is it possible to turn it back after it flashes red?

Take a look at the examples on this page that use the new dynamic scene creation capabilities to save and restore lights, etc.

Thank you.
Will try to dig in that tomorrow, but I’m not that far into creating conditions :slight_smile:

I’ll give you the answer. Don’t look until you’re done reading, then check back here to see if you’ve got it. :stuck_out_tongue_winking_eye:

#automation:
- alias: 'Flash Lights'
  trigger:
    platform: state
    entity_id: binary_sensor.0x00158d00031cd4ef_contact
    to: 'on'
  action:
  - service: scene.create
    data:
      scene_id: before
      snapshot_entities:
      - light.playbar_links
  - service: light.turn_on
    entity_id: light.playbar_links
    data:
      flash: short
      rgb_color: [252,3,3]
  - delay: 5
  - service: scene.turn_on
    entity_id: scene.before

I added a 5 second delay to allow the flash to complete. I don’t know how long the flash will take, so adjust accordingly. Also, add the following to your config if it isn’t there. Otherwise the scene services won’t exist.

scene:
4 Likes

haha nice :stuck_out_tongue: . I might get a hang on it someday.
It looks simple and logical but I sometimes have struggles with the order.

If you want to add a second entity_id (sensor), do you copy the whole trigger part of only place a second entity_id ?

You mean you want the automation to be triggered by another sensor? If the type and other parameters of the trigger are the same then you can just add the entity_id:

  trigger:
    platform: state
    entity_id:
    - binary_sensor.0x00158d00031cd4ef_contact
    - binary_sensor.OTHER_SENSOR
    to: 'on'

When either sensor changes to on the automation will trigger.

That’s what I was looking for :slight_smile:
Thanks for the help !

Hey @pnbruckner,

I try to achieve something similar but currently cannot get it working. The trigger is the second step I want to tackle, starting first with the flashing part. Here is my automation:

- alias: 'Test'
  trigger:
    platform: time
    at: '23:45'
  action:
  - service: scene.create
    data:
      scene_id: before
      snapshot_entities:
      - light.hue_ter_4
  - service: light.turn_on
    entity_id: light.ter_hue_4
    data:
      flash: short
      rgb_color: [255,255,0]
  - delay: 5
  - service: scene.turn_on
    entity_id: scene.before

My issue is, that actually the light flashed in cold-white light and AFTERWARDS changes to the specified color and stays in that color. Any Idea what I have set up wrong?

Hi, any reason you chose 252,3,3 as RGB color instead of 255,0,0.
In my case I had to add the light simply turning on as red color before doing the flash, as they would otherwise flash white instead of red :

As two scripts (on and off) :

flash_lights_turn_on:
  sequence:
    - service: scene.create
      data:
        scene_id: before_flash_lights
        snapshot_entities:
        - light.lampe_portable
    - delay: '00:00:01'
    - service: light.turn_on
      entity_id: light.lampe_portable
      data:
        rgb_color: [255,0,0]
        brightness: 1
        transition: 0
    - service: light.turn_off
      entity_id: light.lampe_portable
      data:
        transition: 0
    - service: light.turn_on
      entity_id: light.lampe_portable
      data:
        flash: long
        rgb_color: [255,0,0]
        brightness: 255
        transition: 0


flash_lights_turn_off:
  sequence:
    - service: scene.turn_on
      entity_id: scene.before_flash_lights

I don’t know why, but using “short” flash does not work with my hue lights, only long works well…

[EDITS] : had tu turn on the light in red then turn it off before launching the flash, otherwise it would flash badly (white if I did not set red before the flashing, and not very nicely if I did not turn it off before flashing).
Also, added a delay just after the scene creation for restoring state, because without that HA would sometimes remember another in-between state…

1 Like

Hi Philippe @TheJuice ! Thanks for your help.

I copied your code snippet into a script and replaced the entity_id of the light with my own. Unfortunately I get the error message below when trying to save the script.

Message malformed: expected dictionary @ data[‘sequence’][0]

What didn’t I understand?

I’ve managed to get this working, using ChatGPT to code it! Have changed my device and entity ID’s:

alias: Flash TV Light when Doorbell Rings
trigger:
  - platform: device
    type: occupied
    device_id: 1201xxxxxx
    entity_id: 327f90xxxxxxxxx
    domain: binary_sensor
condition: []
action:
  - data:
      scene_id: before_flash_scene
      snapshot_entities:
        - light.living_room_tv_light
    action: scene.create
  - data:
      rgb_color:
        - 255
        - 0
        - 0
      brightness_pct: 50
    target:
      entity_id: light.living_room_tv_light
    action: light.turn_on
  - delay: 0.5
  - target:
      entity_id: light.living_room_tv_light
    action: light.turn_off
    data: {}
  - delay: 0.5
  - data:
      rgb_color:
        - 255
        - 0
        - 0
      brightness_pct: 50
    target:
      entity_id: light.living_room_tv_light
    action: light.turn_on
  - delay: 0.5
  - target:
      entity_id: light.living_room_tv_light
    action: light.turn_off
    data: {}
  - delay: 0.5
  - data:
      rgb_color:
        - 255
        - 0
        - 0
      brightness_pct: 50
    target:
      entity_id: light.living_room_tv_light
    action: light.turn_on
  - delay: "00:00:05"
  - data:
      entity_id: scene.before_flash_scene
    action: scene.turn_on
mode: single

Hi Simon, welcome to the forum!

2 things chatGPT didn’t tell you:

  • if you post yaml code, it’s a good idea to format it properly (</> sign in the toolbar)
  • you can use repeat for a block together with a number on how many times it should be repeated

Be careful not to go wild with chatGPT, it’s not really liked here.
From How to help us help you - or How to ask a good questionDon’t use ChatGPT but you’re a free person…