Knowledge for the World

How to use Siri to control anything -- from IFTT to custom programs and devices

Voice control is a rising trend with products like Alexa and Google Home appearing in more homes. For DIYers and hackers, there are a number of ways take advantage of some of these tools to build voice controlled applications. Yet, it's remained difficult to take advantage of the voice control features implemented in Siri for any custom use. Fortunately, a howchoo reader named Sanjeet turned us toward a tool he wrote called SiriControl that allows you to use Siri as the voice control mechanism for your applications. This guide will walk you through the process of setting up and using SiriControl.

Before we begin, here is a brief overview of how SiriControl works. SiriControl takes advantage of Siri's ability to record notes. So we'll configure Siri to write new notes to a Gmail account. Then SiriControl will read new notes from that Gmail account, parse the text, and execute any modules that match a list of words.

1

Create a dedicated Gmail account

SiriControl utilizes the notes feature of Gmail. And since we have to disable a few security mechanisms to allow SiriControl access to our notes, it's wise to use a Gmail account dedicated to this project.

You can create your Google account here. As always, use a secure password and store it securely.

2

Enable access for less secure apps for Gmail

Visit this site and click the toggle to Allow less secure apps.

3

Enable IMAP for Gmail

From your Gmail account, click the Settings cog icon, then click Settings. Then click the Forwarding and POP/IMAP tab at the top. Now click Enable IMAP.

4

Add your new Gmail account to your iOS device

On your iOS device, go to Settings > Notes > Accounts > Add Account.

Click on the Gmail logo and sign in to your newly created account.

5

Enable notes and ensure it is the default account for creating notes with Siri

After creating the account, make sure that Notes is enabled.

Then navigate back to the Notes settings page, and select this account as the Default Account.

6

To clone the SiriControl repository, you'll need Git installed on your machine.

Then clone the SiriControl repo with:

git clone https://github.com/theraspberryguy/SiriControl-System

7

Navigate into the SiriControl-System directory. Open the siricontrol.py file and add your Gmail credentials.

8

To see how this works, simply run the following:

python siricontrol.py

Then on your iOS device activate Siri and say:

"Note - What is the meaning of life?"

Then within a second or two, you'll see the following print to the screen:

The word(s) 'what is the meaning of life' have been said


------------------The meaning of life is 42-------------------


The module 'life' has been executed successfully.

9

In this step, I'll build a module that I'll actually use. In a recent project, I wired up a Raspberry Pi to control my garage door. So I'm going to write a SiriControl module that allows me to open and close my garage door.

So first I'm going to add a file called garage.py in the modules directory. modules/garage.py will contain the following:

import json
import requests
import sys


moduleName = 'garage'
commandWords = ['garage', 'door']
GARAGE_HOST = 'http://192.168.1.183'


def execute(command):
    try:
        action = command.split(' ')[0]
    except IndexError:
        print('No command passed.')
        return

    if not action in ['open', 'close']:
        print('Invalid action.')
        return

    response = requests.get('{0}/status'.format(GARAGE_HOST))
    status = json.loads(response.text)

    if action == 'open' and status.get('open'):
        print('Door already open.')
        return

    if action == 'close' and status.get('close'):
        print('Door already closed.')
        return

    requests.get('{0}/relay'.format(GARAGE_HOST))

If you're familiar with Python, you can probably see what is going on. If not, I'll explain.

First, there are a few requirements to create a SiriControl module. You need to specify the moduleName, the commandWords, and create an execute function.

If the commandWords are matched, siricontrol.py will pass in the whole command (the note text) to the execute function. So in my case, I'm expecting the note to say either "open the garage door" or "close the garage door". So I'm deriving the action from the first word of the command. Then I'm hitting the API for my garage door to see the current status because my API to open and close the garage door is really just a toggle. So if I say "close the garage door" I don't want it to accidentally open the garage door. So after this validation, if we haven't returned out of the function, we toggle the garage door.

So this is how you create a module! If you need help, you can take a look at modules/templateModule.py.