Disclaimer: This article isn’t meant to teach you coding, but rather the basics of logic, and how it relates to using the All4Hue app for both Android, and iOS. All4Hue is an app that extends the abilities of the Philips Hue ecosystem by tapping into the Philips Hue Application Programming Interface (API). Note: I don’t have any affiliation with the developers of the app. I’m just a user of the app.

You’re probably wondering why you would need to know basic programming logic to use Philips hue. To put it simply, the official Philips Hue app, has very limited functionality in order to keep it simple for the average consumer.  Once you start to purchase more lights, and accessories, the need for more functionality becomes more apparent. 

A common complaint for example, is only having two time periods to choose from when setting up motion detectors.  It’s not that Philips Hue is lacking the functionality, it’s that it’s lacking in their own app.  Fortunately, Philips created an API (Application Programming Interface) for their Philips Hue ecosystem.  An API allows developers to tap deeper into the functionality of the ecosystem, and then add the functionality to their own apps.  

There are several apps out there that allow you to extend the functionality of Philips Hue bulbs and accessories, however, the one i’m using is called All4Hue.  To get the most from the All4Hue app, it helps to understand this basic logic.  

I’ll go through two concepts about programming, which is essentially all you need, to do some really funky stuff with your Philips Hue system.  The first concept is to do with conditions and actions (known as Rules in the All4Hue app).  The second concept is to do with variables (known as Memory Sensors in the All4Hue app).  Both of these are pretty simple concepts, and once you understand them, you’ll find the All4Hue app super simple to use.  

What are conditions and actions

In simple terms, conditions and actions are just rules.  A motion detector for example detects motion, and then turns on a bulb.  Why not just call them rules I hear you say?  Well, the app does call them rules, however, it helps to think of a rule as a list of conditions and actions because if you understand the concept, it makes it really easy to create your own set of rules.  A rule is just a list of conditions and actions.  It might be a simple condition like the one I just spoke about.  Detect motion, and then turn on the light.  In this case, the condition is motion detection, and the action is to turn on the light. By following this same logic, you can create complex rules.  For example, you could set up a rule that checks the time of day, and performs an action based on that time of day.

The Philips Hue app only allows two time periods, but you can set up rules that extend that to as many time periods as you like.  Future tutorials will go into more detail how to do this step by step.

Variables.  What are they, and why should you care?

VariableThink of a variable as just a placeholder for something. Let’s pretend a car is the placeholder, and the number of people in the car is the variable.  At the beginning of the journey, there may be 1 person in the car, and by the end of the journey, 3 people, because during the journey a condition changed.  The condition would be the driver stopping to pick up passengers. The concept can be about anything.  Example; Change the car to a bus, and the number of passengers to 10 at the beginning of the journey, and 23 at the end.  The placeholder name and value can be anything you like, but the concept is the same.

This is all well and good, but how does this have anything to do with the All4Hue app, I hear you ask?  Well, All4Hue allows you to use variables when setting up rules.  The All4Hue app doesn’t call them variables though.  They call them Memory Sensors, but are essentially the same thing.  In the app, you can create a Memory Sensor by giving it a name and an initial value.  Then, in the rules you create, you can either read the value, or change it to something else.  You can create multiple Memory Sensors, and change the values at any time within the rule you create.

Here’s an example.  You create a Memory Sensor called TimeTrigger, and give it an initial value of 0.  You then create a Rule with a condition to trigger at sunset, and an action to set the value of TimeTrigger to 5. Time Period with Philips HueYou then create another rule with a condition that triggers at 9pm, and an action that sets the value of TimeTrigger to 9. Lastly, you create another rule that has a condition that gets triggered at sunrise, and the action sets the TimeTrigger value back to 0.

Using the above example, you have three time periods being triggered.  When the variable is set to 5 which is at sunset, when it’s set to 9 at 9pm, and when the value is 0 which is initially, and also at sunrise.  You can keep adding new time periods by simply adding new rules, and changing the values at different trigger points like above.

Lastly, you create rules that check the value of the TimeTrigger memory sensor, and only trigger an action if the condition is met.  Example;  if motion is detected, AND the value is 9, then turn on the light using the nightlight scene. If the value is not 9, then don’t do anything. etc Do the same thing for the other values (which signify different time periods), and voila. 

The end result is you have a daytime period where the motion detectors don’t do anything.  A time period between sunset and 9pm, where a scene of your choice is activated, and another between 9pm and sunrise, where the scene is set to the nightlight scene.  Obviously, you would choose the time periods and actions for your own circumstances, but the concept is exactly the same.

Pretty cool huh!

The rules can also extend to other accessories such as the dimmer switches. 

Here’s an example of how i’m utilising Rules, and Memory Sensors.

I have a motion detector in my hallway which lights the hallway at night.  In the middle of that hallway, I have a linen closet.  During the day, the motion detectors don’t turn on the light, but after sunset until 9pm, they activate a scene where it lights up the hallway with a decent amount of light.  Between 9pm and sunrise, it changes to a nightlight, so when I’m wandering to the bathroom at night, i’m not blinded by the light. 

Hue Motion Detector and Dimmer SwitchThis was awesome until I needed to look for something in the linen closet at night.  If I turned on the Hall Light manually at full brightness, as soon as the motion detector detected motion, it changed the scene back to the dimmed scene.  To get around this, I used a dimmer switch in the hallway next to the linen closet.  When I press the On button, it changes the scene to full brightness and sets a Memory Sensor to a value of 99.  In the motion detector rules, I added a condition that says if that particular Memory Sensor is set to a value of 99, then don’t do anything, which had the same result of disabling the motion detector.  The end result is the light would stay on full brightness while I was walking around the hallway.  When I’m finished, I simply press the Off button on the dimmer switch, which then changes the value of the Memory Sensor back to the original value, which means the motion detector can then change the scene as it was meant to. It works really well now.

This is why the All4Hue app is so powerful.  You can create some really complex rules to accomplish just about anything with the Philips Hue bulbs, and accessories.  As long as you understand the above concepts, you’ll find yourself doing some really funky stuff with your Philips Hue system in no time. Oh, and the best part is the rules save to the Bridge so the app is no longer required after you create the rule.  I’d recommend keeping it though as it is an awesome tool to have to tweak and create awesome scenarios with your Hue system.

Let me know in the comments below if you use All4Hue, and whether this article was helpful..