Motion Sensor/Closet Light Switch Conundrum
Goal
Goal
- Have light in the large walk-in closet come on automatically when the motion sensor that monitors the door sees motion.
- Allow the light switch for the closet to turn off the closet light
- Allow the light to be turned off remotely when a dog opens the closet door and it is inconvenient to go back to the closet
Challenge
Challenge
- Generic Smart Home automation
- The switch that controls the light is located inside the closet itself and the closet door swings into the closet. As a result, when the goal is to turn off the light and then close the door, the motion detector registers motion and turns the light back on.
Options
Options
- Relocate the motion sensor so that it is not triggered by using the switch or closing the door. This option was rejected because it caused too long a delay in turning on the light when someone is walking into the closet
- Use automation capabilities within Hubitat HE to turn on the light when normal motion has occurred, but to create a modifiable grace period after the switch turns off the light during which the motion sensor is ignored.
Common Assumptions
Common Assumptions
- Hubitat Elevation is installed and running
- Hubitat Dashboard Built-In App is installed
- Hubitat Rule Machine 4.0 Built-In App is installed
Solution Description
Solution Description
- Install a Smart Wall Switch to control the light
- Install a Motion Sensor that registers doorway activity
- Pair both devices to Hubitat
- Inside Rule Machine Create 2 Global variables
- Seconds of Delay For Master Closet (This will be used to specify how many seconds the motion sensor should be ignored for after the light is turned off)
- Type-Number
- Initial Value - 5 (seconds)
- Ignore Master Closet Sensor (This will be used to know whether to ignore motion sensor triggers to turn on the light)
- Type-Boolean
- Initial Value - False
- Seconds of Delay For Master Closet (This will be used to specify how many seconds the motion sensor should be ignored for after the light is turned off)
- Inside Rule Machine Create Variable Connectors for these 2 variable. The connector is needed to display allow the dashboard to interact with the variables' values.
- Create a tile on a dashboard to show and allow alteration of the Seconds of Delay For Master Closet variable. (During initial building and troubleshooting I also built tiles for the motion sensor, light switch and the Ignore Master Closet Sensor variable, but these are not really needed for the process in the long run)
- Create the required rules:
- Rule 1:
Original Version
Updated Version
- When motion detected and Ignore Master Closet Sensor is False, then turn on the switch
- I also had to update the rule because sometimes the motion sensor would be triggered by the action turning off the light and the portion of the rule to turn the light on would happen immediately after the light was turned off resulting in the light popping right back on. The image above shows the updated rule.
- Because I found the Rule Machine interface confusing to build this rule, I wanted to put a step by step on how to build theis rule:
- Select Apps
- Select Rule Machine
- Select Create New Rule
- Name Rule
- Select Select Trigger Events
- Select Motion from the drop down
- Click the Motion sensors Click to Set
- Select the correct Motion Sensor
- Click the Update button or Motion sensors Click to Set
- By default the Motion becomes field should be active, but if not select if from the Motion becomes drop down
- Click Done with this Trigger Event
- Click Done with Trigger Events
- Click Select Actions to Run
- Click Select Action Type to Add to get drop down
- Click Conditional Actions from the drop down
- Click Select Which Action to get drop down
- Click IF (conditions) THEN from the drop down
- Click Click to set to get the Define condition drop down
- Click --> New Condition from the drop down
- Click Click to set to get the capability for Action Condition drop down
- Click Variable from the drop down
- Click Click to set to get Variable drop down
- Click the global variable created earlier from the drop down. In my case that is Ignore Master Closet Sensor
- Click Click to set to get the Boolean drop down
- Click False from the drop down
- Click Done with this Condition
- Click Done with Conditional Action
- Click Select Action Type to Add to get drop down
- Click Control Switches, Push Buttons
- Click Select Which Action to get drop down
- Click Turn Switches on
- Click Turn switches on to get list of switches
- Select the correct Switch
- Click Update
- Click Select Action Type to Add to get drop down
- Click Conditional Actions from the drop down
- Click Select Which Action to get drop down
- Click END-IF (conditions) THEN from the drop down
- Click Done with this action
- Click Done with Actions
- Click Done
- Rule 2:
- When the switch is turned off, set Ignore Master Closet Sensor to True, delay as many seconds as specified in Seconds of Delay For Master Closet then set Ignore Master Closet Sensor to False
- Because I found the Rule Machine interface confusing to build this rule, I wanted to put a step by step on how to build this rule:
- Select Apps
- Select Rule Machine
- Select Create New Rule
- Name Rule
- Select Select Trigger Events
- Select Switch from the drop down
- Click the Switches Click to Set
- Select the correct switch
- Click the Update button or Switches Click to Set
- Click the Switch turns drop down
- Click off
- Click Done with this Trigger Event
- Click Done with Trigger Events
- Click Select Actions to Run
- Click Select Action Type to Add to get drop down
- Click Set Mode or Variables, Run Custom Action from the drop down
- Click Select Which Action to get drop down
- Click Set Variable from the drop down
- Click Click to set to get the Select Variable to Set drop down
- Click the global variable created earlier from the drop down. In my case that is Ignore Master Closet Sensor
- Click Click to set to get the options for the variable drop down
- Click True
- Click Done with this action
- Click Select Action Type to add to get drop down
- Click Delay or Repeat Actions, Wait from the drop down
- Click Select Which Action to get drop down
- Click Delay Actions from the drop down
- At this point if I wanted to come back and change the delay but modifying the rule directly you can, however, because I wanted it to be adjustable via the dashboard, I put the global variable (Seconds of Delay For Master Closet) into the Seconds field surrounded by % ie. %Seconds of Delay For Master Closet%
- Click Done with this action
- Click Select Action Type to add to get drop down
- Click Set Mode or Variables, Run Custom Action from the drop down
- Click Select Which Action to get drop down
- Click Set Variable from the drop down
- Click Click to set to get the Select Variable to Set drop down
- Click the global variable created earlier from the drop down. In my case that is Ignore Master Closet Sensor
- Click Click to set to get the options for the variable drop down
- Click False
- Click Done with this action
- Click Done with Actions
- Click Done
7. Test the automation
8. If the delay when the motion sensor will be ignored needs to be changed, then the variable's value either be changed inside Rule Machine or via the dashboard tile