Please read the disclaimers[1][2][3][4] below

For the last seven years, I have built and operated home kegerators. Each date a keg was tapped or emptied was recorded in a paper journal. I was tracking data at the 'keg' level with no visibility into the 'pint' level. This mean I never had a way to predict the amount of beer left in a keg.

There are solutions to this problem. This includes measuring tools available such as flow sensors, scales, or thermal decals. None of these options would provide accurate readings without compromises. There are also more advanced monitoring systems based on a Raspberry Pi and an Arduino. Kegbot is one example of this. I did not find this option as useful in a home office environment where I was the only one using the kegerator.

While not directly related, my current role at work requires that I learn AWS services. This lead me to explore a cloud-based approach to solve my problem, At one point I was wondering if I could use a DeepLens to watch each beer poured and record the details. Eventually I began tracking data using an AWS IoT button.

Pouring a beer with an AWS IoT button and Amazon Echo

At first I was recording each pour and keg swap into a DynamoDB table.  Initially I set up the IoT button and DynamoDB table in us-east-2 as that is the geographically closest region. The DynamoDB table was a simple design where a UTC timestamp was my primary key and each item would note 'beer' or 'keg' which represented a single or double tap of the IoT button. With this data I could track how many beers were poured in a given day. Since each pour was closely uniform as a full pint, the data could be used to estimate the current keg level.

I had originally intended to integrate this into an Alexa skill when time allowed. After a few months of collecting data, I found myself manually querying the DynamoDB table to make sure I recorded a pour or to look into statistics. That bottleneck was enough motivation to invest in creating a Lambda function and a corresponding Alexa skill to easily access the recorded data.

This is about the point where I gain some valuable hands-on experience with DynamoDB. I had failed to recall my earlier experience creating an Alexa skill when choosing the region for the IoT button integration. I had to create my Lambda in us-east-1 in order to connect it to an Alexa skill. Rather than re-configuring the IoT button to point to us-east-1, I chose to use DynamoDB global tables and replicate between the two regions. At which point I realized I need to start with an empty table in order to convert the current table into a global table. No problem though, I only had a few months of data. It would be easy to create a backup and restore the data after I converted my table to a global table. This continued to be a learning exercise as I quickly discovered that I could not easily restore or import my old data. I had to create a new table from the backup which allowed me to export the data as CSV. Then I used the AWS CLI to batch write items back into the table 25 items at a time. This would have been faster than placing the CSV into S3 and using the AWS Database Migration Service to migrate the data over.

Now that my DynamoDB table was also in us-east-1, I was able to create a basic Lambda function that can access the IoT button data. Once I was able to grasp the array structure that DynamoDB returned, I was able to determine how many beers were poured in the last 8 hours. When I was looking to gather data based on when the kegs were tapped, I realized that I needed to arrange my data in a different way. I was able to group by the type of IoT button event by creating a Global Secondary Index. The result being the Lambda function displayed below:

Lambda Function

Please note that this is my first real use of Python. I come from a strong background in Bash. There may be unnecessary or poorly optimized code in this example.  

My goal was for Alexa to summarize kegerator statistics. I did not require an interactive Alexa skill for this. Because Alexa only requires a basic JSON response to speak a result, I had decided to return the JSON manually rather than use a more complex Alexa skill design. I could however take the skill further to report other statistics or write data. An example may be to ask Alexa to delete the last pour record if it was made by mistake.

Connecting the Lambda with an Alexa skill consists of copying Skill ID from the Amazon Developer console as well as the ARN of the Lambda function from the AWS console and entering the data in the opposite console. Another consideration I had was the ability for Alexa to quickly decipher the name of the skill. I settled on a simple name and the skill is invoked with saying "Alexa, open tab" (as in a bar tab).

The End Result


1. I had a pragmatic approach to this project.
2. I do not consider myself a software developer.
3. This is the first time I have used Python, Bash scripts are my wheelhouse (example).
4. The views and opinions expressed are not those of my employer and are mine alone.