I have an automation question that I’m hoping some one can assist me with. What I’m attempting to do is setup an Event Based Automation. I have the event part working fine, the action is where I’m struggling. What I want to have happen when the event is triggered control some LED lights strips using the flux_led integration. The high level steps for the automation action are below:
Get LED Lights Current State and save it.
Change LED Light Color
Wait X number of seconds
Return LED Lights back to their previous state (i.e. what was gathered in Step 1)
Changing light colors and brightness is very simple. The part that I’m having issues finding a way to accomplish is getting the current state, saving it and the sleeping in an automation execution. Is this possible and if so are there any example of how I can accomplish this?
You might be interested in my Light Storepython script. It was written to save & restore lights, including their attributes (such as brightness and color.) I haven’t used it with LED lights, so if you run into trouble, let me know.
As far as “sleeping” goes in an automation’s actions, that’s a simple delay.
Thank you for the suggestions & links. I read up on Light Store, but ended up solving my problem another way. I figured I’d post my solution here in the event that anyway one runs into the same problems.
What I ended up doing is writing a bash script that calls flux_led -i to get the current settings off the LED light strips strips and then saves it to a variable in the script. After that I continue to call flux_led & sleep to complete the steps I outlined above. Once the script was written and tested I was able to call it via a shell_command in my automation and everything is working as expected.
Thanks again for the suggestions. I need to do some more reading on the python scripts link you sent as that might be a cleaner was to accomplish what I’m doing.
FWIW, it’s possible to achieve your request using automations.
You can store the light’s current state in an input.text or input.number (this is the long-standing way of storing variables in Home Assistant). Alternately, you could use a custom component like either Home Assistant Variables or HASS Variables to store the light’s current brightness and RGB color.
Restoring the light’s brightness is easy. Restoring its RGB color, using an automation, is a bit more challenging because it is in the form of a list [255,125,165] and you can’t generate this data structure with a template (but there’s a workaround).
As already mentioned, delay can pause the action’s execution for a given time period.
So, it’s all doable with YAML automations but, given that an existing, superior solution (pnbruckner’s Light Store python_script) is already available, probably not worth the effort (unless one enjoys the challenge).