…actually I know one, who is a huge fan of Raspberry Pi…it’s CHOCOLATE from the ConfigCat team 🙂
In this blog post I would like to walk you trough a few simple steps how to build a remote light switch using the ConfigCat platform.
- Raspberry Pi 2/3 with:
- internet access
- ConfigCat python SDK
- (‘GPIO Zero’ integration to any hardware)
- ConfigCat subscription (free plan is enough :))
Step 0. – Prepare the device to run your code
I use my board with Raspbian OS but you can use any distribution. I prefer it because it (usually :)) contains all necessary components for my pet projects. Read more about Raspberry Pi OS installation here.
Install ConfigCat SDK with pip:
sudo pip3 install configcat-client
install gpiozero libs
By default the Raspbian desktop image contains the GPIO Zero package. On a different OS, you’ll have to use PIP:
sudo pip3 install gpiozero
Step 1. – Set up your ConfigCat project
Sign up / Log in to ConfigCat
Create a project and a setting
Give your setting a name.
Copy your API key and setting key.
Step 2. – Code
Create a file (e.g. remoteswitch.py) with your favourite editor (I prefer nano) and implement the following code:
from gpiozero import OutputDevice
# set GPIO#3 port (you can select any GPIO output port)
relay = OutputDevice(3)
# initialize ConfigCat client to get your setting value
# get the latest value
# save into 'my_remoteswitch' variable
my_remoteswitch = client.get_value('demoswitch', False)
# for debug purpose only
# depend on the value the condition turns on/off the output
if my_remoteswitch == True:
In line 9 you should add your own APIKEY. This solution uses the ConfigCat SDK’s in manual polling mode. (Read more about polling modes here).
Step 3. – Test
Run your code with the following:
Depending on the value of setting the program prints the actual value of your switch on the ConfigCat Management Console and turns on/off the OutputDevice as well.
Step 4. – Demo
For the demonstration I created a simple circuit.
The components I have used:
- LED diode to show the switch status
- one resistor to limit the current (500Ω)
- two wires to connect to GPIO#3 port and a ground
- Raspberry Pi to serve power to the LED (you won’t need external power supply)
Step 5. – Further development possibilities
- Set up a program as a daemon (always run, after reboot)
- Apply this solution with any wireless power switch on your home