logo elektroda
logo elektroda
X
logo elektroda

How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

p.kaczmarek2 633 4
ADVERTISEMENT
📢 Listen (AI):
  • How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Sonoff R5 Scene Controller is a battery-powered 6-gang remote wall switch featuring three different button events (click, double or hold). It is usually paired with Sonoff Gateway, but here we will show you how you can pair it with ESP32 Tasmota device and use it with Home Assistant to create custom automations.
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Sonoff R5 Scene Controller features physical button (tactile switches), so it may be preferred by some users over the solutions based on touch buttons.
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    So, I assume that you have at least one R5 switch. You don't need the Sonoff gateway for this guide.
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Just make sure that your R5 has required batteries, as it runs on two CR2032.
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Then, you will need ESP32 device. Even a tiny board like ESP32-S3 Super Mini USB Type-C will work well.
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Flash it with Tasmota Mi32-bluetooth version (file ends with *-mi32.bin) - https://github.com/Jason2866/Tasmota-specials/tree/firmware/firmware/tasmota32/other
    Choose Tasmota matching your ESP - there are multiple ESP32 versions, C3, S3, etc. Use esptool or Tasmota online installer, or any other flasher of your choice.

    Once Tasmota is running and connected to your WiFi, run in Tasmota console:
    
    SetOption115 1
    

    This will enable BLE. Then, in Tasmota Berry scripting console, paste this to auto load scripts:
    
    code is shown below as image and also present in attachment - removed due to spam filter
    

    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    This will fetch required scripts from Github. Remember, it requires internet access!
    Check the console output and once completed under Manage File system check if the needed files are present:
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Click on create and edit new file, name it autoexec.be and paste this line in:
    
    code is shown below as image and also present in attachment - removed due to spam filter
    

    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Device should restart and you will get a new button on tasmota device home page:
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Now click a button on your Sonoff device it should appear above and click Save Device:
    Screenshot showing the MQTT integration setup in Home Assistant with configuration fields filled for a Sonoff R5 device.
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Once device is saved if you click on the eWeLink Remote button you can set up Alias name which will be important once you start integration into HA.

    Name the device something recognizable (Sonoff R5 in my case):
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Configure MQTT with the data of your choosing, just like you usually do with Tasmota:
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Device will reboot and connect to your HA, or should say MQTT running on HA.

    Go back to tasmota console and type this in:
    
    EweTopicMode 3 %prefix%/remote/%alias%/%type%
    

    Now we can test out HA MQTT setup, go into MQTT and click configure, under Listen to topic type:
    
    /tele/remote/#
    

    and start listening, press a button on your device, and you should see your device come up:
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    Each button event (click, double click or hold) is published via ESP32 to Home Assistant.

    Almost there, go back in your browser and while still in MQTT, click on the 3 dots on the side of core-mosquito integration entry and select Add MQTT Device.

    Name your device, give it a model and configuration URL (http://<tasmota_device_IP>)
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    On the next screen Type of entity should be Binary sensor and entity name you chose for yourself:
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    On the next screen leave the device class empty, you can change this later if you need to.

    Click next and now we are configuring MQTT specific data. State topic should be:
    
    tele/remote/<your_device_name>/<model>
    

    Value template field should contain this string:
    
    {% if value_json.Button1.Action == 'single' %}ON{% else %}OFF{% endif %}
    

    Payload for on and off should remain the same, click on advanced settings and for OFF delay type in 1, leave expire after blank:
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    We are done, finish the wizard and a new Sonoff R5 entry should appear, click on 1 device under it’s name and test:
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?
    The same approach can be used for other buttons, just use names like Button2, Button3, etc. Similarly, you can use event names like "double" or "hold".

    The same way can be used to connect multiple R5 buttons to single ESP, just set different aliases:
    Screenshot of MQTT integration setup for Sonoff R5 in Home Assistant, showing state topic and value template settings.

    That's how you can connect multiple R5 buttons to Home Assistant via ESP32. Of course, you can also use any other MQTT server and just process published data there, even with Node-Red. For more information about eWeLink Tasmota support, see Flobul/Tasmota-eWeLinkRemote readme:
    https://github.com/Flobul/Tasmota-eWeLinkRemote?tab=readme-ov-file#installation
    Full credit goes to Flobul, you can also check his repository for other supported devices like dimmers, etc. Also special thanks to @DeDaMrAz for testing, photos.

    That's all for now, but in the next part we may try to connect other devices to our gateway. Let us know if you've found this guide useful - do you have any experience with using ESP32 as BT gateway? Feel free to share.

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 12106 posts with rating 10102, helped 579 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • #2 21591709
    DeDaMrAz
    Level 20  
    In case you want to publish and see data from the sensors this build is designed for - Mi thermostats use a rule, in tasmota console type:

    Rule1 on System#Boot do RuleTimer1 10 endon on Rules#Timer=1 do MI32Option2 1 endon

    activate it with

    rule 1 1

    and reboot the device.

    also to enable ESP32 internal temperature showing both in the tasmoat page and publishing it via MQTT in tasmota terminal type:

    setoption146 1

    More info on how to add these sensor to HA will follow soon, but the principle is basically similar.
  • ADVERTISEMENT
  • #3 21591835
    divadiow
    Level 34  
    I have no eWeLink bluetooth devices but I thought I'd play along as far as I could go.

    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

    I did find I already had autoxcec.be from factory,

    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

    Code: Text
    Log in, to see the code


    but no problem, create and edit anyway
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

    and that's it. 🤣

    Added after 5 [hours] 39 [minutes]:

    divadiow wrote:
    I have no eWeLink bluetooth devices


    but I do have a collection of TH05F/THB3 Tuya bluetooth temp/hum devices
    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

    Just converted one to BTHome opensource firmware https://github.com/pvvx/THB2 and here she is in Mi Tasmota

    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

    How to connect Sonoff R5 Bluetooth Remote to Home Assitant via ESP32 Tasmota Bluetooth Gateway?

    maybe the conversion steps of these types of devices needs its own thread.

    thanks @DeDaMrAz for bringing Tasmota Mi ESP32 to my attention
  • ADVERTISEMENT
  • #4 21592152
    p.kaczmarek2
    Moderator Smart Home
    Sure, that also would be an interesting presentation!

    I also wonder, would Tasmota BT gate also allow us to pair those cheap Tuya Bluetooth-only lamps? You know, like the ones we order with WiFi modules inside, but Bluetooth-only version.
    Here is a sample teardown of such device: https://www.elektroda.com/rtvforum/topic4105891.html
    Helpful post? Buy me a coffee.
  • #5 21592357
    divadiow
    Level 34  
    I wonder 🤔

    This is my first Bluetooth mini-adventure. I have a Tuya Moes breaker with BT2S (TLSR8250F512ET32) module. I also wonder if there are options for this. 🤔🤔🤔
📢 Listen (AI):
ADVERTISEMENT