SwitchBot bot/curtain/meter/contact/motion MQTT ESP32 bridge - Local control

ya. The esp32 is running BLE at max power, while also running wifi/mqtt and webserver. The developer of the NimBLE library mentioned similar comments. The BLE power can be reduced in the code, if it causes issues

if you only have curtain, bot, and/or meter that shouldnt be a problem though

update all the libraries before reflashing. The BLE lib was recently updated, not sure if there is an outstanding issue with thr BLE library atm

Ok cool, thank you.

The one part i struggle with every time is upgrading the actual vis studio side of things.

I seem to have to start from scratch every time, download the files from GitHub.
delete the existing files “SwitchBot-BLE2MQTT-ESP32 folder” and then make a new project and rebuild the whole thing from scratch with just coping past the config that i saved in notepad

Is there an easier way? any instructions?

Thanks :slight_smile:

yes you need to copy paste your settings from version to version. As long as I didnt add a new variable you can copy paste the variables names etc from your last file

This is my first esp/arduino project and making values configurable through a webpage wasnt really a design plan to avoid issues during development

you can use a program like “Beyond compare” or “winmerge” to compare your last file against the latest version and easily copy your settings over that way

update all the libraries before reflashing.

I’ve never thought about that. Still the same ibraries since this project kicked off. Guess no better time then now.

These are the ones I see that are updatable. No BLE packages. Nevermind, I see it. It’s the last one.

hey @duceduc funny you commented. It seems some BLE Nimble library issues recently came up and were dicussed in an espresense issue

I am trying out the latest NimBLE version now, but those issues probably affected this code also

sounds like issues started after 1.3.3. Might be fixed in 1.3.7?

Yeah ok, if that’s what it is, that’s what it is LOL I just wanted to really make sure there was no other way :slight_smile:

I doubt anyone would be complaining about it mate, you have done such a great job in putting this together so we have local Switchbot.

Really thank you :slight_smile:

I so much want espresense to work. The big hurdle is the esp32 doesn’t have enough memory. Almost always crashes/ reboots.

That’s interesting,

Lewis was saying that its the most bang for your buck presence

I’m using two OG Pi Zeros with Room Assistant. Its not that reliable in switching to the right one though, ive found.

I was hopping that espresense would be a good solution :frowning:

Hello, i have two switchbot bots that i managed to integrate into home assistant using a custom addon that in my opinion works better than the official one.
Unfortunately, Bt range is very poor, so i donwloaded the project and followed the istructions for Visual Studio Code PlatformIO.
I have two Esp2 boards, both from Azdelivery (ESP32 NodeMcu WiFi and D1 Mini Esp32) with CP2102.
I changed Mac addresses and the required settings, the process went smoothly with both boards, and i only got some yellow warnings (forgive me but i’m totally noob with esp32 and Mqtt).
After flashing, in both cases i can get the ipaddress of the board, but i only get a linkquality entity in Home Assistant (i.e. -65 rssi), with no other entity related to my bots (see picture).
I double checked the Mac Addresses and flashed many times the two boards, using different project tasks for the first board (esp32, azdelivery-devkitv4, etc) and Wemos D1_mini_32 for the second board, but i didn’t find a way to get the bot entities.
I didn’t set any password for them.
Am I missing something?

Thank you very much
mqtt_expl

So far, I think this is a great project, but I’m struggling.
Got my first SwitchBot item, which is the SwitchBot Meter Plus.
Below is the area that I put it in for the code, and the Mqtt Explorer information.
I see the switchbot gateway in my MQTT area on my Home Assistant, but not the meter.
Is the Meter Plus not supported? Do I need to put it some place else in the code? The ESP and the Meter are right not to eachother. For reference, the ESP board I’m using is https://www.amazon.com/gp/product/B07QCP2451/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1

image
image

the bots are not being discovered by BLE. not sure why but I can only guess incorrect MAC. Make sure you use “:” inbetween the MAC address, I accidentaly used a “;” once and it will do that

the mqtt settings look correct because you got the wifi rssi entity of the esp32 board. Since you aren’t seeing any messages on homeassistant then the device hasnt been found

Are u placing the esp32 close to at least one of the bots?

Hey so the switchbot meter plus is brand new and there is no specific documentation for it

it may provide slightly different data then the normal meter, I dont know. If so then it may not work without a couple changes

If you want to send me some screenshots of the BLE advertising data using an app called “nRF connect” on your android or iphone I can look at implementing it

Understand. I ended up with the device so I figured I would try.

I’m not entirely sure what you need. I tried to clone, but it didn’t like that so I took a screenshot.
Let me know if there is something else that I can try to provide.


Hello, thank you for your answer.

Actually Mac addressess are correct, i have checked them many times and tried upper and lowercase. Maybe there is a conflict with this integration?

by the way theble_monitor integration doesn’t find any of my switchbots.

I have also tried with arduino IDE instead of Visual Studio Code PlatformIO with the same result (only Linquality, no bots)

Thank you

both those screenshots work, but if u can send a couple and label them that will help alot

I am looking for the part that says “Service Data:”
from screenshot 1, or the the line where it says 0x16 in screenshot 2

the service data will update when the temp or humidity value changes etc.

so take a screenshot and mark the current temp and humidity, then hold the meter in your hand or something to increase the temp. Then take another screenshot and mark the temp and humidity. Rescan in between each screenshot

that integration wont affect this. they are separate

you have “switchbots” and not “magic switchbot” right? because they are different. You use the switchbot app?

if u put the MAC in correctly, and I see the mqtt part works, so then there isnt much else. it should just work if the switchbot battery isnt dead

you can send me some screenshots of your code configs, or send me code

Thank you again.

I have two switchbots, both work with app (seen as Bot 1a and Bot B4) and home assistant custom integration (https://github.com/cagnulein/switchbot_press), but with poor bt range

Battery is new and firmware is 4.9, may I provide other information?

Many thanks

esp32 is close to at least one bot (for now to test)?

send screenshots of your code changes u made, u can omit passwords and wifi names etc

I had an issue with an ESP32 running a PMS5003 and DHT22 that kept losing connection. Oddly enough I have 4 exact same ESP32’s with Exact same setup that were not having that problem. One of which was even at a greater distance from an AP then the one losing connection.

After a bit of google-ing I added the following line under

wifi:
  ssid:
  password:
  power_save_mode: none

for now that seems to have done the trick. on that specific ESP32 module.