____ _ _
___ _ __ / ___|___ _ __ | |_ _ __ ___ | | _ __ _ _
/ _ \ '_ \| | / _ \| '_ \| __| '__/ _ \| | | '_ \| | | |
| __/ | | | |__| (_) | | | | |_| | | (_) | |_| |_) | |_| |
\___|_| |_|\____\___/|_| |_|\__|_| \___/|_(_) .__/ \__, |
|_| |___/
____ _ _
___ _ __ / ___|___ _ __ | |_ _ __ ___ | | _ __ _ _
/ _ \ '_ \| | / _ \| '_ \| __| '__/ _ \| | | '_ \| | | |
| __/ | | | |__| (_) | | | | |_| | | (_) | |_| |_) | |_| |
\___|_| |_|\____\___/|_| |_|\__|_| \___/|_(_) .__/ \__, |
|_| |___/
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.
I had the hardware, and I needed an easy way to call the sockets from a Home Assistant instance on a separate machine.
These instructions will get you a copy of the project up and running on your Raspberry Pi.
Here is what you will need:
- Raspberry pi (I'm using an RPI1 model B+)
- The pi-mote board https://energenie4u.co.uk/catalogue/product/ENER314
- The energenie sockets https://energenie4u.co.uk/catalogue/product/ENER002-4
For more info on interfacing with the pi-mote check the energenie website (PDF).
- Python (2.7 or 3.x) & required packages
- flask
- RPi.GPIO
wget https://raw.githubusercontent.com/ragebflame/enControl/master/install.sh && chmod +x install.sh && ./install.sh
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
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)
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
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
- 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 👀
Pull Requests welcome.