logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 75 0
ADVERTISEMENT
📢 Słuchaj:
  • 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 11966 posts with rating 9996, helped 572 times. Been with us since 2014 year.
  • ADVERTISEMENT
📢 Słuchaj:
ADVERTISEMENT