Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Philips Hue Android SDK Checking for Sunset

I am working on an app that uses the Philips Hue SDK. I want to perform an action if after sunset. It looks like there is a sensor on the bridge that can return true or false if the user is currently under daylight.

I'm finding the documentation is a little lacking in this area, or at least I'm not finding it. I've found http://www.developers.meethue.com/documentation/supported-sensors but it gives no information about how to use it. The only other thing I've found is http://www.developers.meethue.com/documentation/java-sdk-getting-started#usingSensors which just says how to find new sensors. I don't want all sensors, I just want to access the daylight sensor and just do a check is it daylight and if not do something.

like image 871
Boardy Avatar asked Apr 19 '16 18:04

Boardy


1 Answers

You can accomplish this by setting the JSON values appropriately on the bridge. Here is how to do it using the debug/clip.html tool on the bridge. You could use one of the Hue API's to perform these operations also, but using the debug tool is very easy.

First, PUT (update) the Daylight sensor config with your own long and lat. These values are for Omaha, NE. The offsets can be set plus or minus 120 minutes to make the state change earlier or later than the computed sunrise/sunset time for the specified lat/long coordinate.

/api/<username>/sensors/1/config

{
  "long": "96.0419W",
  "lat": "41.2647N",
  "sunriseoffset": 0,
  "sunsetoffset":  0
}

If you get it right, the state/daylight value should change accordingly.

Now, POST (create) a rule that will fire based on the daylight state:

/api/<username>/rules

{
  "name": "Turn lights off at sunrise",
  "conditions": [
    {
      "address": "/sensors/1/state/daylight",
      "operator": "eq",
      "value": "true"
    }
  ],
  "actions": [
    {
      "address": "/groups/0/action",
      "method": "PUT",
      "body": {
        "on": false
      }
    }
  ]
}

This rule will turn all lights (group 0) off WHEN the sensor's state/daylight value flips to true at sunrise. You could add a second rule to turn lights on at sunset.

like image 159
Ron Reuter Avatar answered Oct 17 '22 02:10

Ron Reuter