Control a Raspberry Pi with your voice
Web agency » Digital news » Control a Raspberry Pi with your voice

Control a Raspberry Pi with your voice

In today's article I close my roller shutters with my voice!

For the example, I chose to associate my personalized order with a control script for my roller shutters on my Raspberry. However, you can use this example to interface any script and therefore do home automation at home controlled by voice.

Application to trigger actions on the RPi

The web application is created using the Python framework named Flask.

We start by installing the framework on our Rpi.

We create a python file that we make executable

Here is the code used. I have defined 2 resources: opening and closing.

In the example I am using the “GpioControl” class that I am giving you as an example. This places the GPIO ports in a “1” state for one second. Obviously, this script is specific to the control of my roller shutters. You must replace yours as part of the home automation control you are developing.

Start the Flask Web server (I run in sudo because the GPIO library requires root rights)

We will test the resource. On Linux I test using the Curl tool. The syntax is as follows

To test the “closure” resource, I type

Creating the Tasker action

I'm assuming you've already created an event and recorded the voice command. We will now create the action associated with this event.

The action will consist in sending the HTTP POST request to the Flask server on the Rpi.

  • In the task menu previously opened following the creation of an event, enter a name for your task.
  • Click on “+” to add a new action
  • We go to the “Network” category, then “Post HTTP”
  • In “Server: Port” we give the IP address of the Rpi as well as the port of the Web server. In my case 5000, the default port of Flask
  • In “path”, enter the URL of the requested resource. In my example / closure
  • In “Data / file” I place my data sent in the POST, namely a password. password = ”mypass”

flask_http_rpi

Voila, all you have to do is call the order via Google Now. This is what it gives me.

★ ★ ★ ★ ★