Lately I've been going a bit more advanced in some of my automations thanks to my wife/Partner and the W/PAF (Wife/Partner Appreciation Factor) being high with HE.
Where I struggled the most was in trying to understand the most effecient use of Private Booleans, Variables and Global Variables along with how to capture much more complex previous states.
To help the future person like me who was wrestling with this, I've created this post to document two specific scenarios I have as an example for others and ideally conversation around even better ways to achieve some of these or other advanced automations.
While my use-cases may be unique, they can easily be applied to a ton of other scenarios where you wish you could easily know or even get back to your previous state before the automation kicked in.
So on to the automations...
- Turn on Closet Light when door opens, turn off when closed, but leave on if the light was already on before the door opened
To achieve this, I was really unsure if I should go down the path of a Global Variable to store the state of the light being on or off when the door is opened, or something else. In a thread I can't find right now, it was suggested that using a Private Boolean was the most resource friendly way to use a variable that is only needed in one Rule.
Here is where I landed.
i. If the Closet door is opened, set the Private Boolean to the current state of the light (on/off), then proceed to turn on the light. Set a cancel-able timer to turn off the light if the door is left open for too long. Also set the light dim value per mode.
ii. If the Closet door is closed, and the light wasn't already on, cancel the timer set on open, and turn off the light. If it was already on, just leave the light on.
- Turn on a large set of lights when my Roomba is cleaning, when it's done, revert all of the lights back to the state they were in before the Roomba kicked off.
i. First thing Id did was create a scene for the Roomba Cleaning which turns on the lights I want on.
ii. Secondly I created another scene in the reverse, same devices, just all set by default to off. For this one I turned on the "Create Capture Device", so I can use this scene as basically a variable for capturing the state before the Roomba starts cleaning.
iii. Third, I created a Rule that will Capture the current state of lights when the Roomba starts cleaning, then after 5 seconds activates the Roomba Cleaning scene.
When the Roomba is done cleaning, I activate the previous stored scene so my house is exactly in the state it was before the Roomba kicked off.
I hope this is helpful to others!
And if you see any place I could have optimized, I'm all ears to make improvements here!