cc_pi.png

…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.

Ingredients:

  • Raspberry Pi 2/3 with:
  • 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

Install ConfigCat SDK with pip:

install gpiozero libs

By default the Raspbian desktop image contains the GPIO Zero package. On a different OS, you’ll have to use PIP:

Step 1. – Set up your ConfigCat project

Sign up / Log in to ConfigCat

Create a project and a setting

cc_s1

Give your setting a name.

cc_s2

Copy your API key and setting key.

cc_s3

Step 2. – Code

Create a file (e.g. remoteswitch.py) with your favourite editor (I prefer nano) and implement the following code:

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:

 

cc_run.png

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.

cc_wire.png

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

 

Tags: