Motion Sensor/Closet Light Switch Conundrum

I have been working on this and wanted to share what I think is a good solution, but also solicit feedback if anyone has suggestions for solving this is a better way.

I recognize that this is likely somewhat redundant with this discussion:

I am starting to document my Smart Home journey on my own website, and so have the description on my personal site.

Goal

  1. Have light in the large walk-in closet come on automatically when the motion sensor that monitors the door sees motion.
  2. Allow the light switch for the closet to turn off the closet light
  3. 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

  1. Generic Smart Home automation
  2. 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

  1. 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
  2. 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

  1. Hubitat Elevation is installed and running
  2. Hubitat Dashboard Built-In App is installed
  3. Hubitat Rule Machine 4.0 Built-In App is installed

Solution Description

  1. Install a Smart Wall Switch to control the light
  2. Install a Motion Sensor that registers doorway activity
  3. Pair both devices to Hubitat
  4. Inside Rule Machine Create 2 Global variables
  5. 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)
    1. Type-Number
    2. Initial Value - 5 (seconds)
  6. Ignore Master Closet Sensor (This will be used to know whether to ignore motion sensor triggers to turn on the light)
    1. Type-Boolean
    2. Initial Value - False
  7. 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.
  8. 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)
  9. Create the required rules:
Many Tedious Steps
  1. Select Apps
  2. Select Rule Machine
  3. Select Create New Rule
  4. Name Rule
  5. Select Select Trigger Events
  6. Select Motion from the drop down
  7. Click the Motion sensors Click to Set
  8. Select the correct Motion Sensor
  9. Click the Update button or Motion sensors Click to Set
  10. By default the Motion becomes field should be active, but if not select if from the Motion becomes drop down
  11. Click Done with this Trigger Event
  12. Click Done with Trigger Events
  13. Click Select Actions to Run
  14. Click Select Action Type to Add to get drop down
  15. Click Conditional Actions from the drop down
  16. Click Select Which Action to get drop down
  17. Click IF (conditions) THEN from the drop down
  18. Click Click to set to get the Define condition drop down
  19. Click --> New Condition from the drop down
  20. Click Click to set to get the capability for Action Condition drop down
  21. Click Variable from the drop down
  22. Click Click to set to get Variable drop down
  23. Click the global variable created earlier from the drop down. In my case that is Ignore Master Closet Sensor
  24. Click Click to set to get the Boolean drop down
  25. Click False from the drop down
  26. Click Done with this Condition
  27. Click Done with Conditional Action
  28. Click Select Action Type to Add to get drop down
  29. Click Control Switches, Push Buttons
  30. Click Select Which Action to get drop down
  31. Click Turn Switches on
  32. Click Turn switches on to get list of switches
  33. Select the correct Switch
  34. Click Update
  35. Click Done with this action
  36. Click Select Action Type to Add to get drop down
  37. Click Conditional Actions from the drop down
  38. Click Select Which Action to get drop down
  39. Click END-IF (conditions) THEN from the drop down
  40. Click Done with this action
  41. Click Done with Actions
  42. 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:
Many Tedious Steps
  1. Select Apps
  2. Select Rule Machine
  3. Select Create New Rule
  4. Name Rule
  5. Select Select Trigger Events
  6. Select Switch from the drop down
  7. Click the Switches Click to Set
  8. Select the correct switch
  9. Click the Update button or Switches Click to Set
  10. Click the Switch turns drop down
  11. Click off
  12. Click Done with this Trigger Event
  13. Click Done with Trigger Events
  14. Click Select Actions to Run
  15. Click Select Action Type to Add to get drop down
  16. Click Set Mode or Variables, Run Custom Action from the drop down
  17. Click Select Which Action to get drop down
  18. Click Set Variable from the drop down
  19. Click Click to set to get the Select Variable to Set drop down
  20. Click the global variable created earlier from the drop down. In my case that is Ignore Master Closet Sensor
  21. Click Click to set to get the options for the variable drop down
  22. Click True
  23. Click Done with this action
  24. Click Select Action Type to add to get drop down
  25. Click Delay or Repeat Actions, Wait from the drop down
  26. Click Select Which Action to get drop down
  27. Click Delay Actions from the drop down
  28. 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%
  29. Click Done with this action
  30. Click Select Action Type to add to get drop down
  31. Click Set Mode or Variables, Run Custom Action from the drop down
  32. Click Select Which Action to get drop down
  33. Click Set Variable from the drop down
  34. Click Click to set to get the Select Variable to Set drop down
  35. Click the global variable created earlier from the drop down. In my case that is Ignore Master Closet Sensor
  36. Click Click to set to get the options for the variable drop down
  37. Click False
  38. Click Done with this action
  39. Click Done with Actions
  40. Click Done
  1. Test the automation

  2. 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

Here is my next learning related to this conundrum. In some cases, when the motion sensor has stopped sensing motion while the light is on and then gets activated right before the light is turned off, it is possible for the light to be switched off, before the variable is changed, resulting in the light turning right back on.

To account for this corner case, I updated the rule as shown here:
Closet%20Motion%20Turns%20on%20Closet%20Light%20v2

I hope that by checking if the light is already on, then I will close off this corner case.

This should not be happening unless you are not moving when you exit the closet. Presumably the the motion sensor is active as you are walking out of the closet. When you turn the light off, the motion sensor will still be active. When you close the door, the sensor will still be active. That should not turn the light back on because the sensor has not gone from Inactive to Active, which is what will cause the light to turn on. The sensor remaining in active should not be triggering the light to come on. That is, unless you're able to get out of the closet without moving.

Having this handled in 2 rules is going to make things much more complicated. I would first try to simply trigger based on motion changing to turn the light on and off based on motion. That would allow you to be able to not have to turn the light off manually if the door is opened by the dog.

I think the problem with your suggestion is that the shape and size of the closet it such that it is possible to remain in the closet and yet no longer trigger the motion sensor. So I want the sensor to only trigger the on, while leaving off to the switch.

So, the sensor can see you walk into the room but not see you the whole time you are in there? Then I would just use the contact sensor and train my dog to not open the door. We used to use a cabinet door to keep my dog out of the kitchen. Not tied to anything, just pushed open. He could have easily moved it. But he didn't cause we're the people and he's the dog.

Correct description of the situation. Hindsight does say that a contact sensor would be superior in this case to a motion sensor, but when all you have is a hammer (or motion sensor), then everything looks like a nail (or a chance to drive off of motion).