Took me a little while to get this working.
What I wanted was my hall light to turn red if anyone was in the toilet and then when the toilet was no longer in use to turn the hall light back to its previous state. I like the hall light a certain shade of blue so I didn’t need to capture the previous colour, you may need to capture this if you want to return it back to whatever colour it happened to be on.
I captured the switch status so that it always turned off after the toilet was no longer occupied if it was off before anyone used it and left it on if it was on before hand.
I have a separate piston that turns the toilet light on when in use, and this assumes that the toilet light does not turn off until a short wile after it is vacated. Therefore I am able to use the fact that the toilet light is still on as control on the if statement that returns the hall light back to its previous state.
The devices I needed to make this work was
- Motion sensor in toilet
- Smart bulb in toilet
- Coloured smart bulb in hall
Here is the piston