Teabot, in its Lego housing

We like drinking tea and so we have a large teapot, someone makes a Teapot, we all drink tea and everyone is happy.

Well almost, the problem is how do you know when there’s tea in the pot, how many cups of tea are left in the pot or how old the tea is?

To solve this important issue we did what any engineering team would and hooked our teapot up to the internet.

It’s simple really all you need is

1x USB Postage Scale

1x Raspberry Pi

1x Thermometer

We use the scales to measure the weight of the Teapot, the thermometer to report if the tea if warm and the raspberry pi ties it all together with some Python.

All of the electronics fit behind the scales

The state of the Teapot is represented as a finite state machine that looks something like:

It’s defined here — https://github.com/gbrady92/Teabot/blob/master/teabot/teapot_state.py

No Teapot is the initial state and where the state machine will reset to if the application crashes

We then combine the state we’re currently in with readings from the scales and temperature sensor to decide which state to transition to.

We weighed the teapot with a kettles worth of water in to get the threshold for a new pot of tea

We know how much the teapot weighs with no water in to detect when its empty

Anything between these two measurements means we some tea in the pot but it’s not a new one

Unfortunately the temperature sensor turned out to not work that well, and so our cold teapot detection is pretty flakey

All of this logic is implemented in here — https://github.com/gbrady92/Teabot/blob/master/teabot/status_helpers.py#L152

So with the ability to workout what state the teapot is in we now just needed to let everyone know when there was a new teapot and let them query how many cups are remaining

We wanted to have a web interface for getting stats and interacting with Teabot so we decided to handle that away from Teabot on the server side.

We use callbacks for the transitions to POST information about the new state of the teapot to the server

This allows us to keep a history of every state the Teapot has been in for fun analytics later on

Aswell as posting the new state of the Teapot to the server if we’ve entered the FULL_TEAPOT state we kick off a brewing timer.

ISO 3103 — https://en.wikipedia.org/wiki/ISO_3103 the Tea brewing standard recommends 6 minutes but we found this to be too long so we only wait 3 minutes for it to brew.

And once the brewing timer has expired Teabot POSTs a message to the server telling it to post a message in our Slack channel announcing the Teapot as being ready for drinking.

Finally we implemented a Slack webhook to allow people to use a /teabot command to POST a message to the server asking how many cups of tea are remaining in the teapot and we use the last history item that was send to us to answer that question.

The webserver is a simple Flask app that lives here — https://github.com/AaronKalair/teabot_endpoints/blob/master/teabot_endpoints/endpoints.py

(Fun fact there’s an endpoint that returns the 418 I’m a Teapot status code — https://github.com/AaronKalair/teabot_endpoints/blob/master/teabot_endpoints/endpoints.py#L134 )

This was V1 of Teabot that was released, and with a set of scales showing how heavy the teapot was a leaderboard grew on the whiteboard next to Teabot with the heaviest pot that had been made.

So we decided to turn this into a full feature of Teabot and teabot_stats was born — https://github.com/AaronKalair/teabot_stats

Teabot stats is a React / Redux application that lets you claim a teapot if you’ve made it

And uses that information to build a leaderboard or “Tea-derboard” as is now known — https://github.com/AaronKalair/teabot_stats/pull/21/files

Letting everyone see your tea brewing skills.

It also provides a handy overview of the status of the Teapot and keeps track of the total number of Teapot’s we’ve made along with the total weight of tea made.

After about a year we’d make 1Mg of tea and had a cake to celebrate

So there we have it, an internet connected Teapot to keep track of our teapot and provide stats and a leaderboard.

This blog post is based upon this 3 minute lightning talk I gave at PyconUK

Follow me on Twitter @AaronKalair