Flash a light with a specific color

Having just recently acquired a few Hue color lights, the problem you described intrigued me.

I performed a few simple experiments using Developer Tools > Services. I tried different combinations for hs_color, and then using color_name, but the result was always the same: the light flashes (once) using whatever color it was originally set to use and not the one specified in the service call.

Screenshot from 2020-05-06 10-21-35

This implies that first service call should set the color and subsequent ones request flash: short.

great. thx. that did the trick.

the last service call should probably be the color being used before the script went off. Is there any way to save and recall this last state?

BR

I can’t think of an elegant way to do that. The light’s current color (before you change it with the script) is not stored anywhere. Therefore the last service call in your script won’t know what color to use.

The light’s hs_color attribute is not available when the light is off. So your script can’t get this initial value unless the light is already on.

Would this work ? Not tried it myself, apparently you can save a state and restore it

Creating scenes on the fly

EDIT, no not quite, only restores state and not colour

Correct. You would want the scene to store and restore attributes and it doesn’t support that.

well, for now I think I just figure out the color code being used normally and call it as a service at the end of the blinking script.

Maybe this ?

No. That python_script has to work with the same limitations. A light’s attributes, like hs_color, are only available when the light is on. The python_script saves the light’s attributes only if it is on. Here’s the relevant line:

if entity_id.startswith('light.') and cur_state.state == 'on':

from here:

Peter’s requirement is to get the light’s initial color prior to the first flash operation while it is still off.

One workaround would be to initially turn on the light, pause a moment, then read and save its hs_color attribute (to an input_text) and then proceed to flash the light. At the end of the flashing process, the value in the input_text can be used to set the light to its initial color, pause, then turn it off.

1 Like

thanks for the answers. I started to set all light scenes via home assistant. This way it is actually not needed to save latest color state.

for the sake of completeness, here the working code for flashing the light

  alias: Flash Hue Go - red 10x
  sequence:
  - data:
      brightness: '255'
      hs_color:
      - 0
      - 100
    entity_id: light.hue_go
    service: light.turn_on
  - data: {}
    entity_id: light.hue_go
    service: light.turn_off
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on
  - delay: '1'
  - data:
      flash: short
    entity_id: light.hue_go
    service: light.turn_on

Best

1 Like

Effectively, you’ve changed the requirements because a scene doesn’t know anything about a light’s previous hs_color.

For example, let’s say the light is turned on and set to blue, then turned off. If you run a scene now involving that light, the scene doesn’t know the light’s color was blue so it can’t restore it to blue.

alright let me explain this more detailed.

the situation was the following:

  • the flash of this particular light goes off with a color red.
  • later on, I switch on a scene via philips hue hub directly. This way, the scene uses the latest color of the involved lights. In this case the light being used for flashing turns red instead of the color set via hue hub.
  • The workaround I use is that I don’t use the scenes from hue hub anymore but instead created scenes within home assistant which basically do the same but have dedicated color for each light in this scene. So it actually overwrites the color red by the color being set up in the HA scene.

Point is, if I use scenes in HA with defined colors for each bulb, I don’t need to save the color of the lights before the flash goes off.

?

A Hue scene can specify each light’s color.

  • The advantage of a Hue scene is that Home Assistant sends one command to activate the Hue scene and all lights within the scene change to the desired state (and color, etc) simultaneously.

  • A Home Assistant scene sends commands for each and every light defined in the scene.

FWIW, I use Hue scenes to set groups of lights to specify colors and brightness and that takes precedence over whatever previous color and brightness they may have had.

your just off loading the calls to the bulbs to hue, it does the exact same thing…

I have been trying to get this to work and since the last HA upgrade this will not work for me at all. is anyone having the same issues?

But differently (one’s more efficient than the other).

Works fine for me with 2021.9.6.

It’s not exactly the same. When you create a scene in HA, there will be one command for each light sent to the zigbee hub, which can lead to delayed or even lost commands, especially if there are a lots of lights involved. However if you create a scene on the zigbee hub, only one command will be sent to the zigbee hub and it will be propagated automagically to all the involved lights, no delayed or lost cpmmands.

Yes if you create a Helper( in devices and services) to record and track the last state it could be used

Your first post in two years and it’s to reply to a post made two years ago. Interesting symmetry. :slightly_smiling_face:

In my now ancient post I wrote “I can’t think of an elegant way to do that”. Monitoring a light’s hs_color value and storing it in a Helper everytime it changes, isn’t particularly elegant. Nevertheless, post an elegant example of how to store/restore the list value of hs_color.

I run this in my scripts before I make a scene change, works like a charm…

service: scene.create
data:
  scene_id: temp_scene
  snapshot_entities:
    - light.office_1
    - light.office_2
    - light.book_shelf

this creates a scene on the fly that you can call to revert back. hope it works for you.

… Bingo!