Philips Hue Triggered by PIR Sensor - Code Help Please

299 views
Skip to first unread message

Joseph Farrier

unread,
Oct 29, 2015, 1:24:31 AM10/29/15
to Wireless Sensor Tags
What am I doing wrong?  I can get the lights to toggle with reed sensors so I know my Hue stuff is correct.  Please help!

var hue_bridge=<%Hue bridge IP address_H%>;
var hue_user = <%Hue username%>;
var hue_lampids = <%Hue lamp IDs (separate by ,)%>;
var sensors = <#PIR sensor_[72]_N#>;
function (sensor) {
        sensor.timedOut = function () {
                hue_lampids.split(",").forEach(function(id){
                    KumoApp.httpCall("http://"+hue_bridge+"/api/" + hue_user+"/lights/"+id+"/state", "PUT", 
                    '{"on": false}');
                });
        };
        sensor.detected = function () {
            hue_lampids.split(",").forEach(function(id){
                KumoApp.httpCall("http://"+hue_bridge+"/api/" + hue_user+"/lights/"+id+"/state", "PUT", 
                '{"hue": 50000,"on": true,"bri": 200}');
            });
        };
});

Senyo Seckley

unread,
Nov 22, 2015, 2:55:13 PM11/22/15
to Wireless Sensor Tags
Hi did you manage to get this to work? I've got some pir sensors coming in the post, and I wanted you use them to control my hue lights

Joseph Farrier

unread,
Nov 22, 2015, 4:00:07 PM11/22/15
to Wireless Sensor Tags
Use this code.  It will turn on a single/multiple hue light(s) upon motion sense but then turns them off once the PIR sensors goes to timeout.  The timeout setting for each PIR sensor is in the sensor settings.  You can change the code to turn off after a give time period or just delete that part to  leave the light on.  If you have multiple PIR sensors trigger the same light keep in mind that an motion sense will turn them on and any timeout will turn them off and that can be confusing logic to manage.  If you have just a single PIR sensor for a single set of lights then it is much easier to manage.  If you want to use multiple PIR sensor to trigger lights then I would recommend using a time delay to turn off the lights.  For any of this to work you must have the developers account to your Hue Bridge (to obtain your user name and set a password).


var hue_bridge=<%Hue bridge IP address_H%>;
var hue_user = <%Hue username%>;
var hue_lampids = <%Hue lamp IDs (separate by ,)%>;
<#PIR sensor_[72]_N#>.forEach(
function (sensor) {
    sensor.detected = function () {
        hue_lampids.split(",").forEach(function(id){
            KumoApp.httpCall("http://"+hue_bridge+"/api/" + hue_user+"/lights/"+id+"/state", "PUT", 
            '{"hue": 50000,"on": true,"bri": 200}');
        });
    };
    sensor.timedOut = function () {
        hue_lampids.split(",").forEach(function(id){
            KumoApp.httpCall("http://"+hue_bridge+"/api/" + hue_user+"/lights/"+id+"/state", "PUT", 
            '{"on": false}');
        });
    };
});

Joseph Farrier

unread,
Nov 22, 2015, 4:01:17 PM11/22/15
to Wireless Sensor Tags
Here is code for a ten minute delay:

var hue_bridge=<%Hue bridge IP address_H%>;
var hue_user = <%Hue username%>;
var hue_lampids = <%Hue lamp IDs (separate by ,)%>;
<#PIR sensor_[72]_N#>.forEach(
function (sensor) {
    sensor.detected = function () {
        hue_lampids.split(",").forEach(function(id){
            KumoApp.httpCall("http://"+hue_bridge+"/api/" + hue_user+"/lights/"+id+"/state", "PUT", 
            '{"hue": 50000,"on": true,"bri": 200}');
        });
        KumoApp.setTimeout('', 600000);
        hue_lampids.split(",").forEach(function(id){
            KumoApp.httpCall("http://"+hue_bridge+"/api/" + hue_user+"/lights/"+id+"/state", "PUT", 
            '{"on": false}');
        });
    };
});

On Sunday, November 22, 2015 at 11:55:13 AM UTC-8, Senyo Seckley wrote:

Senyo Seckley

unread,
Nov 24, 2015, 1:12:30 PM11/24/15
to Wireless Sensor Tags
Thanks you're a diamond, I'll try them out when I get my pir sensors through the post. Forgive me for sounding dumb, but am I right in thinking that timeout is a period without any motion detection...?

Aidan Bree

unread,
Nov 26, 2015, 11:46:45 AM11/26/15
to Wireless Sensor Tags
Hi.

I stumbled on this post whilst looking to do something similar with Hue.

Currently I have sensors (not reed) on my doors and I would like to do this:

- I currently have IFTTT configured to switch all lights on at sunset
- On door open
- If after sunset (and therefore before sunrise), and if the lights are currently off
         - Switch on the light and set a timer for two minutes after which switch off

Has anyone done anything like this?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages