Before your can control our lights with the PyPortal, we'll need to set which lights we'd like to control within the code (code.py).
Open the Philips Hue application on your phone/tablet.
Navigate to Settings->Light Setup
The number next to the light is the light identifier. You'll be using this value in the code to refer to the light which you're setting.
- Tapping the i next to the light's name will bring up more information about it - like which room/group it's assigned to and the full name.
Next, you'll modify the following lines of code to correspond with the light identifier you're controlling.
- If you're new to creating and editing CircuitPython code: Read through this page and come back to this guide when you're ready.
For example, if you are setting up a lamp an identifier of 3 and a living room light with an identifier of 1, edit the following line in code.py from:
hue_lights={'lamp': 1, 'livingroom': 2}
to
hue_lights={'lamp': 3, 'livingroom': 1}
From the Mu Editor, click the Serial button to open the REPL. You should see the REPL display the code's status as it loads the interface.
Select a light by tapping the name of the light you'd like to control. The code will default to the first light specified within the hue_lights
list.
Tap the on/off button to toggle the power of the light you selected.
- Buttons invert their color while they make a request to the Hue Bridge. Once the request is complete, the button changes back to its original color.
- If you're having issues with your light not responding: Scroll down to the Diagnosing Errors section below.
Tapping a color button will set the light to the button's fill color.
- We used the Hue library's
rgb_to_hsv
method to set different colors for the buttons. For more information about this method and how the code works, navigate to the Code Walkthrough page for this guide.
Page last edited April 09, 2024
Text editor powered by tinymce.