Skip to content

How-to: Add WiFi to your coffee machine, part 3

I added WiFi to my coffee machine, and I control it with my home automation server Domoticz, this part is about the integration with Domoticz.

If you haven’t already, check out part1 and part2, they explain what’s going on ūüôā In this post, we’ll see how to prepare the esp8266, how to create the different devices in Domoticz, and finally how to create a custom component in Dashticz, an alternative interface for Domoticz.


Coffee machine preparation

In order to communicate with the home automation system, we will need two main software components in the WiFi module:

  • a TCP server
    • It¬†¬†will allow the module to receive commands from the use (power, make coffees)
  • a TCP client
    • It¬†will allow the module to send out the machine status at regular intervals

Check out the whole¬†the source code¬†on GitHub here. I won’t go over every line of the code, but let’s check out the most interesting bits:

esp8266 fast startup

In this snippet, I setup a timer that will probe the current status of the WiFi connection, and I will try to get an IP every 500ms until the returned status is “STATION_GOT_IP” (that’s the 5 in the code). Check the different statuses available¬†here. Using a static IP for teh esp8266 greatly improves the startup time.

Send out the machine status


This is the code that tells the home automation server the current status of the machine, the JSON request is formed using the Domoticz JSON API here. You can see that I simply replace the device id and the text with the machine status (on, warning, error or off).

Make me a coffee

This is where the magic happens! if the received message is recognized by the program, the machine is turned on/off, or a coffee is poured. Now that the code is ready on the coffee machine, we need to set everything up on the home automation server.

Add the devices to Domoticz

Now for the Domoticz side, we need to create four devices that together will allow total control of the machine:

  • An input device to get the machine status.
  • Three output devices to power the machine and make large/small coffees.

Get the machine status Domoticz allows you to create virtual devices that you can update/read with JSON, this is what we’ll do here. I did it like that:

  1. Open the Domoticz web interface
  2. Click on the¬†“setup” tab
  3. Click on the¬†“Hardware” menu in the list
  4. Underneath my hardware list,¬†create a new hardware,¬†I put “Coffee machine” as a name
  5. “Dummy” as Type
  6. Click on Add. The new Hardware in the list:domoticzHard
  7. Create a virtual sensor for the newly created hardware (blue button “Create Virtual Sensor” in the hardware line)
  8. Select Text as type. Now we can add it to the dashboard and customize it
  9. Click on the¬†“setup” tab
  10. Click on the¬†“Device” menu in the list. There is the¬†new “Text” sensor¬†sensorText
  11. Click on the green arrow on the right of the sensor, it will ask for a name, I put CoffeeMachineStatus.
  12. Note the Idx number for this device, for me it was 8¬†but it will very likely be different for somebody else. It needs to match the number in the LUA file “TCPService.lua”.

Tadaa! The machine status is now visible in Domoticz, under the “Utility” tab.

Add switches into Domoticz

Now that we got the status of the machine, we need to setup the three buttons to power the machine and make coffees. For that I created three similar switches:

  1. Go to switches tab
  2. Manual Light/Switch
  3. Hardware: Coffee machine
  4. Device name: CoffeeMachine – SmallCoffee – LargeCoffee
  5. The other options doesn’t matter.

Next step is to create and link LUA scripts to each of these switches, which will send out the commands to the machine.

Connect the switches 

By putting a LUA script in <Domoticz folder>/scripts/lua, using the name script_device_<daviceName>/lua/, the script will be executed everytime you click on the device from the web interface. this is the script I use to turn the machine on or off:


It is pretty straight forward, I use the linux tool “nc” to automatically connect to the TCPserver on (which is the coffee machine) and send the “turn_off” or “turn_on” command. The nc command syntax is the following:


The two other scripts (to pour coffees) are on the GitHub repo. Their only difference is that they send different string to the machine. At this point, I have all the devices at the same place, I am able to turn the machine on and off, and check the status. Unfortunately this is very unpractical, and takes way too much room.



The next step is to merge all these information into a nice looking single bloc.

Make it nice

I use an alternative dashboard for Domoticz, it looks better and is easier to customize. It is called Dashticz and is available here. My fork with the coffee machine bloc is available here I never worked with pure JavaScript before, so modifying the existing code was quite slow, but I think it turned out nice, after working on it this afternoon I got a bloc that looks like this and is fully functional:


The icon on the right tells you the current state of the machine (and controls the machine power when clicked), and you can pour yourself a cup a large/small cup of coffee with the icons underneath. Check the video! Thank you for reading!

Published inUncategorized


  1. Ark Ark

    I have an intelia saeco too, different model and I was considering this hack, however, mine does clean the pipes with water when turned on and turned off so I can’t really leave a cup below and have a coffee in the morning.
    Does yours do the same? or did you find a way of working around it?

    • Benoit Dumas Benoit Dumas

      Hi there,

      My machine does the same, rinses the pipes during startup and shutdown.
      The way I solved this was to mash the “stop” button until the screen turns green. This stops the rinsing before any water could drop down the cup. You can check out the code in part 2.


Leave a Reply

Your email address will not be published. Required fields are marked *