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

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.

Here are the screen shots.
First is ambient.



Next is holding it in my hand.



Let me know if there is something additional.

Thanks mate!

Appreciate that.

Can you should me where you have put that in the code? I thought it was only for ESPhome and this was different.

hey @liminal, the changes mentioned only apply to esphome

This code is set to run with WIFI at the default value which is active. I do not have any code to put the wifi into any type of sleep mode

Ok so the service data length of the new meter plus is the same length as the old one, so my guess is the data is the same

…but what is different is the new meter uses a different UUID value. So if you can try the following code change it might make the meter plus work

change this…

 if ((advertisedDevice->isAdvertisingService(NimBLEUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b"))) || isContactDevice(deviceName) || isMotionDevice(deviceName))

to this…

 if ((advertisedDevice->isAdvertisingService(NimBLEUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b"))) || isContactDevice(deviceName) || isMotionDevice(deviceName) || isMeterDevice(deviceName))

You sir are pretty amazing.
That fixed it.
image

1 Like

nice… total guess. Glad it works. I will add the meter plus to the supported devices in the next code release. Thanks for confirming and testing

Hello, both the switchbots and the board are on my desk, very close to wifi router.
This is my configuration

/* Wifi Settings /
static const char
host = “esp32SWB”; // Unique name for ESP32. The name detected by your router and MQTT. If you are using more then 1 ESPs to control different switchbots be sure to use unique hostnames. Host is the MQTT Client name and is used in MQTT topics
static const char* ssid = “my_wlan”; // WIFI SSID
static const char* password = “xxxxxx”; // WIFI Password

/* MQTT Settings /
/
MQTT Client name is set to WIFI host from Wifi Settings*/
static const char* mqtt_host = “192.168.x.xx”; // MQTT Broker server ip
static const char* mqtt_user = “user”; // MQTT Broker username. If empty or NULL, no authentication will be used
static const char* mqtt_pass = “password”; // MQTT Broker password
static const int mqtt_port = 1883; // MQTT Port
static const std::string mqtt_main_topic = “switchbot”; // MQTT main topic

/* Switchbot Bot Settings /
static std::map<std::string, std::string> allBots = {
/
{ “switchbotone”, “DD:A4:B3:0F:10:1A” },
{ “switchbottwo”, “E2:F9:80:15:7F:BA” }*/
};

Thank you again

Is this exactly your config file?
There are a few unclosed comments in there and the Switch Bot Settings is also commented out.
Make sure you start a comment with /* and also end it with */

Please add the config as preformatted text using </>