Remotely control power sockets from the Raspberry Pi
Branch: master
Clone or download
Pull request Compare This branch is 4 commits ahead of RPi-Distro:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
energenie
examples
.gitignore
CONTRIBUTING.md
LICENCE.txt
MANIFEST.in
README.rst
boot_gpio.sh
mkdocs.yml
setup.py

README.rst

Energenie

Python module to control the Energenie add-on board for the Raspberry Pi used for remotely turning power sockets on and off.

This has been tweaked so it can be used outside a persistent Python instance.

This fork of the original uses sysfs instead which means after booting and setting the GPIOs up, it can be run as which ever user is given permissions to the sysfs GPIO files.

Example of setup, maybe in /etc/rc.local

echo 17 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio17/direction chmod 766 /sys/class/gpio/gpio17/value

echo 27 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio27/direction chmod 766 /sys/class/gpio/gpio27/value

echo 22 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio22/direction chmod 766 /sys/class/gpio/gpio22/value

echo 23 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio23/direction chmod 766 /sys/class/gpio/gpio23/value

echo 24 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio24/direction chmod 766 /sys/class/gpio/gpio24/value

echo 25 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio25/direction chmod 766 /sys/class/gpio/gpio25/value

Installation

On Raspberry Pi, install the energenie module in pip.

Python 3:

sudo python3 setup.py install

Usage

Example usage:

from energenie import switch_on, switch_off, switches_init
from time import sleep

# ready switches if this is first run
switches_init()

# turn all plug sockets on and off
switch_on()
switch_off()

# turn a plug socket on and off by number
switch_on(1)
switch_off(1)

switch_on(3)
switch_off(3)

# turn some plug sockets on, then turn them off after 10 seconds
switch_on(1)
switch_on(4)
sleep(10)
switch_off(1)
switch_off(4)

# get states of which plugs on/off.
plugs_state_array = get_plug_state()

Contributors

Open Source