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

although as @anon94216691 mentioned the way you pasted the code messes up the comments, I see the error. The inside of allBots needs to have the comments removed and to only include the devices you want. Right now your list is empty because the inside is commented out. Needs to be this for you…

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

Thank you! I’ll fix the code this evening and keep you posted.

It worked! Thank you!
Now i’m testing signal strength and responsiveness…so far so good!

1 Like

Hi devWaves
I received a new product from switchbot today. Looks like they now have a BLE/Wifi LED strip light. I know this is totally different, but was curious if this is something you think that could be controlled using the Matt gateway to BLE.

Below is the link.

SwitchBot Smart LED Strip Lights, 16.4ft RGB WiFi Bluetooth Lights with App Control, Work with Alexa and Google Assistant, 16 Million Colors with Remote Control and Music Sync for Home, Kitchen, TV https://www.amazon.com/dp/B09J8VKBQL/ref=cm_sw_r_apan_glt_i_BG6HM71YCQ3BS8NDA46Z?_encoding=UTF8&psc=1

Based on what I’ve discussed with switchbot, I should be receiving a humidifier here shortly too, but we will see. They seem dead set on sending me everything else first.

hey @Gamerayers . The led strip doesnt have any documentation yet so at the moment it cant really be supported without. I did start looking at implementing the rgbw bulb which has documentation here bulb documentation

… but that isnt done. If the LED strip is similar to the bulb then it might work the same, but I dont know yet. I also dont own one atm

for anyone that has recently updated the switchbot firmware of their standard meter you will need to update to v6.10 of the ESP32 code at least

it sounds like switchbot has updated their firmware of the original meter to closer match the meter plus firmware

thanks @duceduc for noticing and bringing to my attention

1 Like

How this update is done? I’ve never understood Switchbot meter update process.
I have no cloud (no hub), does it mean I fortunately won’t have it?
If no cloud doe not avoid it, is it something we have to confirm before?

the switchbot device firmware updates are only done using the switchbot app. To update a device without a switchbot hub you simply just use your smartphone, turn bluetooth on, and stand close to the device while updating

if you arent having issues, you don’t “need” to update your devices firmwares. Firmware updates may be needed for switchbot hub support, not sure

it is possible that a switchbot firmware update breaks functionality with the esp32 code because the device changes its message format. So be cautious when updating switchbot device firmwares. If you have to, best to do one device first, then test with the esp32

the switchbot documentation is not kept up to date with firmware updates from what I can tell

Using my phone, with it completely in airplane mode minus Bluetooth, I can control the Humidifer.

I can take some screen shots of the nRF if that would help with controlling the different settings.
From what I can tell there is an on/off command, an auto command and 3 speeds. Additionally, a command to turn on/off light and on/off sound, and then an atomization efficiency value from 1 to 100%. Lastly, it monitors the current humidity in the room.

I can also do this for the rgb LED strip light if that would be helpful. I know there is no spec for this yet.

The values I need are the byte arrays that would be sent to the humidifier, LED etc. Which I don’t think you can get from nRF connect app, but I am no pro with it. The data the devices publish over BLE can be reverse engineered in most cases. Thats where the screenshots are good

in the esp32 code you will see these are the byte arrays I use now for the other devices


static byte bArrayPress[] = {0x57, 0x01};
static byte bArrayOn[] = {0x57, 0x01, 0x01};
static byte bArrayOff[] = {0x57, 0x01, 0x02};
static byte bArrayOpen[] =  {0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x00};
static byte bArrayClose[] = {0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x64};
static byte bArrayPause[] = {0x57, 0x0F, 0x45, 0x01, 0x00, 0xFF};
static byte bArrayPos[] =  {0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, NULL};
static byte bArrayGetSettings[] = {0x57, 0x02};
static byte bArrayHoldSecs[] = {0x57, 0x0F, 0x08, NULL };
static byte bArrayBotMode[] = {0x57, 0x03, 0x64, NULL, NULL};

static byte bArrayPressPass[] = {0x57, 0x11, NULL, NULL, NULL, NULL};
static byte bArrayOnPass[] = {0x57, 0x11, NULL , NULL, NULL, NULL, 0x01};
static byte bArrayOffPass[] = {0x57, 0x11, NULL, NULL, NULL, NULL, 0x02};
static byte bArrayGetSettingsPass[] = {0x57, 0x12, NULL, NULL, NULL, NULL};
static byte bArrayHoldSecsPass[] = {0x57, 0x1F, NULL, NULL, NULL, NULL, 0x08, NULL };
//static byte bArrayBotModePass[] = {0x57, 0x13, 0x64, NULL, NULL, NULL, NULL, NULL};     // Other github documentation shows this to be the array for setting mode with password (firmware 4.5, 4.6)
static byte bArrayBotModePass[] = {0x57, 0x13, NULL, NULL, NULL, NULL, 0x64, NULL};       // The proper array to use for setting mode with password (firmware 4.9)

I would need similar for all the humidifier and LED commands.

The commands can most likely be intercepted with a special BLE sniffer, but I dont have one

If lucky the LED commands may be close to the RGBW commands and you can try sending the documented bulb commands to the LED to see if they work.

here is an example of how to send commands with nRF connect

nRF comnect how to send command to BLE device

for the Bulb an example command…

If you want Brightness and RGB you would do… (using 0x12)

[0x57, 0x0F, 0x47, 0x01, 0x12, 0x32, 0xFF, 0x00, 0x00]

if you want just RGB (no brightness) you would do… (using 0x16)

[0x57, 0x0F, 0x47, 0x01, 0x16, 0xFF, 0x00, 0x00]

the bulb commands are documented here bulb commands

For those interested I have a version 7.0 in the works and can be tested here
v7alpha github

it includes a TON of new changes I will see if I can list them all…

  • Reworked how MQTT messages are published to avoid Wifi and BLE overlaps. Big stability improvement
  • Better battery life for all switchbot devices using Passive vs Active scanning if Motion or Contact sensors are used. If you only have bots, meter, curtain then passive scanning cannot be used
  • Fix to ignore blank/empty set messages
  • Fix for curtain position set command. A decimal value is converted to an int
  • Webserver will restart every 30 min
  • New setting: Mesh multiple ESP32s together for better motion/contact performance
  • New setting: Curtain position can move with curtain after a set/control command
  • New setting: Active scan only, if you don’t want the battery improvement
  • New setting: Active scan all the time, if you don’t want the battery improvement and you are also using the switchbot hub/app. For immediate state updates
  • New setting: Passive scan only, if you want to use the ESP32 as a motion/contact only ESP32 that shouldn’t affect battery
  • New setting: Always MQTT update if scanning

I am using undocumented features of the motion/contact sensors to save battery and improve performance for all devices. It works great for me and I am actually surprised how good now… but it is still in development so bear with me

2 Likes

I can see the link quality sensor in HA, subscribed to the “switchbot” topic in the MQTT integration, but I guess I need to write custom MQTT messages for every Switchbot Meter. Does anyone have example Home Assistant yaml to do that?

hey @lepton there is no yaml to write. if the esp32 was setup correctly the devices are auto created in HA. The link quality you are seeing is most likely the esp32 wifi link quality device. So your esp32 is connected to your wifi and mqtt, but maybe your meter device MAC is not configured properly

If youre writing yaml then you are missing something

Integration is so good that I missed them. Great job.

the name of the devices are what you named them in the esp32 code. The default values are meterone, metertwo. Each device has a bunch of entities

MQTT discovery needs to be on in HA for automatic discovery

if you are only seeing one device get created (the esp32 device) then it means the devices arent being detected. possible issues

  1. MACs not configured correctly
  2. devices are too far
  3. Meter firmware is too new for esp32 code version. but the latest esp32 code supports the latest meter firmware

No problem. Glad u got it working. My version 7 update is almost done

Actually, only a single Meter is picked up, instead of about six per device. It’s odd, because some devices are closer, which aren’t being picked up. I put them in a plastic case, but that shouldn’t block the signal that much, right?

u can PM/DM send me your allMeters list and/or code snippet if you want. If it detected one then the esp32 code is compatible, probably just a typo somewhere.

the plastic will affect signal but it shouldnt a ton. But that is why I have an esp32 with external antenna.

good idea to setup the code with all meters around u, but shouldnt be needed. Just good for quick testing

I identified an important mistake (on my side). Is there a way to update these via ssh over wifi (OTA)?

yes, just go to the IP address of the ESP32 in a browser. You can do OTA from there. Create a .bin file from arduino IDE or platformIO and upload the .bin file