This flask API uses the raincloudy python library.
I am not a Python programmer; this is really bad code. Please fix it. There is no authentication because the expectation is that you're running this on your internal, trusted home network. You've been warned.
WARNING: I only have 1 controller & 1 faucet, so while this should work for multiples of each, it has not been tested.
- Install raincloudy, flask, flask-jsonpify, json
# pip3 install raincloudy # pip3 install flask # pip3 install flask-jsonpify # pip3 install json
- Change the EMAIL/PASSWORD/PORT variables in the raincloudy_flask.py. My port in the example is 5059.
- Change directory in the .service file to match where your raincloudy_flask.py file is.
- Copy service file to /lib/systemd/system/ then enable it.
# systemctl daemon-reload # systemctl enable raincloudy.service # systemctl start raincloudy.service
- Grab the Dockerfile via wget and put it in a directory on your Docker server. Then run the commands below from that directory
# docker build -t raincloudy-flask --build-arg EMAIL='your@email.address' --build-arg PASSWORD='your_password' .
CTRL-C out of it when it's complete. PORT is optional and will default to 5059- Run your newly created image:
# docker run --restart unless-stopped -p 5059:5059 -e CURL_CA_BUNDLE="" --name raincloudy-flask -t raincloudy-flask
(if you changed the port when you built your image, you should also change it here) - That's it. If you need to troubleshoot your docker image, you can get into
it via:
# docker exec -it raincloudy-flask /bin/bash
or# docker run -it raincloudy-flask /bin/bash
and then poke around.
# curl -s http://yourip:5059/api/status # curl -s http://yourip:5059/api/[controllerid|status]/[faucetid]/[open|close|auto|rain/[zone#]/[time in mins/0/1]
See here.
- Your controller id and faucets should be listed when you start the image/script:
Controller: d88039xxxxx Status: Online > Faucet: xxxx Status: Online * Serving Flask app "raincloudy_flask" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off * Running on http://0.0.0.0:5059/ (Press CTRL+C to quit)
- Test this inside, not hooked up before running in production. You can easily hear the valves open and close.
Bug me on Twitter at @brianwilson or email me here.