I am fairly new to home assistant and still learning the way to automate my smart devices. I realized there are a lot of possibilities which makes it quite hard some time to get things the way I want it. So far try and error did the trick for me but here’s something I can’t figure it out.
I simply create two scripts. one does flash a light 10 times in red for alarming me. Another one switches on the same light for 10s in green color.
First script for flashing the light does work, however it doesn’t change the color to red (hs_color: [0,100]). The second script works as well and here it actually changes the color to green (hs_color: [120,100]) independently from the color it had before. Exactly like it is supposed to be.
So what’s the difference between both scripts, so that the flashing script doesn’t change the color to red. Is
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.
This implies that first service call should set the color and subsequent ones request flash: short.
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.
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.
Effectively, you’ve changed the requirements because a scene doesn’t know anything about a light’s previoushs_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.
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.
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.
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.
Your first post in two years and it’s to reply to a post made two years ago. Interesting symmetry.
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.