Infrared Voice Controlled With Snips

Greg
Greg
May 9, 2019 · 10 min read

A guest blog post by Greg.

Too many remotes? Simplify! Use your voice to control infrared devices around your home using Snips voice platform. A completely on-device assistant that does not share anything it hears, or what it is you do. Privacy by design.

Image for post
Image for post

Background

This project not only benefits me, it also fills a requirement for other users out there. My elderly parents, for example, can never find the right button to press on the TV remote. This also benefits people with disabilities who are not able to manipulate a remote physically, but are able to say to an assistant what they want to do.

Once upon a time… I had 4 remotes, just for the devices in the lounge room alone. A remote each for the TV, amplifier, DVD, and aircon. They are now in the bottom draw, and I just speak aloud what I want to control.

Some basics

Hey Snips, turn my Samsung TV on
’hey snips’ = wake word — start listening to my command
’turn my Samsung TV on’ = Intent — IR Control
Specific things about the intent that are important. (1) ‘Samsung TV’ and (2)‘on’. The IR Control application (this project) sees that you want to use the Samsung TV remote and press the power ON button, so that’s what it does.

There are two parts to this project. The IR Control and the IR Client.

The IR Control is part of a Snips assistant application.

The IR Client uses a RPi Zero with an IR receiver and emitter connected to GPIO pins. This project shows you how build and interface the RPi with an IR receiver and emitter, configure the remotes you use in your home, and then apply this information to your own Snips assistant.

If you don’t yet have a Snips setup, Snips with Seeed provide a Maker Kit to get you up and running with Snips.

Image for post
Image for post
Snips & Seeed -Makers Kit

For more information and an in-depth look into Snips, check out the Snips Docs.

Building the IR Client

Items you will require to build the IR Client:
- Raspberry Pi Zero (W version for wifi connection)
- Infrared Receiver Module — Generic 38kHz
- Breadboard (generic)
- 2x 940nm Infrared Emitters
- General Purpose Transistor NPN (PN2222A will do)
- 10k ohm Resistor
- Jumper wires (3x female-female, 3x female- male, 2x male-male)

Lay them out on a breadboard, as shown in the below images and circuit diagrams.

Image for post
Image for post
fritzing diagram of component layout
Image for post
Image for post
circuit diagram for emitters
Image for post
Image for post
Breadboard showing emitters
Image for post
Image for post
generic receiver
Image for post
Image for post
https://pinout.xyz pin assignment

Follow the layout, paying attention to the Tx and Rx signal pins. 3.3v is used by the IR receiver, and the IR emitters use 5v.

Installing the IR Client software

To install the IR Client on the RPi Zero, ssh into the device and run these commands:

git clone https://oziee@bitbucket.org/oziee/irclient.git
cd irclient
sudo bash install.sh

The install.sh script:
- creates a venv environment
- installs the python library requirements
- installs LIRC
- sets up the IR Tx/Rx pin assignment
- creates the service to start the app on boot

Once the install completes, it will prompt you to edit the settings.ini file in the current directory.

nano settings.ini

Enter in your Snips connected MQTT broker address and port, and a unique name for the IR Client device.

Image for post
Image for post

Testing the LIRC

sudo /etc/init.d/lircd stop
mode2 --driver default --device /dev/lirc0

Press some buttons on the remote control while it is pointed at the receiver and you should see the RPi console outputting multiple lines like the below:

Image for post
Image for post
console output from the mode2 when the receiver receives IR signals from a remote

Adding remote codes to LIRC

sudo /etc/init.d/lircd stop
sudo irrecord -d /dev/lirc0 ~/lircd.conf

Follow the on screen instructions. The gist of it is, you enter in a name for the remote you are recording, press random buttons on the remote over and over a few times while LIRC learns and detects pulses, signals, pause timing etc.

You will be prompted to enter in names of the function button to record such as KEY_POWER, KEY_VOLUMEDOWN. LIRC uses capitals and a list of valid values can be found here.

Image for post
Image for post

Once you have completed recording your remote, you need to copy the created file to the lirc directory which contains all the conf files. You can do a `ls` to check for the name of the file that was created. It will be something like <what you named the remote>.lirc.conf

sudo cp ~/<name of remote>.lirc.conf /etc/lirc/lircd.conf.d
sudo /etc/init.d/lircd start

Create as many remote conf as you like, making sure they are all uniquely named, and are all copied over to the “/etc/lirc/lircd.conf.d” directory.

LIRC has a repo of remote configurations created by others that can be downloaded and used. Of course, not every remote on earth has been documented and available for download. Check out the repo for a list of remotes that can be downloaded for your use.

LIRC also includes command line tools to search this repo and install them, you can read how to here.

Setting up the IR Control in the Snips assistant

Use the search field to look for “ir control” and then add this app to your assistant:

Image for post
Image for post
adding the IR Control to your Snips assistant

Once the app is installed, and the Snips skill server has taken control of running the Snips apps, you can log into the IR Control web management page from your browser by going to <url of snips server>:7777 (the default port is 7777, but you can change this to anything from inside the Snips config.ini for the app.

The management page will communicate with all the IR Clients you have built on the network, and gather a list of all the known remotes for each device and their function button mappings.

Image for post
Image for post
main page of the IR Control web interface management portal

Here you are able to add common word and names to remotes and buttons which you say out loud to your assistant. Snips will then do its magic to understand what you ask and, in turn, inform the IR Controller of which device, or remote and which button IR code you want transmitted.

In the web page enter in synonyms, or words that describe or name something. In the image example above, it would be hard to ask your assistant in a sentence that you want to use the N2QAYB000352 remote, so entering in a common word or name that you would say in conversation with the assistant makes sense. You can then say “TV” or “Samsung TV” and Snips and the IR Control app will know you mean the N2QAYB000352 remote. Same goes for the function buttons. Saying “on” or “off it knows to use the KEY_POWER button that is mapped.

“Turn the TV on” = N2QAYB000352 | KEY_POWER

Creating Your Own Actions

Image for post
Image for post
view of the Actions page

Asking your assistant, “let’s watch a movie”, the TV will turn on, the amplifier turns on. Yet the amp takes 8 seconds to start before it will react to any other remote commands, so a pause value is set, as in the example image above. A 10-second pause occurs before the next function is performed, which is to set the amp to the TV input.

Check the bitbucket repo README for extra information on the web interface.

Telling Snips assistant your setup

Image for post
Image for post

One at a time, you’ll copy the items between the *****’s and import it into the corresponding Intents slots in the Snips Console. In the above image the highlighted items are copied and imported to the `ir_control` intent, into the slot button (shown below).

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Once all the slots for ir_control and ir_action have been imported, save your assistant, and install the newly updated assistant to your Snips setup.

In future, if you rename a remote, delete a remote, add or remove a remotes function buttons, created new actions — you will need to use the Intent Builder to gather the changes to import into the Snips assistant. You should remove all the current values in the Snips console intent slots before importing new items, as this will remove old items that may no longer be valid.

Other Features

Hey Snips, start a sequence for me” — listening for your commands.
press the TV guide button
“press up button”
”up”
”up”
”select”

“ok stop listening for commands” — this ends listening. If you do not let the assistant know you want to stop announcing commands, it will just keep listening until you do.

You need to say either the device or the remote once to set a base of where to start. From then on you can just say the button commands to be completed which are mapped to that device or remote. If you want to then start interacting with a different remote, say that remotes name so that IR Control knows you now will be referring to a different remote to operate. When you want to stop using commands, just ask it to stop.

In Action

You can just see the IR emitters light up
Image for post
Image for post

What next

Start thinking about what you too could automate. The possibilities are endless, limited only by to your imagination. If you can think it, code it, make it, then use it with your own home assistant. Check out the Snips store in the console for many other applications designed by other Snips developers for you to use.

Credits

Snips Blog

This publication features the articles written by the Snips…

Greg

Written by

Greg

Snips Blog

This publication features the articles written by the Snips team, fellows, and friends. Snips started as an AI lab in 2013, and now builds Private-by-Design, decentralized, open source voice assistants.

Greg

Written by

Greg

Snips Blog

This publication features the articles written by the Snips team, fellows, and friends. Snips started as an AI lab in 2013, and now builds Private-by-Design, decentralized, open source voice assistants.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store