Using Amazon Echo/Alexa for control of DIY gadgets

Does anyone here have experience with using Amazon Echo/Alexa for controlling home-made gadgets? Alexa does a good job of converting speech to HTTPS requests. (According to reviews, this works in real world environments; background noise and distant microphones.) See https://developer.amazon.com/public/sol … rted-guide for an introduction to the API.

I have several home automation projects connected to a central home server (old laptop). Currently I control them with a web browser interface, but it would be nice if I could also use voice commands.

The Alexa API seems to be fairly open, but it is geared toward widely used public services rather than web services which exist on one’s own home network. Has anyone tried to make this work?

EDIT: Further googling turned up this: http://www.instructables.com/id/Hacking … azon-Echo/

Never heard of it.

I finally got around to buying an Echo Dot (Amazon/Alexa), and it is indeed practical to control my home gadgets with voice commands using the Echo Dot. Using the Alexa API, you can send any sort of HTTP request you want (in response to voice commands). My DIY home automation devices were already controllable via HTTP, so it was just a matter of programming the glue to connect Alexa to my gadgets.

I have several sparkfun things with SI7021 (temp +humidity ) posting to blynk. Can you be so kind as to share some code so I can see how to integrate these with may Amazon dot

Posting a complete code example would be a lot of work – the code and configuration is spread between many files.

Here is a quick and terse guide:

(1) Read the Alexa API documentation. One starting point is here: https://developer.amazon.com/public/sol … rted-guide

(2) Use the “lambda function” option – it’s much easier than hosting everything on your own server.

(3) Use the “favorite color” (or maybe it’s called “color picker”?) sample code from Amazon as a starting point. I used the node.js version.

(4) Here’s an intent handler which interacts with an external URL, which could be any internet-accessible server. (Be sure to select a “role” for the lambda function which allows outgoing internet access.)

// ------- intent handlers ------------

function getCurrentTemperature(intent, session, callback) {
	const cardTitle = 'Personal get current temperature';
	const thermometerSlot = intent.slots.Thermometer;
	let repromptText = '';
	let sessionAttributes = {};
	let shouldEndSession = false;
	let speechOutput = '';
	
	var thermometer = 'back porch';
	if (thermometerSlot && thermometerSlot.value) {
		thermometer = thermometerSlot.value;
	}
	thermometer = th_name_normalize[thermometer] || thermometer;
	
	var abbr = th_abbrev[thermometer];
	if (!abbr) {
		callback(sessionAttributes,
			 buildSpeechletResponse(cardTitle, 'unrecognized thermometer name', null, false));
		return;
	}

	var options = {
		host: 'homeserver.mypersonaldomain.net',
		port: 8456,
		path: `/get_temperature?name=${abbr}`,
	};

	var callback2 = function(response) {
		var json = '';
		response.on('data', function (chunk) {
			json += chunk;
		});
		response.on('error', function (e) {
			console.log("Error message: " + e.message);
			callback(sessionAttributes,
				 buildSpeechletResponse(cardTitle, 'H.T.T.P. error', null, false));
		});
		response.on('end', function () {
			var data = JSON.parse(json);
			if (data) {
				if (data.error) {
					speechOutput = `There was an error: ${data.error}.`;
				}
				else {
					speechOutput = `The ${thermometer} temperature is ${data.degf}.`;
					shouldEndSession = true;
				}
			} else {
				speechOutput = "unable decode JSON";
			}
			callback(sessionAttributes,
				 buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
			});
	};

	http.request(options, callback2).end();

}