Teaching Alexa to 3D Print

Sometimes a gadget like Alexa or Google Home is a solution looking for a problem. Then the problem you’ve been looking for hits you square in the face. I’ve confessed before that I have an oscilloscope problem. I also have a microcontroller development board habit. It appears now I have too many 3D printers. I recently finished building my latest one, an Anet A8 I picked up on Black Friday. While calibrating it, I found myself juggling a screwdriver, a pair of pliers, and trying to operate the thing all at one time. I realized I had to come up with a better way.

I don’t know if it qualifies as an addiction yet, but I also have an Alexa in every room (although I call it “Computer” because I’m a Star Trek fan) and a Google Home device almost everywhere. Why can’t I get one of these assistants to operate my printer for me? What are assistants for, after all, other than telling Dad jokes?

You’d think adding voice control to a 3D printer would a bit difficult. With the right tools, it is actually pretty easy. Luckily those tools aren’t anything special… if you want a set up like mine, where Alexa controls your 3D printer, read on.

The Plan

Obviously, the Alexa is going to be my voice control input so that part is taken care of. You could use Google Home, too. What would have been the hardest part a few years ago is now perhaps the easiest part, paradoxically.

The second part of the puzzle is Repetier Server. You could probably use Octoprint (Tom Nardi just wrote a great guide for setting up Octoprint), but I use Reptier. If you haven’t used either, these programs create a Web page that allows you to control your printer from a browser. They also provide a Web-based API. That means you can send commands to your printer remotely just by forming a valid web request.

You might be able to guess the third part of this equation: If This Then That or IFTTT. You’ve probably used this before. It is something of a Swiss Army knife for routing web events to different web services.

With these three items — a voice control assistant, a web server that controls your printers, and an IFTTT account, you are almost there.


It is easy enough to get IFTTT to take a trigger phrase from your assistant and do something about it. For Alexa, you have to say “Alexa, trigger mumble mumble” which would send “mumble mumble” to IFTTT. The problems is, what to send?

There are three things you’ll need to accomplish to get something like “Alexa, trigger 3D printer home” to work. First, your Reptier Server needs to be accessible from the public Internet. Yes, hackers might take over your printer, but I’m willing to take that chance. Since IFTTT will send web requests to your server from outside your network, you have to do this to work with IFTTT.

Second, you need an API key from your copy of Repetier Server and the “slug” name of your printer. You might think this would give you some relief from print-happy hackers, but no. It is easy enough to find the key and the printer names. The “slug” is a short internal name for each printer that the user doesn’t necessarily see.

The third thing is, you need the commands you want to send the printer. For example, homing is G28. You can send any G code you like or even multiple G codes.


You should open your printer server to the Internet using some non-standard port. For example, Repetier Server normally is on port 3344. You might want to expose port 9999 instead. That isn’t bulletproof security, but it can’t hurt. How you do this depends on your network. Check your router for “Port Forwarding” and direct requests on your chosen port to the IP address of Repetier Server. If you need more guidance just Google your router’s model number and “port forwarding”.

Since your external IP address is probably not static, you will also want some dynamic DNS forwarding to associate a URL name with your external-facing machines. I have my own DNS servers, but Duck DNS works well. There are plenty of others, too.

Try your commands from a web browser to make sure they work. The first command you can send is just to get information. As an example let’s say your server is at the fake address dyn.hackaday.com:1430. Try this URL from your browser:


You’ll see something like this (broken up for readability):

{"apikey":"1ca77731-aaaa-4c31-a44a-65deadbeefb8","name":"Repetier-Server Free",
"printers":[{"active":true,"name":"Monoprice Select Mini","online":0,"slug":"Monoprice_Select_Mini"},
{"active":true,"name":"Printrbot Plus","online":0,"slug":"Printrbot_Plus1"},
{"active":true,"name":"Anet A8","online":1,"slug":"Anet_A8"}],"version":"0.86.2"}

You can probably deduce that the big hex string is your API key (this one’s fake). You can see my three printers which the server knows as Monoprice_Select_mini, Printrbot_Plus1, and Anet_A8.

Next, try to do a printer home. You should jog the print head somewhere so you get a dramatic homing when it works. Try this (substituting your details for the bold text, of course):


The URL encoded characters after “data=” are actually these characters: {"cmd":"G28"}. You can probably enter them that way into your browser and it will convert them, depending which browser you use. Repetier won’t send anything exciting back to the browser, but if all went well, your printer should home.

By the way, forwarding an external port to your 3D printer is a security hole. For a normal set up, you could ask Repetier to authenticate users or keep the service safe with, say, port knocking, VPN, or some other secure scheme. The problem is IFTTT — the thing we’ll use in the next step — is going to need to talk to the printer from outside and it isn’t going to know how to authenticate or otherwise open your ports.

If you were serious about using this and serious about security, you could write a small web service that would do something smarter to authenticate you and then forward the request to Repetier which would no longer be outside-facing. However, whatever authentication method you use would have to be one that IFTTT could handle without exposing your secrets (in other words, just passing a password in plain text isn’t the answer).

In my case, I didn’t feel too worried that during the times my printer is on that someone would scan all the ports I expose looking for 3D printing servers and start printing spam on my printers.

If Then

Once you have your web service working and accessible, you can open up IFTTT. Sign in and go to the My Applets page. Click New Applet. You’ll see “if + this then that” and you want to click the plus sign.

From the list of services, find Amazon Alexa (the search box works well). When you click that service, pick “Say a Specific Phrase”.  From there you will tell IFTTT what you want Alexa to listen for after the word “Trigger.” For example, you might enter “3d printer home.” For some reason, the text has to be all in lower case and sometimes you have to spell things like they sound so Alexa will understand. For example, “anet” required me to say “Ahhh-net” which was too hard to remember, so I changed that pretty fast.

Press “Create Trigger” and you’ll now see a plus sign between the word “then” and “that” — press it. Find the service called Webhooks and click it. There will be a single choice called “Make a web request.” Click that.

In the URL box, you can put the whole string you had working in your browser. You can use the non-URL encoded characters here. For the method, select GET and the content type is application/json. You can leave the body field blank. Click Create Action and then Finish. That’s it!


Now to home your printer just say “Alexa, trigger 3d print home.” IFTTT doesn’t give you much in the way of diagnostics, so if it doesn’t work, you’ll have to play around a bit. I actually changed mine to “3d printer” but I probably need to change it again since I have more than one I need to command.

You can add as many of these commands as you like. For example, the commands “M140 S50 M104 S190 T0” would heat your bed and extruder up to 50 and 190 degrees. You could turn on the fans, home the Z axis (my favorite), or anything else you can do in G code.

You can also do some things that aren’t in G code. For that, you’ll need to read the Repetier API documentation. For example, the copyModel command can start a job, and stopJob might be handy if you are across the room and notice the print has fallen off the bed. For that matter, if you are watching over a web camera and you have an Alexa nearby, that might be really handy!

This is a quick and easy way to add voice control to your printer. You might find it is one of the better uses for your virtual assistant. It would be nice if there was a more secure way to expose the service. Also, I am aware most people use Octoprint and that should be able to pull the same trick. If you’ve managed either of those, please tell us how you pulled it off in the comments below.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *