Skip to content

ESP32 guide

Michael Arthur edited this page Oct 30, 2024 · 1 revision

ESP32 BLE Active Proxy for Mammotion Lawn Mower

Introduction

This guide outlines the process of creating an ESP32-based Bluetooth Low Energy (BLE) active proxy for Mammotion lawn mowers (such as Yuka or Luba models) using ESPHome. This proxy acts as an intermediary between your lawn mower and Home Assistant, extending the mower's range and providing a more stable connection to your home automation system.

Note

You must use esp-idf as the framework and may need to initially flash it from a computer to get the partitions correct.

Hardware Requirements

  • ESP32 development board (e.g., ESP32-WROOM-32)
  • USB cable for power and programming

Software Requirements

  • ESPHome
  • Home Assistant

Configuration

Basic ESPHome Setup

Create a new file named mammotion_proxy.yaml with the following configuration:

substitutions:
  name: bluetooth-proxy
  friendly_name: Bluetooth Proxy
packages:
  esphome.bluetooth-proxy: github://esphome/firmware/bluetooth-proxy/esp32-generic.yaml@main
esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: false

esp32:
  board: firebeetle32
  framework:
    type: esp-idf


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

api:
  encryption:
    key: {YOUR KEY}
logger:
ota:
  platform: esphome
improv_serial:

    #esp32_ble_tracker:
    # scan_parameters:
    # We currently use the defaults to ensure Bluetooth
    # can co-exist with WiFi In the future we may be able to
    # enable the built-in coexistence logic in ESP-IDF
    #  active: false

bluetooth_proxy:
  active: true

button:
  - platform: safe_mode
    name: Safe Mode Boot
    entity_category: diagnostic
    
  - platform: restart
    name: "Reboot Proxy"

# Used for debugging issues
# external_components:
#   - source: github://esphome/esphome@bluetooth-proxy-log-device-requests
#     components: bluetooth_proxy
#     refresh: 0s

BLE Configuration

Add the following BLE configuration to enable the ESP32 to act as a proxy only for your lawn mower:

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

ble_client:
  - mac_address: XX:XX:XX:XX:XX:XX  # Replace with your lawn mower's MAC address
    id: mower_ble_client

    on_connect:
      then:
        - logger.log: "Connected to Mammotion Lawn Mower"

    on_disconnect:
      then:
        - logger.log: "Disconnected from Mammotion Lawn Mower"

    services:
      - uuid: '0000ffff-0000-1000-8000-00805f9b34fb'

# Add the restart button
button:
  - platform: restart
    name: "Reboot Mammotion Proxy"

Usage

  1. Flash the ESP32 with the ESPHome configuration.
  2. Position the ESP32 within range of both your Wi-Fi network and the Mammotion lawn mower.
  3. The ESP32 will automatically connect to your Wi-Fi network and start scanning for the lawn mower.
  4. Once connected you can add your mower in Home Assistant.

Troubleshooting

  • If the ESP32 fails to connect to Wi-Fi, it will create a fallback hotspot. Connect to this hotspot to reconfigure the Wi-Fi settings.
  • Ensure the MAC address in the configuration matches your lawn mower's MAC address.
  • Check the ESPHome logs for any connection issues or errors.

Security Considerations

  • Use strong passwords for Wi-Fi and OTA updates.
  • Keep your ESP32 firmware up to date.
  • Consider using a separate VLAN for your IoT devices, including this proxy.

Future Improvements

  • Implement more detailed status reporting and control options specific to your Mammotion lawn mower model.
  • Add power management features to optimize battery life if running on battery power.
  • Implement error handling and automatic reconnection strategies for improved reliability.

By following this guide, you should have a functional ESP32 BLE active proxy for your Mammotion lawn mower, enabling seamless integration with your Home Assistant setup.