Robot Coffee Maker!

I attached a NodeMCU and a servo to my coffee maker so I can turn it on from bed. Or I could integrate it into my alarm system so the lights and coffee maker turn on at the same time when I need to wake up.

OK, so it’s not quite done yet and it’s really kind of a kludge, but I made a lot of progress last night.

I forked this code for MQTT-controlled blinds and adapted it for a servo connected to a Cuisinart Grind & Brew coffee maker. It’s weird because the coffee maker shows up as a light in HA, but I also kludged up my config so it at least appears to make sense. It has a little coffee cup icon and everything.

I have a couple issues in the tracker, if anyone wants to help out with that. Not quite sure what to do. I need the onboard LED to turn off, and I need the servo to not move when it powers up.

Also I need a proper case, and the servo is held on by a Command Strip and some electrical tape. That will only get me so far.

Here’s a video of the thing: https://ia601506.us.archive.org/2/items/RobotCoffeeMaker/Robot%20Coffee%20Maker.ogv

8 Likes

Lol worst video ever in the history of the internet. But on the other hand I like you code and I and going to steal it for my turny on thingy.

Thanks for the code much appreciated.

Yes, it is quite a bad video. I was very tired and without a tripod.

The video was good enough to get the idea. The parts have been ordered and next weekend is going to be my build date.

what is the section called coffee_brightness in the .ino file used for?

Also guessing that out pin 2 is the one controlling the servo. For my servo I got an mg995 servo which I had laying around.

That section is literally there to just make the program not break. Like I said, I adapted this from a blinds program. If you or someone else can make this make sense, you or they receive many thanks from me.

1 Like

This bit helps with twit upon startup. You might need to change value in the Myservo.write(0) to get better results, mine was best with 0.

void setup() {
pinMode(2, OUTPUT);
myservo.write(0);

Config.yaml

  • platform: mqtt
    name: bigwaterheater
    command_topic: “home/kitchen/coffee_payload”
    state_topic: “home/kitchen/coffee_state”
    payload_on: “ON”
    payload_off: “OFF”
    qos: 1
1 Like

here is the newset updated code for 2 servos/switches doing on/off rather tht just simple button pressing, this is good for rocker type switches.

#include <Servo.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>[
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>

#include <PubSubClient.h>


/************ WIFI and MQTT INFORMATION (CHANGE THESE FOR YOUR SETUP) ******************/
#define wifi_ssid "***" //enter your WIFI SSID
#define wifi_password "***" //enter your WIFI Password

#define mqtt_server "192.168.0.**" // Enter your MQTT server adderss or IP. I use my DuckDNS adddress (yourname.duckdns.org) in this field
#define mqtt_user "homeassistant" //enter your MQTT username
#define mqtt_password "********" //enter your password

WiFiClient espClient;
PubSubClient client(espClient);

Servo myservo;
Servo myservo2;



void setup() {
  pinMode(2, OUTPUT);
  myservo.write(25);
  myservo2.write(25);

  Serial.begin(115200);

  setup_wifi();

  client.setServer(mqtt_server, 1883); //CHANGE PORT HERE IF NEEDED
  client.setCallback(callback);

}


void setup_wifi() {

  delay(9);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(wifi_ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(wifi_ssid, wifi_password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;
    String message(p);
    String mytopic(topic);
    if ( mytopic == "home/kitchen/coffee_payload" && message.equals("ON")){  
      myservo.attach(D4);
      delay(500);
      myservo.write(78); 
      client.publish("home/kitchen/coffee_state", "ON");
      delay(500);
      myservo.detach();
      }
    else if (mytopic == "home/kitchen/coffee_payload" && message.equalsIgnoreCase("OFF")){
      myservo.attach(D4);
      delay(500);
      myservo.write(11);  
      client.publish("home/kitchen/coffee_state", "OFF");
      delay(500);
      myservo.detach();
    }
    else if ( mytopic == "home/kitchen/coffee2_payload" && message.equals("ON")){  
      myservo2.attach(D6);
      delay(500);
      myservo2.write(78); 
      client.publish("home/kitchen/coffee2_state", "ON");
      delay(500);
      myservo2.detach();
      }
    else if (mytopic == "home/kitchen/coffee2_payload" && message.equalsIgnoreCase("OFF")){
      myservo2.attach(D6);
      delay(500);
      myservo2.write(21);  
      client.publish("home/kitchen/coffee2_state", "OFF");
      delay(500);
      myservo2.detach();
    }    

}


void loop() {

{

  if (!client.connected()) {
    reconnect();
  }
  client.loop();
}
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
  if (client.connect("ESPBlindstl", mqtt_user, mqtt_password)) {
      Serial.println("connected");

      client.subscribe("home/kitchen/coffee_payload");
      client.publish("home/kitchen/coffee_state", "OFF");
      client.subscribe("home/kitchen/coffee2_payload");
      client.publish("home/kitchen/coffee2_state", "OFF");

    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}
1 Like