Coffee machine (Moccamaster) Z-wave hack

Shelly stuff is very good and very affordable, good find on this one!

Nice work Maurice!
I would love to do something similar, but without changing the original buttons. I actually use the extra heater when brewing full pots sometimes.
Any advice on how I could be doing this without using a push-button?

Sorry for the really late reply to your question.
Some of these power switches can interoperate with different kinds of switches.
The Fibaro that I used for example, supports both momentary switches (push-button) and toggle switches (rocker). In the switch configuration you can change the mode of operation, to make a simple on/off switch work.
I didn’t make use of this, simply to make the switch more predictable. I push on the left side of the switch to turn on the device. With a rocker switch, you have to toggle the switch to flip the power state, and that might be either pushing it left or right.

On thing to beware of, is when the rocker switch has a light built-in. If I remember correctly, the switch position is hard-linked to the light state. Therefore, it wouldn’t be possible to turn on the button light when it’s in the OFF position and you would enable the smart switch remotely. An alternative would be to use a rocker switch without a light in it, and install an extra status light that you power from the smart switch. I would go for a round light, since those are most easy to build in by drilling a round hole in the enclosure.

Hope these hints help!

Regards,
Maurice

I modded my old Moccamaster as well. Thanks for the inspiration!

Instead of a Fibaro, I used a Sonoff Dual R3 to provide the smarts. The Sonoff has an ESP32, so I flashed it with ESPHome. That opened up clever programming possibilities, more of which later.

I replaced the two on/off switches with the very same momentary switches that you’re using. For indicator lights, I used two round neon ones, also per your suggestion. I drilled holes for the lights left and right of the switches.

Like the Fibaro, the Sonoff Dual R3 measures power. Technivorm says we should use the extra heat switch to pre-heat the glass jug while brewing, and keep it on if more than 5 cups are being brewed. I followed their advice to the letter.

When the Moccamaster is turned on and the Sonoff determines from the power consumption (>100W) that the coffee maker is indeed brewing, it automagically applies extra heat. It also measures the time taken to empty the water tank by monitoring the power consumption. If it’s 180 seconds or more, my electronic barista deduces that more than 5 cups were brewed, so the extra heat can stay on. All this can be overridden by pressing the switches. In fact, the extra heat should be turned off manually when 5 cups or less are left in the jug. After all, the Sonoff can measure power consumption, but not coffee consumption.

I also made it so that there’s an auto power-off after 40 minutes. That’s in accordance with EU directive Nr. 801/2013 (EU critics can come up with a more palatable excuse). Helpfully, HASS sends a notification to my phone to remind me not to waste the coffee still left in the pot. Likewise, there’s a phone reminder when brewing is done.

It was an enjoyable project, but what’s best, it’s actually useful! It saves squirrels and pretty trees, too!


1 Like

+1 for the liberal use of Wago 221’s! :slight_smile:

Power sensing, auto-off and reminders sound like great added value.

Thanks. Gotta use all them Wagos, because the wiring got more complicated with two momentary switches and two indicator lights in the picture.

I used velcro tape to stick the Wagos and the Sonoff to the aluminium frame. It’s not a good idea to let any of them rest on the bottom plate, because any coffee that drips onto the hotplate can leak inside and cause havoc. Technivorm would do well to fix this – if they haven’t already.

Nicely done @epollari !

Cool idea to have the high power consumption time determine the number of cups :smiley: I only use it for signalling “coffee is ready” (which is 30 seconds after the power drops down, by which time the filter dripping is ready).

Auto power-off is something I do too. My home assistant sends me a telegram message to notify me about coffee getting lost when I don’t act quickly. Also a nice trigger for knowing that I have been concentrating too much on coding and too little on drinking coffee.

Thanks. Your pioneering work benefited me greatly.

Even if you don’t use extra heat, you may want to count the cups to predict how long it takes for the coffee to drip into the pot. Obviously, it varies according to the number of cups. The filter basket on mine lacks the automatic drip-stop and patience isn’t my strong point, so I’m forever cleaning the hotplate. There must be a simple formula for predicting the exact drip time. I guess I’ll have to time it with various loads.

Why aren’t you using HA Companion App notifications instead of Telegram?

I implemented the Telegram notification before the companion app was supporting app notifications IIRC. One of these days, I will be re-implementing my whole setup, and then the companion app is definitely going to be my weapon of choice.

There are some nice perks to the HA Companion app. I don’t need to be reminded that an auto-off occurred yesterday, so I’ve set the notification to expire and hence, disappear after a while. Also, I’ve included a shortcut to the coffee maker’s virtual on/off switch, so it’s extra easy to give myself extra time to finish the pot.

1 Like

Nicely done on the mod! Any chance you could share the esphome config so I (and others) could use it as a base? I’m planning to mod my Moccamaster the same way you did with the sonoff dual r3 :slight_smile:

OK, here goes:

esphome:
  name: mokkamestari
  friendly_name: Mokkamestari (Sonoff DUALR3)
  on_boot:
    - light.turn_on: led_power

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging, but disable logging over serial
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "<censored>"

ota:
  - platform: esphome
    id: my_ota
    password: "<censored>"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Mokkamestari Fallback Hotspot"
    password: !secret wifi_password

captive_portal:

web_server:

globals:
  - id: en_timer_var
    type: bool
    restore_value: no
    initial_value: 'false'

  - id: sec_timer_var
    type: int
    restore_value: no

button:
  - platform: factory_reset
    id: reset_button
    name: "factory reset"

light:
  - platform: status_led
    pin:
      number: GPIO13
      inverted: true
    internal: true
    id: led_power
    name: "status LED"

# BL0939 power sensor UART settings
uart:
  tx_pin: GPIO25
  rx_pin: GPIO26
  baud_rate: 4800
  parity: NONE
  stop_bits: 2

sensor:
  - platform: bl0939
    id: sonoff_power
    update_interval: never
    active_power_1:
      name: "power 1"
      id: power_1
#      internal: true
    active_power_2:
      name: "power 2"
      id: power_2
#      internal: true

  - platform: template
    id: brew_dur
    accuracy_decimals: 0
    name: "Brewing time"

  - platform: template
    id: cups_brewed
    accuracy_decimals: 2
    name: "no. of cups brewed"

interval:
  - interval: 1s
    then:
      - if:
          condition:
            - lambda: 'return id(en_timer_var);'
          then:
            - component.update: sonoff_power
            - lambda: 'id(sec_timer_var) += 1;'

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: true
    name: "button"
    on_click:
      min_length: 10s
      max_length: 30s
      then:
        - light.turn_off: led_power
        - lambda: 'id(reset_button).press();'

  - platform: gpio
    pin:
      number: GPIO32
      mode: INPUT_PULLUP
      inverted: true
    name: "switch 1"
    on_press:
      - switch.toggle: switch_1

  - platform: gpio
    pin:
      number: GPIO33
      mode: INPUT_PULLUP
      inverted: true
    name: "switch 2"
    on_press:
      - if:
          condition:
            - switch.is_on: switch_1
          then:
            - switch.toggle: switch_2

  - platform: template
    id: power_timeout
    name: "power timeout"

  - platform: template
    id: coffee_ready
    name: "coffee ready"

output:
  - platform: gpio
    pin: GPIO27
    id: relay_1

  - platform: gpio
    pin: GPIO14
    id: relay_2
        
switch:
  - platform: output
    name: "relay 1"
    output: relay_1
    id: switch_1
    on_turn_on:
      - script.execute: power_timeout_script
      - script.execute: hotplate_script
    on_turn_off:
      - switch.turn_off: switch_2
      - script.stop: hotplate_script
      - script.stop: power_timeout_script
      - lambda: 'id(coffee_ready).publish_state(false);'

  - platform: output
    name: "relay 2"
    output: relay_2
    id: switch_2

script:
  - id: power_timeout_script
    mode: restart
    then:
      - lambda: 'id(power_timeout).publish_state(false);'
      - delay: 40min
      - lambda: 'id(power_timeout).publish_state(true);'
      - switch.turn_off: switch_1

  - id: hotplate_script
    mode: restart
    then:
      - lambda: 'id(en_timer_var) = true;'
      - delay: 2s
      - if:
          condition:
            - lambda: 'return id(power_1).state > 100;'
          then:
            - switch.turn_on: switch_2
            - lambda: 'id(sec_timer_var) = 0;'
            - delay: 2s
            - wait_until:
                condition:
                  - lambda: 'return id(power_1).state < 100;'
                timeout: 200s
            - if:
                condition:
                  - lambda: 'return id(sec_timer_var) < 180;'
                then:
                  - switch.turn_off: switch_2
#           - delay: lambda: 'return (id(sec_timer_var) * 2);'
            - lambda: 'id(brew_dur).publish_state(id(sec_timer_var));'
            - lambda: 'id(cups_brewed).publish_state(id(sec_timer_var)/35);'
            - lambda: 'id(coffee_ready).publish_state(true);'
      - lambda: 'id(en_timer_var) = false;'

There are still some deficiencies in the code. I still haven’t bothered with a formula to estimate drip time, so once boiling is finished, Home Assistant optimistically announces that coffee is ready, while it’s actually still dripping. Also, I need to devise something to prevent these annoucements when I manually turn power back on after an auto-off (or have forgotten to fill the water tank the previous night).

Pidä hauskaa!

I stood next to my MoccaMaster a few brewing rounds, and for me the max dripping time after finishing boiling was 30 seconds. So that’s what I have hard-coded as the wait time before announcing “Coffee is ready!” on my telegram :slight_smile:

There wasn’t much difference between brewing only a bit and brewing a full pot (I think I saw 15-20 seconds for a non-full pot), so I didn’t bother with getting a formula that took the cooking time into account or so. I can live with 15 seconds late announcements.

Are you saying I suffered ten years of studying wiskunde for nothing? I still curse Simon Stevin for translating all mathematical terms into Dutch. Even we Finns, whose language is out of this world, stick with the Greek and Latin terms.

Hey, nobody is stopping you from gaining 5 seconds on the coffee intake initiation time. It is clear that this is a noble and praise-worthy goal!

Sorry for wiskunde, but feel free to name it mathematica.

As a long-time Phorum user (about 2003 to 2014-ish) its a nice surprise to recognise your name here! The site is no longer ran by me and has switched to Xenforo but is still really active.

I just converted our coffee brewer with great inspiration from your github instructions, but used a Shelly relay instead (A PM2 because that was what i had available).

The button cutouts in the metal was not the right size for the switches so I had to modify the plastic surroundings instead to make it fit but otherwise it was straight forward.

If anyone uses a Shelly relay for this, remember to set it to OFF as default after power outage, and Auto Off after a suitable amount of time.

The PM2 relay has one more switch and output, so you could get creative…

Ha, nice to see a Phorum user “in the wild” :smiley:

The modification is looking good.
Nice classic color machine you got there :+1: