Allan Ramsay
Nespresso Pi

Nespresso Pi

💡
Note: I wrote this post a number of years ago, so it references old versions of software and may not be entirely up to date. The coffee machine in question wore out and I have replaced it with a regular espresso machine that I have not automataed... yet...

So we all know that coffee is pretty important, it's pretty much productivity in a cup. And pushing the "give me coffee" button on the machine is just wasting energy. Time to solve this problem that is not at all really a problem.

Enter a coffee machine with Bluetooth, a Raspberry Pi, some JavaScript and several cups of aforementioned coffee. The goal here is to integrate this machine into the existing home automation system so that Alexa can find it, then we can setup a routine:

"Alexa, make a coffee" ... "OK!"

The Hardware

Only two main components required here:

Coffee Machine

The coffee machine I am using is the Nespresso Expert, made by Breville. This machine has an app for Android and iOS that already lets you do some pretty neat things, like tuning the coffee quantities and scheduling your brew for a specific time. While in reality this is really enough, we can't just let that be.

Raspberry Pi

Really anything with Bluetooth LE that is supported by the fantastic Noble library will work, the most convenient I had on hand was a Raspberry Pi Model 3B+ running Raspbian Lite.

The Software

For the software we're going to build a script that listens for commands on an MQTT topic (triggered from Home Assistant) and then translates that command into the proper series of Bluetooth commands to emulate the phone app.

Fortunately someone has done a lot of the hard work already and there exists a library using a BLE plugin for Cordova. Since we're not writing a phone app, we'll use this as a reference.

The first step is finding the authentication string for your particular machine. This was a bit of a nightmare as it involves traffic capturing your Bluetooth traffic and inspecting it in Wireshark. Try as I might I could not get the logging to work on my Samsung Galaxy S8 and had to fall back to my old Samsung Galaxy Note 5 to get the HCI log. Anyway, YMMV and I found the linked guide from the previous GitHub link very helpful.

Since we are using Noble for our Bluetooth connection, we need to install the required packages on the Raspberry Pi:

$ sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev

We can also use the Nodesource Debian repos to get the latest arm64 build of Node 8:

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt-get install -y nodejs
1noble.on('discover', function(peripheral) {
2  peripheral.connect(function(error){
3    peripheral.discoverServices(null, function(error, services){
4      let auth = services.filter(service => service.uuid == authenticationService)[0];
5      let coffee = services.filter(service => service.uuid == coffeeService)[0];
6
7      auth.discoverCharacteristics(null, function(error, characteristics){
8        let authThing = characteristics.filter(
9           characteristic => characteristic.uuid === authenticationCharacteristic
10           )[0];
11        
12        coffee.discoverCharacteristics(null, function(error, characteristics){
13          let coffeeThing = characteristics.filter(
14             characteristic => characteristic.uuid === coffeeCharacteristic
15             )[0];
16
17          authData = new Buffer.alloc(8, '8XXXXXXXXXXXXXXX', 'hex');
18          authThing.write(authData, false, function(err){
19            coffeeData = new Buffer.alloc(10, '03050704000000000002', 'hex');
20            coffeeThing.write(coffeeData, false, function(err){
21            });
22          });
23        });
24      });
25    });
26  });
27});

Finally we can add an MQTT switch into Home Assistant in configuration.yaml to trigger a coffee of our desire to be made:

1switch:
2  - platform: mqtt
3    name: Coffee Machine
4    icon: mdi:coffee
5    command_topic: coffee/command
6    payload_on: 'hot americano'
7    state_topic: coffee/state
8    availability_topic: coffee/availability