My family owns three cats; for the most part, they are well behaved – unless they are hungry. When it’s time for them to eat, they get a little crazy – constantly meowing and running under/bewteen our legs, or waking us up at night.
We used to keep extra food in their dishes, but they would just overeat – resulting in cat throw-up (which, without fail, I seemed to step in every morning on my way to the kitchen).
We’ve been living in this “claw-ful” situation for a few years, and never really considered resolving the problem, until I saw the re:Invent Alexa Skill contest sponsored by Capital One and Amazon Alexa. My oldest daughter suggested that we (and by we, she really meant me) build an automated cat feeder. I told her that I didn’t have the time to build one… but then, I figured, why not give it a try.
Cat Feeder Alexa Skill:
The Cat Feeder skill allows the user to:
- Feed the cat (an amount of 1, 2, 3 or 4 ounces)
- Ask when Alexa last fed the cat
- Ask if the cats have food
- Ask if the cat feeder needs to be refilled
- Tell me a cat joke (an easter egg, of sorts. Really for my kids)
Commands interact with the physical Cat Feeder using AWS IoT by sending messages to the device via MQTT or getting status of the feeder via device shadow (more on this in the technical sections).
Note – The above video does not show the cat joke intent (or passing the amount slot with the feed cat intent). See video below for demo.
Raspberry Pi Cat Feeder
The RPI feeder (inspired by David Bryan’s Automated Cat Feeder) executes the commands from the skill in the following manner:
- A servo is used to rotate a paddle-wheel (which dispenses the food)
- A usb camera is used to send a photo of the cat food bowl back to user (to determine if the cat’s food bowl is empty)
- A light sensor is used to determine if more food needs to be added to the hopper.
Note – For those that are looking into building Alexa skills, please read and consider. Otherwise, skip this section to get to the “how to build/replicate” the skill.
I’ve published 4 or 5 Alexa skills – each slightly better than the previous one. I wanted to take my learnings from those activities and apply them to this skill. Here were my design principles:
Reuse-ability – I wanted to limit barriers to use this skill. For this skill, that meant:
- No account linking: My skills typically need to save user preferences. In the past, I’ve used Google Auth to enable account linking – retrieving the user id to save preferences to in a DyamoDB table. Google recently changed how they allow authentication in web apps, which “broke” a few of my skills. I didn’t want to live through that again, so I decided to use the Alexa user id to persist user preferences.
- Limited code configuration by the end user: I wanted to make configuration of the physical device as simple as possible, so I (a) build the configuration instructions into the skill and (b) limited the code changes to one variable change in two scripts.
- Maintain-ability – My previous skills were too difficult to maintain. The code was overly complex. For this skill, I decided to RTFM (read the freaking manual) and made better use of the functions provided by the Alexa Skills Kits SDK and Alexa IoT SDK. I also made heavy use of local development (as outlined in this tutorial by Nathan Grice. This saved me HOURS of testing time).
Security – My last IoT skill was not built with security in mind. I didn’t restrict policies or roles, which became a problem when others wanted to replicate my project using my Alexa skill. This time, I thought through my security before I started coding. This allowed me to restrict roles and policies so that I could share access keys and certificates without fear of allowing too much access.
A Hacking/Prototype PoV – As I stated in the introduction, I wasn’t originally going to build this device – as I didn’t think I could get a working prototype in place by competition deadline. But, I decide to give it a go, because the time for me to build the skill (basically, over Thanksgiving weekend) was about 30-40 working hours. I wanted to prove that a working prototype could be built in this time – hopefully inspiring companies to allow their employees to invest 1-2 work weeks developing an Alexa skill for their companies.
olution Build: Cat Feeder Alexa Code
Note: this section details how I built the Alexa skill.
This Alexa skill is somewhat advanced and uses multiple AWS “services” (in addition to Lambda). For those new to Alexa development, I suggest you start first with the Alexa getting started guide. If you’ve developed Alexa skills before, please continue.
The skill (written in node js) is build on the Alexa Skills Kits SDK for Node.js and requires the following code dependencies
- AWS IOT SDK
One DynamoDB table is needed:
- Table Name: Cat_Feeder_Config
- Primary partition key: UserId (String)
One S3 bucket is needed:
- I called mine CatFeeder
API key from APIUX to get day/night information based on zipcode (https://www.apixu.com/ )
The role used will need to have permissions to IoT and DynamoDB
Read More: Alexa powered Automated Cat Feeder