Philips Hue Android SDK Checking for Sunset
Asked Answered
S

1

7

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.

Sandstone answered 19/4, 2016 at 18:25 Comment(0)
T
3

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.

Travis answered 26/4, 2016 at 2:16 Comment(3)
Thanks this is useful but I was looking for doing this in the Philips Hue SDK for AndroidSandstone
Like I said, you can use the Java API to do exactly this, just send the create/update commands to set these values. I'm and iOS developer myself, and have done this in objective-c, but not in Java, but its not difficult. Anyway, thanks for the 25 points!Travis
RE: "I just want to access the daylight sensor and just do a check is it daylight and if not do something." So, first configure the daylight sensor as above, with the correct lattitude and longitude for your location. To determine if it is daylight, check the boolean value located at /sensors/1/state/daylight, with something like isDaylight = sensor[1].state.daylight; (I'm not running Java right now, but it should be something like this). If you need to do something WHEN it changes, then you will have to poll continuously, otherwise construct a rule as noted previously and let IT do the work.Travis

© 2022 - 2024 — McMap. All rights reserved.