Here’s a set of Pistons that I use to control my house lighting by Mode. Each room has individual settings for the lights (color, temperature, and/or level) and for the non-motion off times. There are 4 Pistons:
#1: Variables - RGBW Light Settings
The first Piston is triggered by a change of the locationMode. It sets the light settings variables for the each of the Rooms and then checks to see if any lights are on. If a Room’s lights are on, then it calls that Room’s Action Piston (see Piston #4 below) to adjust the lights in that room.
#2: Variables - offTimes
The second Piston is also triggered by a change of the locationMode. It sets the offTime variable for each of the Rooms. This one also sends a notification to ST containing the offTimes for the mode and adjusts the Piston state to show those as well.
#3: Room Light Rules
The third Piston is an example of my Room Rules Piston. Each room has its own set of rules by which the lights come on/off (motion, door opening/closing, presence, etc.), so I use one for each room.
The 1st If block - Rules to turn lights on
- There are 3 restrictions: 1) is @home true? - This checks whether anyone is home (via a global boolean variable that is toggled by another Piston for presence); 2) is Room_Override switch off? - I have an override switch that can be turned on or off manually via Alexa; and 3) has it been more than 5 seconds since last call to Piston? - This prevents duplicate calls.
- It checks if a) the room’s lights are off and b) if the room’s motion sensor(s) detects motion or the room’s door(s) opens. If so, then it calls the Room’s Action Piston (#4 below), and it sends a notification/changes Piston state showing why it did so and when.
The 2nd If block - Rules to turn lights off
- It has 1 restriction: is Room_Override switch off?
- It checks if a) the room’s lights are on and b) the room’s motion sensor(s) detects no motion for the time set in the room’s offTime global variable (set above in Piston #2). If so, then it turns off the room’s lights, and it sends a notification/changes Piston state showing why it did so and when.
#4: Room Light Actions
The fourth and final Piston is an example of my Room Action Piston. I use one for each room - in this case, my kitchen. This Piston has no triggers, and will only be executed by calls from Pistons #1 or #3.
- There are 2 restrictions: 1) is Room_Override switch off? and 2) is @home true?
- It sets the lights either by color temperature or color (I use color for certain modes and temperature for other modes), and then sets the level. The light settings used come from the global variables set in Piston #1. It then sends a notification/changes Piston state showing the room’s current light settings.
Enjoy!