Git Product home page Git Product logo

keybowrpidrivesmylights's Introduction

keybow RPi Drives My Lights

Keybow RPi drives Shelly plugs / bulbs

Description

Basically this project enables to switch on and off a device (plug or bulb) based on URL call from a mini keybow plugged on a Raspberry Pi!

With the covid, and by force of circumstance, I started to work at home by obligation then by pleasure until I dedicated a room at home with my own setup. With a house on 2 floors, and moments when I am in a meeting, recording videos or simply available, I wanted to manage the availability of access to the room ... in short a kind of "On Air" to indicate my status. Ok, I can hear you from where you are... why didn't I just buy one? Well, it was too simple, and I like to make things!

Setup

So, it is quite naturally that I turned to Raspberry with its smaller form factor, Raspberry Pi Zero W on which I could adapt a mini keyboard. To manage the lights, after some chat with friends on Twitter, it appears that Shelly solutions seamed to be the most appropriate for want I wanted to do, switching on and off thanks to HTTP requests

Here are the component I used:

How to use it

Step 0 - Hardware setup

For this project, I reused a spare Raspberry Pi Zero W I already had. As I'm not mastering soldering, I used a solderless GPIO header thanks to GPIO Hammer Header (Solderless) to give GPIO connectivity for the keyboard. Honestly if you can buy one natively soldered, I recommend to do so, here is the reference: Raspberry Pi Zero WH.

I used the Keybow Kit (3-key) that brings 3 RGB mechanical keys to trigger actions. Pimoroni team released some interesting material to assemble the keybow mini.

RaspberryPi Zeo HW with mini-keybow - front view

To manage the lights, I bough Shelly Plug S and a Shelly Duo - RGBW by Shelly in order to manage two lamps and a bulb.

Shelly Plug S

Shelly Bulb

Step 1 - Micro SD Card Setup

So first step is to download the OS image, I used to download Raspberry Pi OS Lite from the official Raspberry web site.

Then you have to flash the OS to the micro SD card. Even if there are several option, I mainly used Etcher created by Balena, that makes things very simple: You just have to select the image, select your MicroSD card, and flash!

Because Etcher unmount the micro SD card after end of flashing process, you have to reinsert it, because there are 2 files to trick! You will observe that all the OS has been stored into the /boot folder. First, in /boot, create a file called ssh without extension to enable SSH on the Raspberry Pi. Because you are moving forward screenless, you have to activate Wifi on the Raspberr Pi. To do so, you have to create on /boot a configuration file called wpa_supplicant.conf that will allow you to pre-configure the WiFi credentials. At first boot time, the Raspberry Pi will copy and use this as the default configuration file.

In this file, place the following content and adapt it to your own Wifi configuration:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="WIFI_SSID"
scan_ssid=1
psk="WIFI_PASSWORD"
key_mgmt=WPA-PSK
}

Note: More information can be found in the official Raspberry Pi documentation on the section "Configuring Networking" of "Setting up a Headless Raspberry Pi"!

Now, you just have to save the updated content of wpa_supplicant.conf, then unmount you micro SD card.

First step is done!

Step 2 - SSH to the Pi Zero W

Now that's the tada moment, just insert the micro SD Card in the slot, and power up thanks to USB cable! Wait 2 to 5 minutes for the first boot.

Use your prefered IP scanner tool, or just connect to your box router to find the IP address of the Rapsberry Pi, then ssh pi@IP_ADDRESS, the default password is raspberry, and you will have the prompt waiting for you!

Of course, I have to recommende to update your device's OS and change the default password.

It's quite simple, you just have to type those two commands at the prompt:

sudo apt-get update && sudo apt-get upgrade -y and passwd

Step 3 - Install the lib for the mini keybow

To start using the mini keybow, you have to Enable SPI via the following command: sudo raspi-config nonint do_spi 0

Then, all you have to do is to install the library that manage mini keybow hardware: pip3 install keybow

Step 4 - Understand the Python app

The python code of app.pyis quite simple and is doing the following:

  • Initiate a logger to manage maintenance and potential issues properly
  • Load config of the actions to trigger on and off for each devices from a json config file
  • Call setup function that put all RGB buttons in green
  • Manage action to trigger thanks to dedicated handlers, one for each button, swapping from green to red, then to red to green

Step 5 - Install the Python app as systemctl service

Once you have cloned the project, just cd keybowRPiDrivesMyLights, then ./install.sh that will install the python app as a service that will be launched each time the RaspberryPi will start.

This script shell will copy the keybowRPiDrivesMyLights.serviceto /etc/systemd/system, then enable the service via sudo systemctl enable keybowRPiDrivesMyLights and start the service via sudo systemctl start keybowRPiDrivesMyLights

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

keybowrpidrivesmylights's People

Contributors

pensarguet avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.