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

that bug has been there for awhile. just knocking off the bugs as I see them. Hopefully squashed them all now, not seeing any mqtt boot calls anymore. If it cant connect you should see a “status”:“errorConnect” after it tries X times

v1.2 includes a minor reconnect stability change

you may not notice a difference if it was working fine with v1.1, but it might help bots that are further and have issues connecting

Thank you deWaves for your amazing work.

I’m still on v1.0 but only operating a single bot close by… so no issues.
My plan is to import my other 3 bots and 2 curtains over to Mqtt, just finding the time.

I’ll let you know if issues arise once I’m there and on the recent version. :slight_smile:

cheers! :+1:

For anyone looking into improving there Switchbot network with Home assistant, I’m using this esp32 and this perfectly matched container box to keep things tidy. Just need to cut out a hole for the usb power.
Links added from UK Amazon.

Esp32…

Container Box…

Very nice work, devwaves!

All is working fine here, and I am using several switchbot meters to monitor temps and humidity.
The only issue I have is that the temperature is rounded to a centigrade, while switchbot is able to measure tenths of a centigrade. eg: a temp of 18°C is reported, while on the screen I see 18.2°C.
Can this be fixed in the code?

Have you ever used the other local bluetooth options for switchbot? do they display the temp correctly? I don’t have a meter and I basically used the same code

I can take a look though

Hi, thanks for your reply.

I thought that Ron Schaeffers’ solution does report up to a tenth of a centigrade: GitHub - ronschaeffer/sbm2mqtt: Grab SwitchBot Meter data from Bluetooth Low Energy advertisements and publish them to an MQTT topic for use with Home Assistant, etc.
I compared your and his code to extract the temp from the meter and there are a few differences. The solution could be simple, but I first wanted to check with you.

ya I can probably make those changes later tonight

Super! Many thanks.

v1.3 should now display the temperature with one digit after the decimal point

Works like a charm now!

1 Like

Does someone have set it up on Linux?
Because instructions are for Windows.

This is really interesting for me as I look for a local integration for my meters.

And if someone in France have set it up, I am interested in a link to a good ESP32 and, if needed, a case.

Very nice if there is no soldering!

Just by curiosity, why not using ESPHome?

arduino IDE is linux compatible. Arduino - Linux

the solution uses MQTT. switchbots BLE is pretty annoying in terms of making the calls reliable and esphome didnt seem like the solution. my code will connect/send multiple times until it works so you don’t have to

this project started as just a switchbot bot integration because I saw an example on github. I dont own the curtain or meter. luckily the community has benefited from my boredom so I updated it for curtain and meter, lol

MQTT works with all (most) smart hubs etc. I am currently using Homeseer and HomeAssistant in combination with node red/mosquito

it is basically a local switchbot hub for most of their products

I have purchased most esp32 from aliexpress for cheap. amazon also has esp32 but a bit more expensive

1 Like

Moreover, in France, it looks like the ESP32 is not available anymore on Amazon.

Can you give a link please?
I am a professionnal on buying the wrong product on Aliexpress lol.

And thanks a lot for your fast-delay answer!

If I setup your solution I will only have to buy another Broadlink to control a speaker and the hub will become useless :wink:

P.S. If there is a 100% command line solution to build and upload to an ESP it would be great, else I will have to use a virtual machine on Windows to be able to use it.
To be simple it can be installed on Linux but I cannot use the IDE (even install add-on is not possible).

Wemos D1 Mini ESP32 is what I use. but any ESP32 will work. There are many sellers, last time I bought using this link/seller. They sells by 1/5/10 pcs etc

images

ESP8266 does not have bluetooth
you need ESP32

1 Like

@devWaves Do you think it could be possible to implement MQTT discovery to your bridge?

possible, but I had issues with long JSON messages required for auto discovery. They would cause the ESP32 to crash. I found the cause but not the solution. I ended up shortening the JSON payloads

I wasnt sure what to use for the bot auto discovery either when in non-switch mode

1 Like

Hi devWaves. Thank you so much for all the work you have done. Everything is working perfectly. That said, I am wondering whether it’s possible to integrate a light sensor using the same esp32 board. While currently, I have the curtains closing at sunset and opening at sunrise via an automation in
HomeAssistant, I would like to be able to have them close based on the level of light in the room…more so for watching TV. Is that possible?

The curtains should already return a light level value and you shouldnt need to use an external light sensor. But that light level may be for outside

but yes technically the code could be modified to support an external sensor also, wasnt planning on that though because I believe the functionality already exists maybe not for indoor light though

it would only be like 10 lines of code though. I dont have a light sensor to test

Ok thanks…appreciate the quick response and yes, the curtains do have a sensor but outside only as you noted.