Skip to main content

Deactivate Philips Hue Motion Sensor If Lights Already On

There are a lot of posts online asking Philips to add functionality to their motion sensors so that they don't turn lights off if a certain activity is happening or the lights were turned on by another means. There are third-party apps (most of which cost money) to add some functionality to allow this, but it can be done for free if you're prepared to send some JSON configuration to the built-in debugging page. 

"Wait, that sounds scary and difficult!" I hear you cry, but it is actually very simple... even if you aren't a techie. I'll take you through it step-by-step here, but all you need is a web browser and the ability to paste an edited version of the configuration into a web page and click on a button. 

Scenario

There are many different scenarios where this can be useful, but I'm going to give you one of my scenarios here to demonstrate the principle. I have some garden lights controlled by a motion sensor and a Hue Button, but I can also set scenes via my Amazon Alexa or my Home Assistant dashboard. (Home Assistant is an open source, very powerful home automation hub.) The problem is that if I turn the lights on with the button or set a scene via Alexa or HA then move in front of the sensor, it changes the scene and will turn the lights off 10 minutes later. However, sometimes I want the lights on in the garden when we're inside and I want different scenes if we're dining outside or I'm just going to the shed. 

How do I do this easily? Basically, we're going to add a condition to the motion detected rules to check if the lights are already on - if they are, don't change them. It may look scary, but it really isn't - you just need to follow the steps. 

N.B. You don't need any of these integrations for this to work and the principle will work with any setup if you have the Hue Bridge. 

Prerequisites

You must have your Hue Bridge, lights, motion sensor and any buttons or switches set up and working before you begin. Then you need to access the built-in API and create a user account, if you haven't done this already. To get started, open a web browser and navigate to your Philips Hue IP address, e.g. https://192.168.0.100/debug/clip.html. You will probably get a warning that the connection isn't secure, but you can safely navigate to the page, or choose the unencrypted http://... version as you're on a private network. If you don't know the IP address of your Hue Bridge, open the Philips Hue App on your phone, tap on the Settings cog in the bottom right, then tap on the Hue Bridges option at the top and tap on your bridge to get the Status, ID, Software version and IP address. Just substitute your IP address for the one shown above (that's the xxx.xxx.xxx.xxx number). You should see something like the form below:

Follow the instructions at the meethue website to get connected and register an API user on your Hue Bridge. This is a simple and quick process. You will then substitute your API username in the URL textbox as shown above. 

Finding & Editing the Relevant Rules

Now you're connected to your Philips Hue Bridge API Debugger with a username, we can find the relevant motion sensors and the associated rules for turning the lights on and off. To get and edit these, follow the steps below:

  1. Navigate to the Hue Bridge CLIP API Debugger as above.
  2. In the URL field of the form type /api/<username>/sensors and click on the GET button (substituting your username for the <username> text above obviously). 
  3. In the Command Response window you should see a list of all the sensors registered with your Hue Bridge (the list will be longer than you think as most sensors have additional associated helpers).
  4. Now search through the text to find your motion sensor, which will have a "productname" of "Hue motion sensor" for the indoor sensors or "Hue outdoor motion sensor" for the outdoor sensor. The format here is JSON and each entry has the following structure with a numeric ID, state information, software versions, etc. (I have cut most of it out here as it's not important for this post):

    "32": {
        "state": {
            "presence": false,
            "lastupdated": "2021-11-10T16:57:28"
        },
        ...
        "productname": "Hue outdoor motion sensor",
        "swversion": "6.1.1.27575",
    },

  5. You need to make a note of the numeric ID (32 in the above example) of your motion sensor as we will search for rules that use this presence sensor. 
  6. Now we will get a list of the rules in your Hue Bridge by entering /api/<username>/rules into the URL text box and clicking on the GET button again to get a list of rules in the Command Response window. 
  7. Again, there will likely be a lot of rules if you have a few motion sensors or buttons, so search for "/sensors/32/" (substituting the ID number of your motion sensor) to find all the relevant rules.
    The Hue Bridge has 11 rules relating to this motion sensor and we're going to edit 6 of them, adding some additional conditions to check if the lights are already on. Again, these rules are in JSON format with the following general structure with a set of comma separated conditions and actions:

    "96": {
        "name": "16:",
        "owner": "...",
        "created": "2021-11-07T16:35:28",
        "lasttriggered": "2021-11-09T19:53:00",
        "timestriggered": 2,
        "status": "enabled",
        "recycle": true,
        "conditions": [ ... ],
        "actions": [ ... ]
    }

  8. These rules have been created by the Philips Hue app and broadly have the following functions based on setting 2 different scenes and 2 different timers depending on whether it is day or night and the default action of turning the lights off after the timers expire:
    1. It's dark during the day and motion is detected, so set Scene 1
    2. There's motion during the day and it becomes dark, so set Scene 1
    3. It's dark at night and motion is detected, so set Scene 2
    4. There's motion during the night and it becomes dark, so set Scene 2
    5. If there's no motion for the configured time during the day, dim the lights
    6. If there's no motion for the configured time during the night, dim the lights
    7. If motion is detected when lights have been dimmed during the day, set Scene 1
    8. If motion is detected when lights have been dimmed during the night, set Scene 2
    9. If the lights have been dimmed during the day and there's no motion for 30 seconds turn the lights off
    10. If the lights have been dimmed during the night and there's no motion for 30 seconds turn the lights off
    11. If there's no motion and the lights are off, reset the status helper
  9. Copy and paste all 11 rules into a text editor such as Notepad on Windows (don't use a word processor as it may change some of the characters, just use a simple text editor).
  10. In the 11th rule there will be 2 conditions, the first checking that there is no motion (presence = false) and the second checking that the lights are off (either a single light or a light group, whichever you set). Copy the second (lights off) condition and paste it as the last condition into the "conditions": [] section of each of the first 4 rules, remembering to put a comma ',' after the previous condition. Your first rule should have conditions similar to the following (new condition shown in blue with the comma added on the previous line):

    "conditions": [
        { "address": "/sensors/32/state/presence", "operator": "eq", "value": "true" },
        { "address": "/sensors/32/state/presence", "operator": "dx" },
        { "address": "/sensors/33/state/dark", "operator": "eq", "value": "true" },
        { "address": "/config/localtime", "operator": "in", "value": "T07:00:00/T22:00:00" },

        { "address": "/sensors/64/state/status", "operator": "lt", "value": "1" },
        { "address": "/groups/4/state/any_on", "operator": "eq", "value": "false" }
    ]

    This will stop the first 4 rules from triggering if the lights are already on, which will stop the scene from changing when you move in front of the motion sensor. 
  11. We now need to stop the motion sensor from dimming the lights if no motion is detected for the set time by adding a condition to the 5th and 6th rules. Currently, if you move in front of the motion sensor when the lights are on, they will still turn off after your configured time. We need to make use of the helper sensor state to check if the lights were turned on by the motion sensor or not. If you check the actions for the first 4 rules, you will see that the helper status value is set to 1 if the motion sensor turned the lights on during the day and 3 if it turned them on at night. Otherwise the status is 0, so we can check whether this status has been updated by checking if it's greater than 0. 
  12. Copy the condition from the first rule that checks the value of the helper sensor ("/sensors/64/state/status" in the above example) and paste it into the conditions for the 5th and 6th rules, changing "lt" (less than) to "gt" (greater than) and the value from 1 to 0 (don't forget the comma). Your 5th rule should now have conditions similar to the following (again the new condition and comma are shown in blue):

    "conditions": [
        { "address": "/sensors/32/state/presence", "operator": "eq", "value": "false" },
        { "address": "/sensors/32/state/presence", "operator": "ddx", "value": "PT00:09:15" },
        { "address": "/config/localtime", "operator": "in", "value": "T07:00:00/T22:00:00" },
        { "address": "/groups/4/state/any_on", "operator": "eq", "value": "true" }
    ,
        { "address": "/sensors/64/state/status", "operator": "gt", "value": "0" }

    ]


    We don't need to worry about the other rules as they won't trigger unless the lights are turned on by the motion sensor.
  13. Now that you have the edited version of the conditions for the first 6 rules of your motion sensor, we need to upload them to your Hue Bridge. We have to do this one rule at a time. Add the ID of the first motion sensor rule to the URL field in the CLIP API Debugger so that it looks something like /api/<username>/rules/96 for my first rule above and click on the GET button. You should now see just that one rule in the Command Response window. 
  14. Check that this is the correct rule!
  15. Now, in the Message Body window, paste the edited "conditions": [] section from your text editor for this rule and put an open curly bracket '{' at the start and a closing one '}' at the end, so it should look something like this:

    {"conditions": [
        { "address": "/sensors/32/state/presence", "operator": "eq", "value": "false" },
        ...

    ]}


  16. Now click the PUT button to save the new conditions to this rule. You should get a success message in the Command Response window. 
  17. Check the rule has been updated by clicking the GET button and checking the Command Response window.
  18. If this is successful, do the same for the other 5 rules by changing the ID number in the URL field and replacing the Message Body with the relevant conditions. Clicking the GET button will get the rule from the Bridge and clicking the PUT button will update it with the data in the Message Body window. 

Conclusion

Your motion sensor will now only turn the lights on and off if they were off to begin with. Any time you turn the lights on via a switch/button/automation the motion sensor will effectively be disabled until you turn the lights off again. The advantage of not actually disabling the motion sensor is that it can still detect motion, light levels and temperature for other automations without affecting the lights. A second advantage is that this doesn't break the compatibility with the Philips Hue App (although, depending on the edits you make you may need to add these conditions back in, so I'd save a copy of the new ruleset somewhere), nor does it require yet another app on your phone. 

If you're prepared to fiddle with the rules in the way I have shown you here, the Philips Hue lights are amazingly sophisticated as a stand-alone system without the need to integrate them into any home automation solutions. 

Comments

Post a Comment

Popular posts from this blog

Netgear R9000 X10 VLANs on dd-wrt

As part of my Smart Home build, I need a proper network with segregated sub-networks for our computers, IoT & media devices, management and, of course, guests. The full network design and decision process will be the subject of another post, but I obviously need wi-fi - at least 3 different wi-fi networks in fact.  All the forum posts and information I can find say that the R9000 doesn't support VLANs in dd-wrt. I need VLAN support so that I don't have to have 3 or more different APs (one for each network SSID). Looking at the hardware spec (and the fact that the stock firmware supports limited VLANs), I figured that it should support VLANs, so I trawled the forums, looked at the code and learned about the toolsets included in dd-wrt and I made it work!  This post covers how I set up VLANs on my Netgear R9000 Nighthawk X10 in dd-wrt. I'm sure you will want a different setup (in fact this isn't my final setup either, but it shows the principle).  Pre-requisites I am

Interactive Floorplan in Home Assistant with Daylight Simulation

When I started looking at a Smart Home controller for my new house, something that struck me as being quite 'cool' (if you're a geek like me) was a 3D floorplan with interactive icons. When I settled on Home Assistant, there were several people showing implementations with simulated lights turning on and off and switching between day and night. So, I decided to create an interactive floorplan for my home, but I also wanted to simulate the amount of daylight in the image and add other elements, like motion sensors, and coloured lights, etc. Below is the Ground floor as a work in progress.  A few basic pre-requisites that you'll need (all of which have plenty of tutorials on how to set them up): Home Assistant up and running Home Assistant Community Store  (HACS) installed in Home Assistant Config Template Card frontend add-on through HACS to enable JavaScript and CSS support A means to upload image files to Home Assistant (I use the Samba Share Add-on) Some smart lightbu

Multiple Philips Hue Bridges and Alexa (or Google Assistant) using Home Assistant

Philips Hue bulbs are fantastic and hugely flexible when paired with the Hue Bridge. Out of the box the accessories support a range of features and will do most of what people want. However, if you are prepared to go a little bit deeper with them and use the built-in Hue Bridge API, you can get very sophisticated lighting automation and other information. For example, the Rules engine in the Hue Bridge allows for rules to be triggered by other rules and events and they also allow you to set any action for any button press on their accessories (e.g. successive presses of the same button on a tap switch can dim the scene or cycle through as many scenes as you want). Something that Philips doesn't shout about is that their motion sensors also have temperature and lux sensors that you can query - also very useful. So what's the problem? Well, the Philips Hue app and integrations with Amazon Alexa, Google Home Assistant, etc., assume that you have exactly 1 Hue Bridge. I guess that