Skip to content

Python flask API for controlling energenie pi-mote on raspberry pi

License

Notifications You must be signed in to change notification settings

ragebflame/enControl

Repository files navigation

____            _             _
  ___ _ __  / ___|___  _ __ | |_ _ __ ___ | |  _ __  _   _
 / _ \ '_ \| |   / _ \| '_ \| __| '__/ _ \| | | '_ \| | | |
|  __/ | | | |__| (_) | | | | |_| | | (_) | |_| |_) | |_| |
 \___|_| |_|\____\___/|_| |_|\__|_|  \___/|_(_) .__/ \__, |
                                              |_|    |___/

Python flask API for controlling energenie pi-mote on raspberry pi

What does this do

This is a Python script which interacts with an energenie pi-mote using a flask api. This will allow you to turn sockets on & off with rest requests.

Why you ask

I had the hardware, and I needed an easy way to call the sockets from a Home Assistant instance on a separate machine.

Okay cool! let's get started

These instructions will get you a copy of the project up and running on your Raspberry Pi.

Here is what you will need:

Hardware

For more info on interfacing with the pi-mote check the energenie website (PDF).

Software

  • Python (2.7 or 3.x) & required packages
  • flask
  • RPi.GPIO

Installation

Automated install

wget https://raw.githubusercontent.com/ragebflame/enControl/master/install.sh && chmod +x install.sh && ./install.sh

Manual install

For Debian based distros:

sudo apt update && sudo apt upgrade -y
sudo apt install git python pip
git clone https://github.com/ragebflame/enControl
cd enControl && sudo pip install -r requirements.txt

Run

sudo python enControl.py

server running:

sudo python enControl.py
 * Serving Flask app "enControl" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)

REST requests

Available POST requests

id commands
1 on / off
2 on / off
3 on / off
4 on / off
all on / off

Check API

curl -i localhost/energenie-control/api/v1.0/gpio_pins
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 25
Server: Werkzeug/0.14.1 Python/2.7.6
Date: Fri, 19 Oct 2018 12:21:06 GMT

Turn socket 3 on

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"id":"3","command":"on"}' \
  localhost/energenie-control/api/v1.0/gpio_pins

Run on startup

To run the flask server on startup, add the following to the /etc/rc.local file before the "exit 0"

# Start the flask server - Python 2
sudo python /home/pi/enControl/enControl.py &
# Start the flask server - Python 3
sudo nohup python3 /home/pi/enControl/enControl.py

exit 0

Tasks

  • Implement Travis-CI
  • Re-factor code using Flake8 linter
  • Add an auto-install script
  • Update the README to reflect Python3 installs on the RPI
  • Add Home assistant config
  • Expand unit test coverage
  • Add install steps for Arch based distros
  • Add additional functionality
  • Improve this readme 👀

Contributing

Pull Requests welcome.

About

Python flask API for controlling energenie pi-mote on raspberry pi

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published