I’m trying to figure out a way to query the state (brightness, color_temp, etc.) of my LIFX light bulb when it is off. Unfortunately, LightEntity does not expose the state attributes in the normal way when lights are off.
Is there any way to bypass this and get to the raw data in an automation?
For context, what I’m trying to do is fade my lights to warm at sunset, but only if I haven’t already manually changed the color. If the light is temporarily off when the automation fires, I can’t query the color.
As you have discovered, when a light entity’s state is off it no longer stores brightness, etc in is attributes. So where is this purported “raw data” you mentioned located? In the device itself?
If it is, the LIFX integration offers no service to retrieve it (only a service to set certain parameters while the light is off).
The data is stored on the device and is even stored in the Python object in Home Assistant. If you killed the line I linked to, you could absolutely read the data. I was hoping to be able to bypass that sanitization step somehow.
If it’s stored on the device, its inaccessible to automations because the LIFX integration offers no service to read it. Perhaps you could use LIFX’s published HTTP API to acquire the value via the List Lights call.
I’m not sure what you mean about stored in a Python object; if it’s not stored in the state-machine it’s equally inaccessible to automations. Unless you mean you wish to modify the LIFX integration in order to acquire that data.
I had a similar problem. When my motion automation triggered my lifx lights, it would reset the color to white if the bulbs were off. What I wound up doing in node red was to use an automation that calls scene.create then shuts the light off, rather than just turning it off. You could then query the scene that was created possibly?
I think… If you use the trigger state node in node red then it will trigger each time you turn on or off the light.
So when you turn off the light read the message and you should have old_state values, which is what the light was before it was turned off.
If you save those values then you should be able to turn it on with the same settings, if that is what you are looking for.
On a related note, there’s a PR in the Core repo to display a light’s attributes even while it’s off. However, it’s a Breaking Change and Frenck explains the potential pitfalls. Note: based on a quick review, the PR is for displaying the attributes, not for setting them while the light is off (which few lights offer).