4

I see that the Hue API provides, on the "Daylight" sensor, fields for geographic location, and a sunrise/sunset offset.

To be specific:

lat
long
sunriseoffset
sunsetoffset

The API as currently published does not provide any information that I could find on how the sunrise/sunset can be used.

If I use the update sensor API to set the latitude and longitude, will the sunrise/sunset offsets be populated with data automatically, and I can query those to adjust my light schedule accordingly? I want to do e.g. "every day, light on at sunset + 20 minutes".

I was going to implement the necessary algorithm myself, but in light of these fields do I need to?

When testing this, I updated the latitude and longitude on the sensor config, here is a dump of the result of querying the sensor after the update:

{
  "state": {
      "daylight":false,
      "lastupdated":"2014-11-06T19:19:31"
  },
  "config": {
      "on":true,
      "long":"1.5333W",
      "lat":"56.2442N",
      "sunriseoffset":30,
      "sunsetoffset":-30
  },
  "name":"Daylight",
  "type":"Daylight",
  "modelid":"PHDL00",
  "manufacturername":"Philips",
  "swvversion":"1.0"
}

You can see the latitude and longitude values that I set (by default they are 'none').

It's now evident that the sunrise and sunset offsets are not calculated values. They are instead used to configure when the sensor value trips over from daylight to not-daylight or vice versa - for example, daylight becomes true "sunrise offset" minutes after sunrise.

Does the bridge know about sunrise and sunset times for the given geographic location?

If so, can I reliably query this sensor to determine daylight or not-daylight taking into account sunrise and sunset?

caprica
  • 3,902
  • 4
  • 19
  • 39
  • Probably not what you need, but you can use IFTTT with HUE and trigger on sunset / sunrise without any lines of code, but I guess you want something more specific (20 minutes after sunset)... – Philipp M Nov 06 '14 at 17:47
  • 1
    The bridge does indeed know about sunrise and sunset times. That's what the geo-location is for. The offset is in minutes. I haven't found any documentation, but the `lastupdated` time is exactly `sunsetoffset` minutes before the sun went down for me. You'll also have to make sure the geo-coordinates more or less match. Yours point to somewhere in the north sea. – Günther the Beautiful Nov 09 '14 at 19:12
  • 1
    I have successfully tested using the daylight sensor for switching my lights on when the sun sets. Please give me a few hours and I will post an example (as an answer). – Günther the Beautiful Nov 11 '14 at 09:17

1 Answers1

10

There is a description of the Daylight sensor at Supported sensors page, a description of sensors at the Sensors page, and you need Rules to make good use of the sensors.

The Daylight sensor will set the state value daylight to true when there is daylight and false when there is not, of course taking into account the offset (in minutes) you specified in the sensor config.

To change your daylight sensor config, use PUT on /api/<username>/sensors/1/config with the following body:

{
    "long": "1.5333W",
    "lat": "56.2442N",
    "sunriseoffset": 30,
    "sunsetoffset": -30
}

Which means the state daylight value will change to false 30 mintues before sunset, and true 30 minutes after sunrise, where the sunset/sunrise times are calculated based on your long (longitude) and lat (latitude) values.

In order to e.g. turn on your lights at sunset, you need to specify a rule with the condition that the daylight value must be equal to false.

Use a POST on /api/<username>/rules with the following body:

{
    "name": "Daylight rule",
    "conditions": [
        { 
            "address": "/sensors/1/state/daylight",
            "operator": "eq",
            "value": "false"
        }
    ],
    "actions": [    
        {
            "address": "/groups/0/action",
            "method": "PUT",
            "body": { "on":true, "bri":254 }
        }
    ]
}

Where the condition for the rule is that the state daylight value must be eq(equal) to the value false.

  • 1
    I'm still a terrible beginner with the hue system, but I have also added another condition to it which is `{"address": "/sensors/1/state/lastupdated", "operator": "dx"}`. Otherwise, I'd fear that the rule constantly keeps the lights on when there's no daylight. By adding the "OnChange"-event for `lastupdated`, it is made sure it's only fired once. Just an idea. – Günther the Beautiful Nov 11 '14 at 21:36
  • I see what you mean, but I have tested the above rule for weeks and it only fires once. I am not sure what would happen if you added that condition, but it is not needed :) – Jesper Riemer Andersen Nov 11 '14 at 22:16
  • Exactly right, which can be verified by the "lasttriggered" timestamp and the "timestriggered" attributes of the rule. – Ron Reuter Apr 30 '16 at 02:31