TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Raspberry Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me

What is it?


The folks at ENERGENIE have created sockets or plugs which can be turned on and off via the Raspberry Pi.  You can buy a starter kit here which includes the RF transmitter add-on board and two sockets to get your started.  
Picture
Once installed and set up your Raspberry Pi can be used with the R-PI to control up to 4 simple Energenie radio controlled sockets independently using a small software program.   The add-on board connects directly to the he GPIO which can be controlled as either input or output lines under your software control.  A Python library is also available to program the sockets. 

Turn a light on / Turn a light off




1. Getting Started


To get started boot the Raspberry Pi up and load the LX Terminal and update:
  
sudo apt-get update
sudo apt-get install python-rpi.gpio


Then reboot the Pi and this will install the Python GPIO libraries meaning you can access and control the pins via Python code.  Next install the Python Libraries, in the LX Terminal, depending on which version of Python you are using type:
Python 3:
sudo apt-get install python3-pip
sudo pip-3.2 install energenie
Python 2:
sudo apt-get install python-pip
sudo pip install energenie
In the future you may need to update  the software use this code:
sudo pip install energenie –update

2. Fitting the Transmitter


Turn the Raspberry Pi off, sudo halt, and fit the Raspberry Pi transmitter board.  It fits nicely onto the GPIO pins.  Power up the Pi and get your ENERGENIE plug sockets ready.  Plug the first socket into the wall.  Before it can be used it must be programmed to learn a control code from the transmitter.  
Picture
To do this the socket must be in learning mode indicated by the lamp on the front of the socket housing flashing slowly. If it is not doing this, press and hold the green button on the from of the housing (while the lamp is off), for 5 seconds or more and then release it when the lamp starts to flash at 1 second intervals.
Setup Program
File Size: 5 kb
File Type: py
Download File

PDF instructions
File Size: 633 kb
File Type: pdf
Download File

Download the above program which will search for and setup the communication between the socket and the Pi.  Run the program and it will send a signal out, follow the onscreen prompts by hitting the return key. 
Picture
If the acceptance is successful it will be indicated by a brief quick flashing of the lamp on the housing which will then stop. Program first one socket then the other in this way, otherwise they will react to the same signal.  

3. The Python Code


The Python Code is very simple to use and you will soon be using your Raspberry Pi to turn the kettle on or off or flash a light on or off. Firstly ensure that you have set up the power socket using the 'set up program' then start a new code window.  
Use the code to turn the socket on: energenie.switch_on(1)
To turn off the socket off use the cod : energenie.switch_off(1)

The simple program below asks the user if they want to turn the light on, if you respond with 'no' then the light stays off.  If you type yes then the light turns on for 10 seconds before switching off.  (The full code is below the video)
#import the required modules
import RPi.GPIO as GPIO
import time


import energenie
from energenie import switch_on
from energenie import switch_off
energenie.switch_off(1)
print "WELCOME TO THE HACKING LAMPS"
print " "
time.sleep(2)
try:
    while True:
        choice = raw_input("Would you like to turn the lights on? ").lower()
        print " "
        if choice == "yes":
            energenie.switch_on(1)
            print "The light is ON!"
            print " "
            time.sleep(10)
            print "Turning Off"
            time.sleep(1)
            print ""
            energenie.switch_off(1)            
        else:
            print "The light is OFF"

# Clean up the GPIOs for next time
except KeyboardInterrupt:
GPIO.cleanup()

  • More programs can be found here
Copyright 2020 TeCoEd @dan_aldred