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

Hi devWaves,

Thanks for the reply.
I only have switchbot curtain rods v2 with firmware 4.6
Yes already have a dedicated mqtt user and password.

Power supply is good: https://www.amazon.co.uk/dp/B01MXXOQTE/?coliid=I1B69LI6LQ97CD&colid=17RBMQPSFGGK9&psc=1&ref_=lv_ov_lig_dp_it

And the ESP32 I’m using is this one: https://www.amazon.co.uk/gp/product/B071JR9WS9/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Not sure about the debugging thing as all this is pretty new to me. v6.11 worked superbly for me with NimBLE 1.3.7, I’m suspecting that it’s still a NimBLE 1.4.0 problem in my case, Will 7.1 still work ok if I revert to NmBLE 1.3.7?

@evanshaw yes 1.3.7 will still work. the change I made was to not unsubscribe from BLE notification inside the notification method. I dont think 1.4.0 is the issue though as it works fine for me

Do u happen to have a diff brand esp32 to try with? someone else mentioned the “esp32s” giving them issues and they moved to a diff brand and it solved all the problems

these are the main ones I use
ESP-WROOM-32-U (with external antenna)

Wemos D1 Mini (CP2104)

Hi devWaves,

Hope you are well.
So I tried dropping to NimBLE 1.3.7, no change.
Then I tried experimenting with a different board type in the IDE, I went to what I think is quite generic “ESP32 Dev Module” again, no change, I was using “DOIT ESP32 DEVKIT V1” previously.
Not really sure which board type I should be using TBH as there is nothing in the list with WROOM in the description.
Anyway, I decided to upgrade back to NimBLE 1.4.0 and again no change. (I’ve kept it as ESP32 Dev Module for now)

Now for the weird part, after the failures I thought I’d switch on the debugging via the Arduino IDE, by setting the line you mentioned :-

static const bool printSerialOutputForDebugging = false;

to true.

And blimey, after setting up the Arduino Serial Monitor with that set, I think I’m seeing the Quantum Wave Affect, where when you monitor something, it does as expected. It’s not crashed since the serial monitor has been on. :crazy_face:

P.S. The chip on the board itself says “ESP-WROOM-32 211-161007”

In that case, my only guess would be the power supply. If u have it plugged into a PC and it isnt crashing but while plugged into the usb charger it does

any slight power fluctuation could mess things up. Even if the power supply is working

If u have an old 1amp cheapo USB power supply I would suggest trying that instead of the fancy one you have

Thanks devWaves will definitely try that and let you know the result.

Hey, I feel a bit bad writing this, as the work done by @devWaves controlles my switchbot flawlesly for months now (big thank you!). But ever since I switched from the back-then wonky native HA switchbot integration to the mqtt bridge, it bothers me that the ESP32 used for it does nothing else. It’s located in my hifi rack, as there is the closest power source to the heating switch I stuck the SB to, so there would be tons of potential for further usecases with the unused pins (audio source switch, physical volume control for the ancient amp, …)
Now we have bluetooth proxy support in esphome, and I’m considering trying out to flash the same esp32 with esphome and to give the internal SB integration another try. It does still have the weird illogical way to provide controls (SwitchBot momentary mode, also entity missing?) though.
Anyone from within this thread who already tried to switch back and has a few days/weeks of experience with the setup?
I know, I could just leave the mqtt bridge as it is, and add yet another esp to the hifirack, but it kind of feels redundant.
Cheers!

I switched back when active bluetooth control using proxies became available. I’m back on this ESP32 solution however. The native integration worked for a day before becoming unavailable again. Even the one Switchbot device I never used the ESP32 bridge for as it always worked fine (humidity sensor) started to have connection issues.

Having said that, I think it may be fixed in the latest version. As my Humidity sensor has become stable again. So I may give it another try.

As I currently just to test have both integrations running I’ve tested on occasion if the native one keeps responding and it does. But not as smooth as the ESP32 bridge. For example if I close a curtain and then stop midway, the native version won’t show the open action and lists the curtain as ‘opening’ for a good half a minute or something. While with the ESP32 bridge I can just close, stop, open right away.

1 Like

hey @Lakini. Don’t feel bad, use whatever solution you feel best suits your needs. The esphome bluetooth proxy stuff is really cool but I personally won’t be moving to it anytime soon if ever for multiple reasons

  1. My code supports meshing esp32s for contact/motion/meters . Meshing esp32s provides lightning fast response time comparable to zigbee/zwave. My motion sensors and contacts sensors have basically zero delay

  2. my mesh code handles the situations where duplicate data can be received where one esp32 receives the data faster than the other. Without that you could get a door that goes open, closed, open, closed when it was only opened,closed once in reality

3.Active scanning is turned on only when needed/desired in favor of passive scanning. This saves battery on switchbot devices. From my knowledge the esphome stuff has active scanning on all the time

  1. My esp32 code only relies on MQTT and does not rely on other integrations that could receive breaking changes. If u have a working setup feel free to leave it that way

  2. I am not sure if the switchbot integration handles when a switchbot devices is busy by reading the response the devices sends back. my code does. You can test this by putting a hold value on a bot, and during that hold time try to call the bot from the switchbot integration. The switchbot will accept the command but if busy will just return a busy response. My code will retry on busy

If you only have like one bot or curtain etc I can see how using an esp32 just for that can be “wasteful” but the code can accomodate using other sensors and the esp32s pins etc, it just isnt as straight forward as the esphome stuff. Just requires combining some arduino examples into the code. I provided some examples in the forum somewhere

but ya the esphome bluetooth proxy stuff is cool. I only wrote my code because the other options sucked at the time. If I had non switchbot BLE devices I would consider using it

3 Likes

Hi!

Thanks for this! It sounds very promising, but for me, this is very unstable. It takes ages for the commands to go through, and my curtain bots keep becoming unavailable most of the time. The board is right next to the curtains, and my wifi strength is solid. Could it be because of the boards I am using? I’m using this board: https://www.amazon.nl/-/en/gp/product/B07Z83H831

Are there any recommended boards out there I can try with?

Thanks

these are the boards I use and they have been running 24/7 for months. No issues, commands are close to instantaneous SwitchBot bot/curtain/meter/contact/motion MQTT ESP32 bridge - Local control - #790 by devWaves

Thanks! There seem to be a lot of variants there. Will any variant work? I read on your github page that you prefer the WROOM-32U?

I’m using these ones: AZDelivery ESP32 NodeMCU
and find them rocksolid and stable.

Thanks, I’m using these ones from the same brand, and it seems 2 out of the 3 I ordered are unstable. https://www.amazon.nl/gp/product/B07Z83H831

That’s really odd. Have you contacted the vendor AZDelivery?

Yes, but I will probably be returning these. Good thing I bought from Amazon. I have in the mean time placed an order on Aliexpress for the recommended board (WROOM-32U). I will return all 3 AZ-Delivery boards once I get my Aliexpress order.

Hi! Anyone here experienced contact sensor sometimes missed the IN and the OUT is not functioning at all?

hey @williever do u have it configured in the switchbot app? For ‘out’ to work on motion then contact, you need to set it up like that in the switchbot app. By default it assume you press the button then exit

Yes, I have configured it by setting up to motion instead of pressing the button. Right now I noticed on the logs saying " * Received message on illegal discovery topic ‘homeassistant/binary_sensor/John’s_Door_Contact_Sensor/bincontact/config’. The topic contains not allowed characters. For more information see MQTT Discovery - Home Assistant"