michielpost / Q42.HueApi

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

Schedules not getting created #259

Closed Smcculloch closed 2 years ago

Smcculloch commented 2 years ago

Starting with a simple case to create an automation, yet nothing happens when I run the following:

var scheduleId = await _hueClient.CreateScheduleAsync(new Schedule
{
    Name = "Wake-up",
    Command = new InternalBridgeCommand
    {
        Address = "/api/<APP-KEY>/lights/13/state",
        Body = new LightCommand
        {
            On = true
        },
        Method = HttpMethod.Put
    },
    LocalTime = new HueDateTime
    {
        DateTime = DateTime.ParseExact("0700", "hhmm", null)
    }
});

Any tips about what I am missing?

michielpost commented 2 years ago

You can find some samples in the ScheduleTests class: https://github.com/Q42/Q42.HueApi/blob/master/src/Q42.HueApi.Tests/ScheduleTests.cs

They work, a new schedule ID is returned, but they are not visible in the app anymore and I'm not sure if they are actually triggered by the bridge. Found more people with problems using schedules, maybe it's not supported anymore?: https://developers.meethue.com/forum/t/4-0-app-schedules-not-working-anymore/6479 https://www.reddit.com/r/Hue/comments/o8csoq/hue_api_schedules_changed/

Smcculloch commented 2 years ago

Thanks! It turns out I needed to set the RecurringDay and TimerTime properties of the LocalTime (and not DateTime):

LocalTime = new HueDateTime
{
    RecurringDay = RecurringDay.RecurringWeekdays,
    TimerTime = DateTime.ParseExact("0700", "hhmm", null)
}

Yeah I found the forum post too about the schedules not appearing in the HueApp. Although I was able to get a schedule running (it just turns on a single light). The new HueApp clearly does scheduling differently as I've been testing my code on a HueBridgeV1 and HueBridgeV2. If I use Postman to query the schedules on both bridges, I can see the schedules, but indeed the schedule does not appear in the "new" HueApp. I have to use the old HueApp when connecting to the HueBridgeV1 and the schedules still appear there.

Hopefully this is something Philips will fix in future updates of the REST Api.

Thanks for the tip!