Wednesday, September 5, 2018

Raspberry PI Relay Control using Python and Flask

I wanted to create a party button accessible from a web site using Python and Flask. Buckle up folks.

So somehow I got flask up and running. There should be a ton of articles on how to install it. I seem to remember it being pretty easy. Just google it already.

I created a new directory called party. Inside this directly I created a static and a template directory. I then created a file called

Here is the script

You can park all your images and such in the static folder and reference them using flask templates. In the template folder I created the look and feel I wanted for the web pages served up by flask.

You can see I call the template in the with the return render_template command. So when you start a party you are quickly returned to the index.html page. Here is the index.html page

I wanted a cool DJ Air horn so I grabbed it and I am using VLC command line to run that. You will notice that the Flask is setup to run a couple other Python Scripts. This is my party start and party stop functions. These python scripts control the relay.

Pretty straight forward on the Relay control. You'll notice on the I wanted to call a little DJ airhorn to really kick the party off right. I am using the VLC command line interface to do that.

Here is what end result looks like

This can be expanded to do all sorts of fun stuff. Using this basic Flask/Python example you setup several different web based controls using Raspberry Pi.


Post a Comment