michielpost / Q42.HueApi

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

How to update Room #289

Closed gkapellmann closed 1 year ago

gkapellmann commented 1 year ago

I am missing something here, but I seem to not be able to change the state of a room, simple turn of or on. What I am trying is:

         public async Task SetRoomState(Guid Id, bool onOff) {
            var req = new BaseResourceRequest();
            if (onOff) { req.TurnOn(); } else { req.TurnOff(); }
            var result = await localHueClient.UpdateRoomAsync(Id, req);
            if (result.HasErrors) {
                foreach (var error in result.Errors)
                    Log.Text(error.Description);
            }
        }

But "TurnOn()" and "TurnOff" dont exist, and I was unable to fins a proper request for the rooms.

"UpdateGroupedLightAsync" doest work for rooms, and I am guessing is not meant to be used here.

What am I missing?

michielpost commented 1 year ago

The Room API is only to manage rooms (create rooms, update which light is in a room etc). The Room API can't be used to set light state. You need to use the Grouped Light API for that.

So first you need to find the Grouped Light ID that corresponds to your Room, and then you can update it:

UpdateGroupedLight req = new UpdateGroupedLight();
req.On = new Models.On() { IsOn = true };
var result = await localHueClient.UpdateGroupedLightAsync(id, req);

More info can be found in the API reference: https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_grouped_light

gkapellmann commented 1 year ago

Aja! ok, now this works.

Yeap, that link was very useful.

Thanks!