0

So I am developing an app integrating Philips Hue smart lights. I am using Hue SDK in swift 4. I want to show available groups in a Table View just like the bridge, and then allow the selection of a group to apply light state changes to. I cant find any documentation anywhere on groups, so any sample code or resources would be soooo appreciated!

1 Answers1

1

The Philips Hue Swift documentation shines again by its absence

This is how you get all the groups from the selected bridge:

    let groups = bridgeController?.bridge.bridgeState.getBridgeResources(of: .group)

And this is how you send a lightstate to a group, i.e. group '0', which is all lights:

    let lightState: PHSLightState = PHSLightState()
    lightState.on = true
    lightState.brightness = 254

    let group: PHSGroup = bridgeController?.bridge.bridgeState.getBridgeResource(of: PHSDomainType.group, withIdentifier: "0") as! PHSGroup

    group.apply(lightState, allowedConnectionTypes: .local, completionHandler: { (responses, errors, returnCode) in
        // do something
    })
Matthijs
  • 515
  • 4
  • 8
  • Oh my lord! Thank you so very much! Made my weekend! – Matt Foreman Mar 30 '18 at 19:56
  • Back again! Just wondering what the best route is to change the colors of lights within a group. Your code allows me to change the color of the whole group, but I have a script to randomly change the colors every 5 seconds. What would you recommend to change the colors of each light within the group to a random color every 5 seconds? Thanks so much! – Matt Foreman Mar 02 '19 at 18:48
  • At the moment I am not working with the HUE SDK, but probably I would take all the lights from a group, throw them in an array and do the things.. – Matthijs Apr 12 '19 at 11:18
  • Is it possible you could send some pseudocode for that? – Matt Foreman Jul 25 '19 at 17:59