Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Relevant code snippet for Philips Hue SDK to be put into color loop mode
/* Just a snippet from a modified PHViewController.m in Philips Hue's iOS SDK.
Here I have a IBOutlet UISwitch *partyTimeSwitch
which is hooked up to a toggle Switch in my UI via Interface Builder */
Action for the party mode button
-(IBAction) switchValueChanged{
PHLightState *lightState = [[PHLightState alloc] init];
if(_partyTimeSwitch.on) {
[lightState setEffectMode:EFFECT_COLORLOOP];
else {
[lightState setEffectMode:EFFECT_NONE];
[self sendState:lightState];
-(IBAction) toggleButtonPressed{
[_partyTimeSwitch setOn:NO animated:YES];
[_partyTimeSwitch setOn:YES animated:YES];
Action sending state
- (void)sendState:(PHLightState*) lightState {
The BridgeSendAPI is used to send commands to the bridge.
Here we are updating the settings chosen by the user
for the selected light.
These settings are sent as a PHLightState to update
the light with the given light identifiers.
Subsequent checking of the Bridge Resources cache after the next heartbeat will
show that changed settings have occurred.
[lightState setOnBool:YES];
// Create a bridge send api, used for sending commands to bridge locally
id<PHBridgeSendAPI> bridgeSendAPI = [[[PHOverallFactory alloc] init] bridgeSendAPI];
// Send lightstate to light
PHBridgeResourcesCache *cache = [PHBridgeResourcesReader readBridgeResourcesCache];
for (id light in cache.lights) {
NSLog(@"light identifier is %@",light);
[bridgeSendAPI updateLightStateForId:light withLighState:lightState completionHandler:^(NSArray *errors) {
// Check for errors
if (errors != nil) {
for (PHError *error in errors) {
// Error occured
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error"
otherButtonTitles:@"Ok", nil];
[errorAlert show];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.