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

I can confirm it’s now working as expected.
Manually toggled the lastWill to offline and after a moment it was changed to online again.

Thanks!

you can watch for the successful command mqtt, just saying it could potentially be wrong

When you say this, where can I get that “confirmation” that it was sent in HA or Node-red.

Thanks in advance.

you would look for the message “status” = “commandSent” on the mqtt topic specific to the switchbot device

<ESPMQTTTopic>/bot/<name>/status

I might have found a way to confirm the switchbot did the action. or if it was busy. I may include that in a future update when I figure it out

Incase you didn’t know, with HA you listen to Mqtt topic flow either in the the Mqtt Integration setup (configure > Listen to a topic) info will show on same page.
Or… using developer tools using - SERVICE MQTT.DUMP and view info in the mqtt_dump.txt file found in Config/ folder.

Hope this helps.

Do you know if it is possible to integrate this somehow (with or without MQTT) into esp32_ble_tracker in ESPHome?

you can probably integrate switchbot meters with esp32_ble_tracker for esphome, but not with this directly. switchbot meters only require a scan function. Meters are always sending out BLE signals with their temp data, you just have to capture it

bots and curtains however require you to first connect to the bot, then quickly send a command to control it. a scan (similar to meter) would return the bot device info (state, battery etc)

You can probably get something working with esphome, but not sure and not with this

Thanks got it working. Using node-red to confirm "command sent " before toggling another input Boolean.

This way, even if my Bot is in press mode I can keep track of ON/OFF state.
Yes, I’m aware of not sending two commands in less than 10 sec. Node-red handles that as well.

Thanks!

I’m looking into an update to grab the hold time and put a delay between commands

1 Like

I’m completely new to this and I can’t seem to get it to work. I succesfully flashed my ESP32, it connects to the WIFI, I see MQTT messages and it finds my 2 switchbot bots through bluetooth.

I am however not sure how they get configured. Is it supposed to go automatically? Because this is what I see in the Serial monitor:

17:09:52.787 -> Advertised Device found: Name: , Address: c8:77:61:xx, manufacturer data: 5900c87761cea5d3, serviceUUID: cba20d00-2xxxx
17:09:52.787 -> Service Data:
17:09:52.787 -> UUID: 0x0d00, Data: Hd
17:09:52.787 -> Stopping Scan found devices ... 
17:09:52.787 -> Scan Ended

And then nothing happens. I have MQTT Explorer open too, and all I see is this:

image

if using HA MQTT discovery you should see your switchbots show up automatically in your HA devices

you can add them to your HA dashboard from devices

from the serial output you sent it looks like your bots were found successfully. you’re almost there

Thanks for your response! I do have HA MQTT discovery enabled and double checked if everything was setup right. I use HA MQTT discovery for many other devices which get automatically added, however the switch bot are unfortunately not being added automatically.

I figured if they would be paired with the ESP32 I’d see messages popup in MQTT explorer too, which doesn’t seem to be the case either.

are u using the default settings?

your bots are discovered and mqtt looks connected. you should be seeing messages while the initial scan is occurring. It wouldnt have said the serial output of Stopping Scan found devices... if it wasnt able to collect and mqtt publish the bot values.

make sure no other devices are using the same mqtt info

you can send me a copy of your file if you want and I can take a look

I am in similar boat, i see samething as realmadrisi is seeing in MQTT explorer , just one messeage lastwill = online,

I think i found the problem , i have multiple devices using the same MQTT (running on Homeassistant), as soon as it find the first ble device it stops scanning, how do i give unique mqtt info for this device?

Hi Folks,

I have just upgraded one of my esp32’s to version 2.3, the meter attached refreshes fine now after HA reboot.
WebUi looks fantastic, less likely to upload code to wrong device now to :grinning:(Thanks!!).

However, since upgrading from V2.1, 2 out of the 3 bots are not refreshing and are not useable.

Entities for all devices (working or not) are seen in HA.

Seems changing main topic was a bad idea, past usage was switchbotMQTT topic, changed back to ‘switchbot’ and working ok now.

static std::string mqtt_main_topic = "switchbot";  

My bad!

any idea on how to give this unique mqtt info, i have tons of BLE devices. As soons as it finds something it stops scanning

I did not include the mac address that could be the problem, how do i find the mac address of the Switchbot?

That would help :slight_smile:

Use the Switchbot app… go to settings of the bot device.

Thanks, found it