Facebook Twitter Instagram Pinterest YouTube
    Trending
    • Add Kodi to RetroPie Menu
    • Disable Auto-login in Raspberry Pi OS
    • Raspberry Pi Cloud Storage with MEGA
    • RetroPie Temperature Monitor from Menu
    • Pi Pico Pinout and Power Pins
    • Install Arduino IDE on Raspberry Pi
    • Raspberry Pi 400 SSD Upgrade
    • Raspberry Pi Temperature Monitoring
    Facebook Twitter Instagram Pinterest YouTube RSS
    Raspberry Pi SpyRaspberry Pi Spy
    • Home
    • Categories
      • General
      • Hardware
      • Programming
      • Python
      • Software
      • Tutorials & Help
    • BerryClip
      • BerryClip Instructions
      • BerryClip Plus Instructions
      • Videos & Reviews
    • Buy
      • Buy Pi
      • Buy Pi Accessories
      • Buy Books
    • Tools
      • Ultimate Raspberry Pi Alexa Skill
      • Pi Power Estimator App
      • Pi-Lite 14×9 LED Matrix Sprite Editor
      • RPiREF Pin-out Reference App
      • Simple Ohm’s Law Calculator
      • Web Sites & Links
    • Tutorials & Help
        Featured
        November 9, 20200

        Raspberry Pi Temperature Monitoring

        Recent
        May 6, 2022

        Add Kodi to RetroPie Menu

        February 26, 2022

        Disable Auto-login in Raspberry Pi OS

        February 2, 2022

        Raspberry Pi Cloud Storage with MEGA

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Hardware»Add-ons»Controlling Energenie Power Sockets with the Pi-mote Addon
      Energenie Sockets and Pi-mote Kit

      Controlling Energenie Power Sockets with the Pi-mote Addon

      3
      By Matt on August 9, 2017 Add-ons, Power

      Energenie create a range of remote control power socket products. These include plugin socket adapters that are great for controlling lamps, pumps and any other mains powered devices. To add some intelligence they sell a hub but of more interest to me is the Pi-mote.

      Energenie PiMoteThis is a £10 add-on board for the Raspberry Pi that allows you to use the GPIO pins to control the sockets. Once setup it is really easy to get your own code to switch the sockets on and off. It’s compatible with all  models of the Pi and I use a few around the house to control lamps and one in the garden as part of my paddling pool pump control system.

      You can buy the sockets separately but you’ll get the best value if you buy a set of sockets with a bundled Pi-mote. I managed to get a set of two sockets and one Pi-mote for £20 but this set is only £22 from the official Energenie shop.

      Buying Energenie Devices

      Energenie products are available from a number of sources so you may need to shop around to get the best price. You can get better value for money by buying a set of sockets and the Pi-mote at the same time.

      • Official Shop
      • CPC/Farnell
      • ModMyPi
      • Amazon
      • eBay.co.uk

      Pairing Sockets to Pi-mote

      Energenie Pi-mote on PiIn order to use the sockets each one must be paired to the Pi-mote and given an ID number in the range 1-4. The Official User Manual contains more technical information but below is the process I used to pair my sockets with a Pi-mote.

      • Create a fresh Raspbian SD card
      • Plug the Pi-mote onto the GPIO header
      • Power up the Pi
      • Download my pairing script using :
      wget https://bitbucket.org/MattHawkinsUK/rpispy-pool-monitor/raw/master/utils/energenie_pair.py
      • Plug in first socket into a mains socket
      • If the LED is on press the button to turn the socket off
      • Hold down the button for 5 seconds then release when LED starts flashing. The LED on the socket should be flashing once per second
      • Run the pair script with the appropriate socket number (1,2,3 or 4)
      python3 energenie_pair.py 1

      The ID you give the socket will be used to control this socket in your Python scripts. You can only have IDs 1,2,3 and 4 but you use the IDs on multiple sockets.

      If you feed the script “5” :

      python3 energenie_pair.py 5

      it will run a test and activate each of the fours IDs in sequence. This allows you to check that your sockets are activated with the ID you were expecting.

      Tip : If you are planning on using lots of sockets then you might want to label them for easier reference later on.

      Erase Socket Settings

      If you want to erase the paired information in a socket you can do the following :

      • Ensure socket is off and red LED is off
      • Hold button until LED starts flashing
      • Continue to hold button until LED starts flashing faster
      • Release button

      The socket will return to learning mode and you can either run the pairing script, turn the socket off or unplug it completely.

      Energenie Socket and Pi-mote

      Energenie Socket Codes

      For reference here are the codes that are used to control the four potential sockets. When using the Energenie or gpioZero methods detailed below you don’t really need to worry about this level of detail but it’s here for reference.

      There are three easy ways to control the sockets.

      Method 1 – RPi.GPIO

      Using RPi.GPIO requires a bit more Python than the other two methods as you have to configure the GPIO pins manually before sending codes to the Pi-mote. The GPIO pins can be configured at the start of your script using :

      import time
      import RPi.GPIO as GPIO
      
      # Set the GPIO numbering scheme
      GPIO.setmode(GPIO.BCM)
      
      # Select the GPIO pins used for
      # the encoder D0-D3 data inputs
      GPIO.setup(17,GPIO.OUT,initial=0)
      GPIO.setup(22,GPIO.OUT,initial=0)
      GPIO.setup(23,GPIO.OUT,initial=0)
      GPIO.setup(27,GPIO.OUT,initial=0)
      
      # Select the GPIO pin to enable/disable the modulator
      # Default to disabled
      GPIO.setup(25, GPIO.OUT,initial=0)
      
      # Select the signal used to select ASK/FSK
      # Default to ASK
      GPIO.setup(24, GPIO.OUT,initial=0)
      

      and a code can be sent to the Pi-mote using :

      # Socket 1 ON
      D3=True
      D2=True
      D1=True
      D0=True
      
      # Set D0-D3
      GPIO.output (27, D3)
      GPIO.output (23, D2)
      GPIO.output (22, D1)
      GPIO.output (17, D0)
      
      # Let it settle, encoder requires this
      time.sleep(0.1)
      
      # Enable the modulator
      GPIO.output (25, True)
      
      # Keep enabled for a period
      time.sleep(0.25)
      
      # Disable the modulator
      GPIO.output (25, False)
      

      In the example above Socket 1 is set to ON by setting all four Pi-mote inputs to True. If you wanted to turn ID 3 OFF you would set

      • D3=True
      • D2=False
      • D1=True
      • D0=False

      The reference table can be used to determine the values of D0-3 required to control the other socket IDs.

      Method 2 – Energenie Library

      In order to simplify things Ben Nuttal Amy Mather and Gordon Hollingworth created a Python library to deal with the detail shown in Method 1. It needs to be installed :

      sudo apt-get install python-pip python3-pip
      sudo pip install energenie
      sudo pip3 install energenie

      This installs the library for both Python 2 and Python 3.

      Turning sockets on and off becomes as easy as :

      import energenie as e
      import time
      
      # Turn all sockets on and off
      e.switch_on()
      time.sleep(2)
      e.switch_off()
      time.sleep(2)
      
      # Turn socket ID 1 on and off
      e.switch_on(1)
      time.sleep(2)
      e.switch_off(1)
      

      This library helps keep your own scripts nice and simple as you only need one line of code to change the state of a socket without needing to configure GPIO pins or worry about the Pi-mote control.

      Method 3 – GPIO Zero

      The next method you can use is the GPIO Zero package. This includes built in methods for controlling all sorts of Pi addons and accessories including the Energenie Pi-mote. It’s installed by default on the latest version of Raspbian but if you need to install manually you can find the install instructions here.

      import time
      from gpiozero import Energenie
      
      # Turn socket ID 1 on and off
      skt1 = Energenie(1)
      skt1.on()
      time.sleep(2)
      skt1.off()
      

      This is similar in complexity to using the Energenie library in Method 2 but may be a better choice if you can make use of GPIO Zero for other bits of hardware in your project such as LEDs or buzzers. Read more about it on the Official GPIO Zero Documentation page.

      Pi-mote Range

      The range of the Pi-mote can be increased by soldering a 135mm piece of copper wire to the point marked ANT1 on the PCB. I haven’t tested the range yet but I will update this paragraph if I do in the future.

      Final Thoughts

      I’ve used all three of these methods and it will be personal preference as to which one is the best choice for you. If you are in any doubt then give GPIO Zero a try as it can also be used to quickly control lots of other hardware as listed in the “API – Boards and Accessories” list.

      Once you can control your sockets with Python you can now add all sorts of functionality. Possible applications include :

      • Controlling Christmas lights
      • Controlling Halloween lights
      • Pool pump scheduling
      • Controlling house lights while you are away

      Light, motion and temperature sensors can be used to create “smart” projects that rival anything you can buy from a store.

      Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticleKKSB Metal Cases for the Raspberry Pi 2 and 3
      Next Article Send Pushover Notification when MotionEyeOS Boots

      Related Posts

      Gameboy Zero 6 Button Board from Aliexpress

      Raspberry Pi Power Consumption Data

      Kano Motion Sensor Kit for the Raspberry Pi

      3 Comments

      1. Erastus Toe on April 14, 2020 8:49 pm

        Will this work in America

        Reply
        • Matt on May 20, 2020 6:49 pm

          No reason it shouldn’t.

          Reply
      2. Jinn Ko on April 21, 2020 2:20 pm

        I can confirm that adding a 135mm wire to the ANT1 point has indeed extended the range! Thanks for pointing me in the right direction. For what it’s worth – this is also documented in the official transmitter documentation: https://energenie4u.co.uk/res/pdfs/ENER314%20UM.pdf

        Reply

      Leave A Reply Cancel Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      January 7, 2022

      RetroPie Temperature Monitor from Menu

      January 24, 2021

      Pi Pico Pinout and Power Pins

      Categories
      • 1-wire
      • 3D Printing
      • Add-ons
      • BBC Micro:bit
      • BerryClip
      • Books
      • Camera Module
      • Cases
      • Events
      • General
      • Hardware
      • I2C
      • Infographics
      • Interfaces
      • Minecraft
      • Model A+
      • Model B+
      • News
      • Pi Models
      • Pi Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      3D Printing Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter LCD LED Linux media Minecraft Model A Model B motionEyeOS PCB photography photos Pi-Lite portable power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI temperature ultrasonic video
      Raspberry PI Related
      • Adafruit Blog
      • Average Maker
      • Official RaspBerry Pi Site
      • Raspberry Pi Pod
      • RasPi.tv
      • RaspTut
      • Stuff About Code
      Tech Resources
      • MattsBits – Pi Resources
      • Microbit Spy
      • Technology Spy
      Archives
      About

      Unofficial site devoted to the Raspberry Pi credit card sized computer offering tutorials, guides, resources,scripts and downloads. We hope to help everyone get the most out of their Pi by providing clear, simple articles on configuring, programming and operating it.

      Popular Posts
      September 19, 2014

      Top 5 Reasons The Raspberry Pi Sucks

      July 27, 2012

      16×2 LCD Module Control Using Python

      October 20, 2013

      Analogue Sensors On The Raspberry Pi Using An MCP3008

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      Facebook Twitter Instagram Pinterest YouTube RSS

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2022 - All Rights Reserved - Matt Hawkins

      Type above and press Enter to search. Press Esc to cancel.