Waiting until the light is off to adjust default dimmer level

wait
light

#1

1) Give a description of the problem
The bathroom light dimmers should be set to a bright default level during the day and dim level at night (100% and 1%, respectively). However, it would be rude to dim the light if it happens to be in use. Youngsters make our schedule inconsistent enough for this to not be a matter of simply choosing a better cutoff time.

I am using GE dimmer switches which just reuse the previous level. Setting the level turns the lights on so I have to immediately turn them back off.

2) What is the expected behavior?
If the light is off, adjust default level immediately, otherwise wait until the light has been off for a short period of time (because there can be a brief flash of light when the level is set), then adjust the default level.

3) What is happening/not happening?
It seems like the Followed By operator should work for this but I couldn’t find any combination of triggers or conditions that paused until the light turned off. Seemed like I should be able to do something like if switch is off or (switch is on followed within 20 minutes by switch stays off for 30 seconds) but anything using followed by evaluated immediately. I would like something that works inside the async for each so that I can easily add more lights to this.

For now I use a while loop that calls Wait until the light has been off for 30 seconds. This works fine but feels like a hack.

4) Post a Green Snapshot of the pistonimage
It works, but I think there should be a better way to do this:

5) Attach any logs (From ST IDE and by turning logging level to Full)
Tried so many things I’m not sure which logs would be applicable. In cases where followed by did not work, the entire condition just evaluated to false immediately.


#2

I defined a variable at the top and used ternary operator to determine the light level it should use based on my location mode. This way each time the piston runs it determines the level and then if it decides it needs to turn the light on then it sets the level from the variable. This is from my HVAC piston but you get the idea.

($locationMode == "Home - Dawn" ? 70 : ($locationMode == "Home - Day" ? 74 : ($locationMode == "Home - Night" ? 72 : ($locationMode == "Sleep" ? 68 : 77))))


#3

Correction, the piston in OP does not work because the variable is reset to its default value (-1) after the action goes asynchronous. The logic works otherwise, just tries to dim to -1%.

Suppose I will need to change how this works a bit to accommodate a normal variable that maintains its value through piston runs.