Example piston to turn a light red outside a room (toilet) if it is in use


#1

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


#2

This is interesting. For your 2nd If statement, if motion is inactive and the toilet light is on then you take action for the hallway light? I am not following this piece as I thought it would only take action on the hallway light after the toilet is vacated and the toilet light is off…

Sorry - still learning…


#3

There are many ways to skin a cat.

I could have used when toilet light changed to off

But I wanted to leave the toilet light on for a few minutes after it is vacated as the light switch also controls a fan.

So to prevent the piece of code running when no one has used the toilet I used when the toilet light is still on.