Setting up Philips Hue with Android

Philips Hue:

Philips Hue is an intelligent light collection; it will help you control your home’s lights using a smartphone, tabs, etc. Philips Hue can welcome you home, wake you up, get you energized, help you feel safe, improve your mood and much more.

Philips Hue uses two communication protocols to control the bulbs: Wifi/Ethernet and ZigBee.

Installation Steps:

  • Connect your bridge with a wifi router and electricity plug.
  • Plugging smart bulb to bulb holder in wifi network.
  • Install the Philips application on your smartphone to connect with the hue bridge.
  • After app installation, connect with hue bridge using a smartphone and after on connect with bulbs.
  • The app is compatible with Android or iOS operating systems.

How it works:

In the below picture, you will get an exact idea of how it works.
Android Philips Hue

  • Smartphone with Android or iOS or a desktop application device, using that user controls the smart bulbs.
  • A router that gets data from devices and forwards it to the hue bridge.
  • A bridge, get data and set commands for smart bulbs.
  • Smart bulbs get commands from the hue bridge and work as per the given command.

A few days ago, I got a chance to work on this technology. It’s very interesting!!! Hope you also enjoy it.

Here I will give you one example using the Android platform. In this example, we will see how we will connect with bridges and connect with bulbs ON/OFF bulbs using mobile.

Steps To Connect With Bridge :

Need to create a “PHHueSDK” instance.
We can directly get the quick start demo of hue Philips; click here.

// Gets an instance of the Hue SDK.
PHHueSDK phHueSDK = PHHueSDK.create();

// Set the Device Name (name of your app). This will be stored in your bridge whitelist entry.
phHueSDK.setAppName(getResources().getString(R.string.app_name));
phHueSDK.setDeviceName(Build.MODEL);

// Register the PHSDKListener to receive callbacks from the bridge.
phHueSDK.getNotificationManager().registerSDKListener(listener);

Search available bridges in a network

PHWizardAlertDialog.getInstance().showProgressDialog(R.string.search_progress, PHHomeActivity.this);
PHBridgeSearchManager sm = (PHBridgeSearchManager) phHueSDK.getSDKService(PHHueSDK.SEARCH_BRIDGE);
// Start the UPNP Searching of local bridges.
sm.search(true, true);

Using PH Listeners we can get the result of search bridge methods :

public interface PHSDKListener {

void onCacheUpdated(List<Integer> cacheNotificationsList, PHBridge bridge);

void onBridgeConnected(PHBridge bridge, String userName);

void onAuthenticationRequired(PHAccessPoint accessPoint);

void onAccessPointsFound(List<PHAccessPoint> accessPoints);

void onError(int code, String message);

void onConnectionResumed(PHBridge bridge);

void onConnectionLost(PHAccessPoint accessPoint);

void onParsingErrors(List<PHHueParsingError> parsingErrors);

}

// Local SDK Listener

private PHSDKListener listener = new PHSDKListener() {
   @Override

   public void onAccessPointsFound(List<PHAccessPoint> accessPoint) {

       Log.w(TAG, "Access Points Found. " + accessPoint.size());

       PHWizardAlertDialog.getInstance().closeProgressDialog();

       if (accessPoint != null && accessPoint.size() > 0) {

               phHueSDK.getAccessPointsFound().clear();

               phHueSDK.getAccessPointsFound().addAll(accessPoint);

               runOnUiThread(new Runnable() {

                   @Override

                   public void run() {

                       adapter.updateData(phHueSDK.getAccessPointsFound());

                  }

              });

       }

   }

   @Override

   public void onCacheUpdated(List<Integer> arg0, PHBridge bridge) {

       Log.w(TAG, "On CacheUpdated");

   }

   @Override

   public void onBridgeConnected(PHBridge b, String username) {

       phHueSDK.setSelectedBridge(b);

       phHueSDK.enableHeartbeat(b, PHHueSDK.HB_INTERVAL);

       phHueSDK.getLastHeartbeat().put(b.getResourceCache().getBridgeConfiguration() .getIpAddress(), System.currentTimeMillis());   prefs.setLastConnectedIPAddress(b.getResourceCache().getBridgeConfiguration().getIpAddress());

       prefs.setUsername(username);

       PHWizardAlertDialog.getInstance().closeProgressDialog();

       startMainActivity(); }

   @Override

   public void onAuthenticationRequired(PHAccessPoint accessPoint) {

       Log.w(TAG, "Authentication Required.");

       phHueSDK.startPushlinkAuthentication(accessPoint);

       startActivity(new Intent(PHHomeActivity.this, PHPushlinkActivity.class));

}
   @Override

   public void onConnectionResumed(PHBridge bridge) {

       if (PHHomeActivity.this.isFinishing())

           Return

       Log.v(TAG, "onConnectionResumed" + bridge.getResourceCache().getBridgeConfiguration().getIpAddress());    phHueSDK.getLastHeartbeat().put(bridge.getResourceCache().getBridgeConfiguration().getIpAddress(),  System.currentTimeMillis());

       for (int i = 0; i < phHueSDK.getDisconnectedAccessPoint().size(); i++) {

           if (phHueSDK.getDisconnectedAccessPoint().get(i).getIpAddress().equals(bridge.getResourceCache().getBridgeConfiguration().getIpAddress())) {

               phHueSDK.getDisconnectedAccessPoint().remove(i);

           }

       }

   }

   @Override

   public void onConnectionLost(PHAccessPoint accessPoint) {

       Log.v(TAG, "onConnectionLost : " + accessPoint.getIpAddress());

       if (!phHueSDK.getDisconnectedAccessPoint().contains(accessPoint)) {

phHueSDK.getDisconnectedAccessPoint().add(accessPoint);

       }

   }

   @Override

public void onError(int code, final String message) {

       Log.e(TAG, "on Error Called : " + code + ":" + message)

           }

       }

   }

   @Override

   public void onParsingErrors(List<PHHueParsingError> parsingErrorsList) {

       for (PHHueParsingError parsingError: parsingErrorsList) {

           Log.e(TAG, "ParsingError : " + parsingError.getMessage());

       }     

   }

};

After getting the list of available bridges, select bridge and connect with a bridge using “PHBrideg”.

PHAccessPoint accessPoint = (PHAccessPoint) adapter.getItem(position);
PHBridge connectedBridge = phHueSDK.getSelectedBridge();
if (connectedBridge != null) {
String connectedIP = connectedBridge.getResourceCache().getBridgeConfiguration().getIpAddress();
if (connectedIP != null) { // We are already connected here:-
phHueSDK.disableHeartbeat(connectedBridge);
phHueSDK.disconnect(connectedBridge);
}
}
PHWizardAlertDialog.getInstance().showProgressDialog(R.string.connecting, PHHomeActivity.this);
phHueSDK.connect(accessPoint);

Now select the bulbs and perform operations on selected bulbs.

Here we can switch ON/OFF lights, set brightness, set color of lights using “PHLightState”

List<PHLight> allLights = bridge.getResourceCache().getAllLights();
PHLightState lightState = new PHLightState();
lightState.setOn(isOn);
lightstate.setBrightness(40)
bridge.updateLightState(allLights.get(position), lightState, listener);

Make sure brightness must be in between 0 – 254. 

Here we just learn basic functionalities of Philips hue. We can do so many things using Philips hue SDK.

The smart lights concept is becoming very popular nowadays; I enjoyed it a lot while learning about Philips hue development; I hope you guys will also enjoy it.

Hope it will be helpful to you!!!😊

Priyanka

Android Developer

Priyanka is an android developer with around 3.5 years of experience developing Android applications with core functionality. She has in-depth knowledge of Java and React Native. Priyanka likes to learn new things and share.

Get in touch for a detailed discussion.

Hear From Our 100+ Customers
coma

Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.

author
ADDIE WOOTTEN
CEO, SMILINGMIND
coma

We had very close go live timeline and MindBowser team got us live a month before.

author
Shaz Khan
CEO, BuyNow WorldWide
coma

They were a very responsive team! Extremely easy to communicate and work with!

author
Kristen M.
Founder & CEO, TotTech
coma

We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.

author
Chacko Thomas
Co-Founder, TEAM8s
coma

Mindbowser is one of the reasons that our app is successful. These guys have been a great team.

author
Dave Dubier
Founder & CEO, MangoMirror
coma

Mindbowser was very helpful with explaining the development process and started quickly on the project.

author
Hieu Le
Executive Director of Product Development, Innovation Lab
coma

The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.

author
Alex Gobel
Co-Founder, Vesica
coma

Mindbowser is professional, efficient and thorough. 

author
MacKenzie R
Consultant at XPRIZE
coma

Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.

author
Laurie Mastrogiani
Founder, S.T.A.R.S of Wellness
coma

MindBowser was great; they listened to us a lot and helped us hone in on the actual idea of the app.” “They had put together fantastic wireframes for us.

author
Bennet Gillogly
Co-Founder, Flat Earth
coma

They're very tech-savvy, yet humble.

author
Uma Nidmarty
CEO, GS Advisorate, Inc.
coma

Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.

author
Katie Taylor
Founder, Child Life On Call
coma

As a founder of a budding start-up, it has been a great experience working with Mindbower Inc under Ayush's leadership for our online digital platform design and development activity.

author
Radhika Kotwal
Founder of Courtyardly
coma

The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!

author
Michael Wright
Chief Executive Officer, SDOH2Health LLC
coma

They are focused, patient and; they are innovative. Please give them a shot if you are looking for someone to partner with, you can go along with Mindbowser.

author
David Cain
CEO, thirty2give
coma

We are a small non-profit on a budget and they were able to deliver their work at our prescribed budgets. Their team always met their objectives and I'm very happy with the end result. Thank you, Mindbowser team!!

author
Bart Mendel
Founder, Mindworks