michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
411 stars 114 forks source link

How to create a schedule that turns all lights off? #218

Closed JBPuzzled closed 3 years ago

JBPuzzled commented 4 years ago

Hi there,

Thanks for your efforts on this project. It's great!

I'm able to modify individual lights and enable existing schedules, but I could not manage to create a temporary schedule (timer) with a command that turns all lights off. I do have schedules in place that I created with the Hue app, so it should be possible. Obviously I'd like to create schedules on the fly determining the number of minutes ad-hoc.

Am I close? Is it possible with Q42.HueApi?

var minutes = 4
ILocalHueClient client = new LocalHueClient("xxx", "xxx");

var schedule = new Schedule()
{
  AutoDelete = true,
  Name = $"temp{minutes}",
  Description = $"Turns off in {minutes} (temp)",
  LocalTime = new HueDateTime() { TimerTime = new TimeSpan(0, minutes, 0) },
  Command = new InternalBridgeCommand(),
  Status = ScheduleStatus.Enabled,
};

schedule.Command.Body = new LightCommand().TurnOff();
schedule.Command.Address = "?";
schedule.Command.Method = HttpMethod.Put;

var result = await client.CreateScheduleAsync(schedule);
michielpost commented 4 years ago

From the Hue docs: https://developers.meethue.com/develop/hue-api/3-schedules-api/#create-schedule

{
    "name": "Wake up",
    "description": "My wake up alarm",
    "command": {
        "address": "/api/<username>/groups/1/action",
        "method": "PUT",
        "body": {
            "on": true
        }
    },
    "localtime": "2015-06-30T14:24:40"
}

Insert your username: schedule.Command.Address = "/api/<username>/groups/1/action";

That should probably work.