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

Thx! I’m a few steps closer again :smiley:

I’ve made all changes to the code, except for one topic:

static std::string mqtt_main_topic = ‘‘switchbot’’; // MQTT main topic
Where can i find this ‘‘topic name’’?

The other code for the bots may remain or should they be removed?
(I only have two switchbot Curtain devices paired)

After that I, upload the code to the board and plug it in with 5v usb?
am I correct when I say that HA will recognize the switchbot curtain instantly?
Or do I need to add other things to HA?

Thank you very much in advance!

mqtt topic is whatever you want it to be. default works fine

yep the rest leave as is. only edit the allCurtains list

you just need mqtt setup in HA with mqtt discovery enabled (It is on by default if u didnt disable it)

when the esp32 boots up it sends the HA mqtt discovery messages for HA to auto create devices. You just need to add to dashboard after that

This is a very cool project! I think I am very close to getting it to work. I’ve managed to get a curtainbot set up with my esp32, however, I cant control it all. I’ve tried as many different mqtt commands as I can think of, but I still can’t get the curtainbot to do anything. By looking at my mqtt explorer can you tell me exactly what the command would be for open or close?

in the attributes the rssi = -84 which is not very good signal. place the esp32 closer to the curtains

if u are manually using mqtt commands an open command would be this for you…

topic

switchbot/esp32/curtain/curtainone/set

payload

OPEN

…but with HA you dont need to manually use MQTT like that. With HA MQTT discovery and auto device creation you will get curtain devices that get automatically created for you in HA

reboot the esp32, wait a bit then check your devices in HA. you should see a curtainone device automatically show up, no need to mess with MQTT commands

I actually just found the autodiscovery entities soon after i posted this, ha. It works great! Very cool stuff, man. Just to confirm, we need to set up/calibrate the curtains with the switchbot app correct?

ya u need the switchbot app to initially calibrate (for curtain) and get mac address and set password (for bot)

Thank you for your support!

I managed to set up the esp32.
when I look at the logs of my mosquito broker add-on, I see the esp32 connected.

However, I don’t see any new devices detected.
I have the default settings of the add-on and when I go to integrations, the mqtt setting has auto detect on.

any idea what the problem could be?

i feel i’m getting close

thanks in advance!

how far away is the esp32 from your curtain? devices wont get created if the switchbot isnt detected. if you dont have a plug close by to the curtain you can test by plugging the esp32 into a usb battery so u can get it close to the curtain

send some examples of what you see in mqtt logs.

there are 2 LEDs on the esp32, the power LED (always on) and the other LED. When the esp32 boots up you should see the other LED turn on when MQTT connects. The light will stay on until all devices are found then it turns off. if the light stays on, it cant find the devices or there is a typo in your mac addresses. the further the switchbot is from the esp32, the longer the LED will stay on during the boot scan.

make sure you only have one mac address in the allCurtains list. If there are mac addresses in the other lists, the ESP32 will continue to search for switchbots that arent near you

make sure you pre calibrate and setup the curtain using the switchbot app first before you using this solution. after that you dont need the app anymore

Check: I put the device in a plug next to the curtain

Check, I see the blue light and then it goes out.

Check: I have one MAC address in the list.

Check: the curtains are up and running with the app.

I also try Mqtt explorer: and I get this:
982C9C09-F102-47B7-8E83-4952E0623596_4_5005_c

I assume the esp32 is not detecting the curtains? so I need to go back to the .ino file in Arduino IDE?

make sure no spaces or special characters are in the names you use

look at this post in this thread, you should see that (mostly. the control topic is incorrect)

ya u probably need to edit the code again

I got it working and very happy with the solution!
I want to improve coverage for my 13 ground floor curtains and install a second ESP32.
Question
Can I have all 13 curtains in the Code of both ESP32s or should I spread (split) them over both of them?

if you have multiple esp32s you can use the same mac on th esp32s BUT you need to ensure they create different devices in HA and the MQTT topics are different. so you would need duplicate devices per esp32.

this is because you dont want a control command to be received by 2+ esp32 and sent 2+ times

best solution is to only use a MAC once over all the esp32s and place the esp32 as close as possible to those MAC devices

for meters you could probably use the same MAC multiple times because it only receives data, it doesnt send/connect to meters

I’ll try it next weekend. Thanks for the quick reply.

1 Like

Thank you very much for your support and time.
I managed to get them in HA!

(the problem was indeed with the code of the curtain)

This makes my day!

I am testing a version 6Alpha which includes support for switchbot contact sensors and switchbot motion sensors

github branch for testing motion and contact sensor

I will merge this into the main branch after testing etc

I’ve managed to get a simple switchbot set up with my esp32cam, however, I am not able to control it all. I’ve tried as many different mqtt commands as I can think of, but I still can’t get the switchbot to do anything. TBH, I am new to MQTT, however, by looking at my mqtt explorer:

Can you tell me exactly what the command would be for open or close?

Aufnahme4

I’m not able to find the device in HA due to autodiscovery.

with your mqtt topics it is this…

switchbot/esp32_switchbot_magnificas/curtain/curtainone/set

payload

OPEN

this is for switchbot curtain, and assuming you called it ‘curtainone’ because you didnt post the name you used

1 Like

I have found the issue. The definition which device to use was uncommented.

I have just released version v6.0 for switchbot motion sensor and switchbot contact sensor support

Notes:

  • If you only have bots/curtain/meters the ESP32 will only scan when needed and requested. If you include motion or contact sensors the ESP32 will scan all the time
  • You can use the button on the switchbot contact sensor in order to trigger other things through HA or your smarthub. Look for the payload "PUSHED" on <ESPMQTTTopic>/contact/<name>/button

Hi devWaves,

Its been a while since I’ve checked in, I’m still rocking v1.2 and v3.0 and devices are still working solidly!

Great to see so much more progress.
Question regarding your latest update with motion/contact sensors.
Would you recommend trying at this stage? any lag or issues to be concerned about?