Introduction: Controlling “Shelly 1 Mini” Home Automation Relays From an ESP32 Using Encrypted-BLE (BTHome)

This project uses an ESP32 (tested with both a Standard-ESP32[NodeMCU] , and also an ESP32S3 [Waveshare ESP32S3-zero]) to directly turn a “Shelly 1 Mini” Relay on and off using BTHome v2 Encrypted-BLE commands (ie. without needing any internet connection or registration).

It should work with any BLE enabled Shelly Relay, but I was using the "Shelly 1 Mini Gen3” and "Shelly 1 Mini Gen4” (both with Shelly firmware version 1.7.1)

Supplies

(NB. This unit is 110-240Vac powered, so only connect it if your happy working with such voltages.)

In normal operation, this Shelly device itself uses about 0.6W at 240V, but also note that the unit does get warm in use (even when it’s relay is turned off).

Step 1: ESP32 or ESP32s3 Setup

Flash your ESP32/ESP32s3 with the below “ESP32_BLE_Controller_v30Dec25.ino” software. Once it is running note the Bluetooth MAC address and also the set “Encryption Key”, eg.

// Bluetooth MAC is B4:3A:01:01:01:01

// Set Encryption Key to 'AABBCCDDEEFF00112233445566778899' (err=0)...

Step 2: "Shelly 1 Mini” Unit Reset

If necessary, factory-reset the "Shelly 1 Mini" (resets hotspot etc):

  1. Press+Hold the small-button (on back of the Shelly) for 10seconds.

Step 3: • to Add-a-password to the "Shelly-hotspot"

Connect to the "Shelly-hotspot" (Go-to "http://192.168.33.1/")

Select "Settings/Access_Point/Access_Point_settings":

  1. Click on “Password protected network”,
  2. Enter a password
  3. Click "Save settings".

Step 4: Update-Shelly-Firmware

If you want to update the Shelly's firmware (this is optional):

First connect the Shelly to the internet:

  1. Connect to "Shelly-hotspot" (Go-to "http://192.168.33.1/")
  2. Select "Settings/Wi-Fi”, and under “Wi-Fi 1 settings":
  3. Click on “Enable Wi-Fi”
  4. Select/Enter SSID & Password
  5. Click "Save_settings"

(You can delete this again after the below firmware-update.)

Now update the Shelly Firmware:

  1. Under "Settings/Firmware" Click on "Check-for-updates".

Step 5: Turn on BLE

To turn-on the Shelly’s BLE (Bluetooth), goto “Setting/Bluetooth” and enable.

(NB. you do NOT need to enable "RPC" if using BTHome Encrypted BLE.)

Step 6: Setup "Shelly 1 Mini” to Work With Your ESP32

Under “Components” against “Bluetooth (BTHome) devices” click on the “+”:

  1. Click on “Add a device by MAC address” and enter your ESP32’s MAC address
  2. Select “Shelly BLU Button1”, and press “Add” (and wait ~30seconds).

(NB. Do NOT select “Unknown” as you will later be unable to choose “Button Push”).

Step 7: Add the "Encryption Key" to the "Shelly 1 Mini"

Click on the cog-wheel next to your “Shelly BLU Button1"

In the “Encryption key” box enter your encryption-key (eg."AABBCCDDEEFF00112233445566778899")

Then press “Save settings”

Step 8: Create an "Action" on the "Shelly 1 Mini"

Under “Actions” select “Create Action”

  1. Under “Select component” select your “Shelly BLU Button1”
  2. Give your action a name (eg. Sw1”)
  3. Under “Event condition” select “Button push”
  4. At the bottom click on “Add action to execute”:

...select “Toggle Output”

...click on “Save local action”

  1. Finally at the very bottom click “Save”

Step 9: Stop Non-encrypted Devices Controlling the "Shelly 1 Mini"

Finally, in order to stop unencrypted devices (such as www.instructables.com/Controlling-Shelly-Home-Automation-Relays-From-an-) connecting and operating the switch:

  1. Select “Settings/Authentication”
  2. Click “Enable password protected device”
  3. Enter a suitable password
  4. Click on “Save”

NB. this will be the password you need to access the “http://192.168.33.1” webpage (but it also stops the above non-encrypted device access).

Step 10: Result

Now your ESP32 (or ESP32s3) should be toggling the "Shelly 1 Mini" switch on and off every 10 seconds.