We a drink a lot of coffee at our house. Making a voice-activated coffeepot was a natural first idea when we talked about bringing voice to a device in the real world. Our coffeepot is already has a timer, but we wanted to prepare the coffeepot and have it start our coffee when we were ready for. Timing the coffee to start right before dessert can be a difficult guess.
First, we made a removable device to fit on top of the coffeepot and made sure it was able to trigger the brew cycle.
We then worked on setting up the Alexa skill. For this we based the skill off of mission 3 from the EV3 Alexa example missions and the Hello World example. The main departure from the mission 3 code was the handler that is setup to send a custom start type directive.
const StartCoffeeIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'StartMyCoffeeIntent';
},
handle(handlerInput) {
const request = handlerInput.requestEnvelope;
const attributesManager = handlerInput.attributesManager;
const endpointId = attributesManager.getSessionAttributes().endpointId || [];
const directive = Util.build(endpointId, NAMESPACE, NAME_CONTROL,
{
type: 'start',
});
var speakOutput = 'Starting your coffee!';
return handlerInput.responseBuilder
.speak(speakOutput)
.addDirective(directive)
.getResponse();
}
};
After successfully triggering a custom Alexa skill, we went about setting up the EV3 python code to move the medium motor to press the brew button when receiving the start directive.
def __init__(self):
"""
Performs Alexa Gadget initialization routines and ev3dev resource allocation.
"""
super().__init__()
# Ev3dev initialization
self.arm = MediumMotor(OUTPUT_A)
... other code ...
def _start_coffee(self):
"""
Handles start commands from the directive.
Moves the arm to trigger the coffee pot to start.
"""
self.arm.on_for_seconds(SpeedPercent(-100), 1)
time.sleep(1)
self.arm.on_for_rotations(SpeedPercent(100), 0.3)
After learning some python, we were able to get the Alexa skill to run the coffeepot. Mute your Echo if it is nearby before watching the video.
Thanks for reading about our project!
Comments