Coder Social home page Coder Social logo

devwaves / switchbot-mqtt-ble-esp32 Goto Github PK

View Code? Open in Web Editor NEW
527.0 21.0 66.0 600 KB

Allows for multiple SwitchBot bots and curtains to be controlled via MQTT sent to ESP32. ESP32 will send BLE commands to switchbots and return MQTT responses to the broker. Also supports Temperature, Motion, Contact sensors

License: MIT License

C++ 100.00%

switchbot-mqtt-ble-esp32's Introduction

SwitchBot-MQTT-BLE-ESP32

Switchbot local control using ESP32. no switchbot hub used/required. works with any smarthub that supports MQTT

https://github.com/devWaves/SwitchBot-MQTT-BLE-ESP32

v7.1

Created: on Aug 17 2022

Author: devWaves

Buy Me A Coffee

Contributions from:

  • HardcoreWR
  • vin-w

Code can be installed using Arduino IDE OR using Visual Studio Code PlatformIO

  • For Arduino IDE - Use only the SwitchBot-BLE2MQTT-ESP32.ino file
  • For Visual Studio Code PlatformIO - Use the src/SwitchBot-BLE2MQTT-ESP32.cpp and platformio.ini files

Allows for "unlimited" switchbots devices to be controlled via MQTT sent to ESP32. ESP32 will send BLE commands to switchbots and return MQTT responses to the broker

  • I do not know where performance will be affected by number of devices
  • This is an unofficial SwitchBot integration. User takes full responsibility with the use of this code**

based off of the work from https://github.com/combatistor/ESP32_BLE_Gateway

Notes:

  • Supports Home Assistant MQTT Discovery
  • Support bots, curtains, temp meters, contact sensors, motion sensors, plug mini
  • It works for button press/on/off
  • It works for curtain open/close/pause/position(%)
  • It can request status values (bots/curtain/meter/motion/contact: battery, mode, state, position, temp etc) using a "rescan" for all devices
  • It can request individual device status values (bots/curtain/meter/motion/contact: battery, mode, state, position, temp etc) using a "requestInfo"
  • Good for placing one ESP32 in a zone with 1 or 2 devices that has a bad bluetooth signal from your smart hub. MQTT will use Wifi to "boost" the bluetooth signal
  • ESP32 bluetooth is pretty strong and one ESP32 can work for entire house. The code will try around 60 times to connect/push button. It should not need this many but it depends on ESP32 bluetooth signal to switchbots. If one alone doesn't work, get another esp32 and place it in the problem area
  • OTA update added. Go to ESP32 IP address in browser. In Arduino IDE menu - Sketch / Export compile Binary . Upload the .bin file
  • Support for bot passwords
  • Automatically rescan every X seconds
  • Automatically requestInfo X seconds after successful control command
  • Retry set/control command on busy response from bot/curtain until success
  • Get settings from bot (firmware, holdSecs, inverted, number of timers)
  • Add a defined delay between each set/control commands or per device
  • ESP32 will collect hold time from bots and automatically wait holdSecs+defaultBotWaitTime until next command is sent to bot
  • Retry on no response curtain or bot
  • holdPress = set bot hold value, then call press (without disconnecting in between)
  • Set/Control is prioritized over scanning. While scanning, if a set/control command is received scanning is stopped and resumed later
  • ESP32 can simulate ON/OFF for devices when bot is in PRESS mode. (Cannot guarantee it will always be accurate)
  • Curtain position will update as curtain is moving
  • Switchbot device states will always update when state is changed while scanning (active/passive)
  • Mesh multiple ESP32s for better motion/contact/meter performance
  • Active scanning (uses more battery) VS Passive scanning (uses less battery)



<ESPMQTTTopic> = <mqtt_main_topic>/<host>

  - Default = switchbot/esp32

ESP32 will subscribe to MQTT 'set' topic for every configure device

  - <ESPMQTTTopic>/bot/<name>/set
  - <ESPMQTTTopic>/curtain/<name>/set
  - <ESPMQTTTopic>/meter/<name>/set
  - <ESPMQTTTopic>/contact/<name>/set
  - <ESPMQTTTopic>/motion/<name>/set

Send a payload to the 'set' topic of the device you want to control
  Strings:
    - "PRESS"
    - "ON"
    - "OFF"
    - "OPEN"
    - "CLOSE"
    - "PAUSE"
    - "STATEOFF"    (Only for bots in simulated ON/OFF mode)
    - "STATEON"     (Only for bots in simulated ON/OFF mode)

  Integer 0-100 (for curtain position) Example: 50
  Integer 0-100 (for setting bot hold seconds) Example: 5           (for bot only) Does the same thing as <ESPMQTTTopic>/setHold

  Strings:
    - "REQUESTINFO" or "GETINFO"                               (for bot and curtain) Does the same thing as calling <ESPMQTTTopic>/requestInfo
    - "REQUESTSETTINGS" or "GETSETTINGS"                       (for bot only) Does the same thing as calling <ESPMQTTTopic>/requestSettings . requires getBotResponse = true
    - "MODEPRESS","MODESWITCH","MODEPRESSINV","MODESWITCHINV"  (for bot only) Does the same thing as <ESPMQTTTopic>/setMode

                  ESP32 will respond with MQTT on 'status' topic for every configured device
                    - <ESPMQTTTopic>/bot/<name>/status
                    - <ESPMQTTTopic>/curtain/<name>/status
                    - <ESPMQTTTopic>/meter/<name>/status
		
                    Example payload:
                      - {"status":"connected", "command":"ON"}
                      - {"status":"errorConnect", "command":"ON"}
                      - {"status":"errorCommand", "command":"NOTVALID"}
                      - {"status":"commandSent", "command":"ON"}
                      - {"status":"busy", "value":3, "command":"ON"}
                      - {"status":"failed", "value":9, "command":"ON"}
                      - {"status":"success", "value":1, "command":"ON"}
                      - {"status":"success", "value":5, "command":"PRESS"}
                      - {"status":"success", "command":"REQUESTINFO"}
		  
                   ESP32 will respond with MQTT on 'state' topic for every configured device
                    - <ESPMQTTTopic>/bot/<name>/state
                    - <ESPMQTTTopic>/curtain/<name>/state
		
                    Example payload:
                      - "ON"
                      - "OFF"
                      - "OPEN"
                      - "CLOSE"
		  
                    ESP32 will respond with MQTT on 'position' topic for every configured device
                    - <ESPMQTTTopic>/curtain/<name>/position
		
                    Example payload:
                      - {"pos":0}
                      - {"pos":100}
                      - {"pos":50}

ESP32 will Subscribe to MQTT topic to rescan for all device information

  - <ESPMQTTTopic>/rescan

  send a JSON payload of how many seconds you want to rescan for
      example payloads =
        {"sec":30}
        {"sec":"30"}

ESP32 will Subscribe to MQTT topic for device information

  - <ESPMQTTTopic>/requestInfo

  send a JSON payload of the device you want to control
      example payloads =
        {"id":"switchbotone"}

                  ESP32 will respond with MQTT on
                    - <ESPMQTTTopic>/#
		
                    Example attribute responses per device are detected:
                      - <ESPMQTTTopic>/bot/<name>/attributes
                      - <ESPMQTTTopic>/curtain/<name>/attributes
                      - <ESPMQTTTopic>/meter/<name>/attributes
                      - <ESPMQTTTopic>/contact/<name>/attributes
                      - <ESPMQTTTopic>/motion/<name>/attributes
		  
                    Example payloads:
                      - {"rssi":-78,"mode":"Press","state":"OFF","batt":94}
                      - {"rssi":-66,"calib":true,"batt":55,"pos":50,"state":"open","light":1}
                      - {"rssi":-66,"scale":"c","batt":55,"C":"21.5","F":"70.7","hum":"65"}
                      - {"rssi":-77,"batt":89,"motion":"NO MOTION","led":"OFF","sensedistance":"LONG","light":"DARK"}
                      - {"rssi":-76,"batt":91,"motion":"NO MOTION","contact":"CLOSED","light":"DARK","incount":1,"outcount":3,"buttoncount":4}
		  
                    Example attribute responses per device are detected:
                      - <ESPMQTTTopic>/bot/<name>/state
                      - <ESPMQTTTopic>/curtain/<name>/state
                      - <ESPMQTTTopic>/meter/<name>/state

		  
                    Example payload:
                      - "ON"
                      - "OFF"
                      - "OPEN"
                      - "CLOSE"
		  
                    ESP32 will respond with MQTT on 'position' topic for every configured device
                    - <ESPMQTTTopic>/curtain/<name>/position
		
                    Example payload:
                      - {"pos":0}
                      - {"pos":100}
                      - {"pos":50}
		  
		Example topic responses specific to motion/contact sensors:
                      - <ESPMQTTTopic>/motion/<name>/motion		Example response payload: "MOTION", "NO MOTION"
                      - <ESPMQTTTopic>/motion/<name>/illuminance	Example response payload: "LIGHT", "DARK"
                      - <ESPMQTTTopic>/contact/<name>/contact		Example response payload: "OPEN", "CLOSED"
                      - <ESPMQTTTopic>/contact/<name>/motion		Example response payload: "MOTION", "NO MOTION"
                      - <ESPMQTTTopic>/contact/<name>/illuminance	Example response payload: "LIGHT", "DARK"
                      - <ESPMQTTTopic>/contact/<name>/in		Example response payload: "IDLE", "ENTERED"
                      - <ESPMQTTTopic>/contact/<name>/out		Example response payload: "IDLE", "EXITED"
                      - <ESPMQTTTopic>/contact/<name>/button		Example response payload: "IDLE", "PUSHED" 

			Note: 	You can use the button on the contact sensor to trigger other non-switchbot devices from your smarthub
				When <ESPMQTTTopic>/contact/<name>/button = "PUSHED"

ESP32 will Subscribe to MQTT topic for device settings information (requires getBotResponse = true) - BOT ONLY

  - <ESPMQTTTopic>/requestSettings

send a JSON payload of the device you want to control
      example payloads =
        {"id":"switchbotone"}

                  ESP32 will respond with MQTT on
                    - <ESPMQTTTopic>/#

                  Example responses per device are detected:
                    - <ESPMQTTTopic>/bot/<name>/settings

                  Example payloads:
                     - {"firmware":4.9,"timers":0,"inverted":false,"hold":5}

ESP32 will Subscribe to MQTT topic setting hold time on bots

  - <ESPMQTTTopic>/setHold

send a JSON payload of the device you want to control
      example payloads =
        {"id":"switchbotone", "hold":5}
        {"id":"switchbotone", "hold":"5"}

ESP32 will respond with MQTT on
- <ESPMQTTTopic>/#

                  ESP32 will respond with MQTT on 'status' topic for every configured device
                    - <ESPMQTTTopic>/bot/<name>/status

                    Example reponses:
                      - <ESPMQTTTopic>/bot/<name>/status

                    Example payload:
                      - {"status":"connected", "command":"5"}
                      - {"status":"errorConnect", "command":"5"}
                      - {"status":"errorCommand", "command":"NOTVALID"}
                      - {"status":"commandSent", "command":"5"}
                      - {"status":"busy", "value":3, "command":"5"}
                      - {"status":"failed", "value":9, "command":"5"}
                      - {"status":"success", "value":1, "command":"5"}
                      - {"status":"success", "value":5, "command":"5"}
                      - {"status":"success", "command":"REQUESTSETTINGS"}

ESP32 will Subscribe to MQTT topic to holdPress on bots. holdPress = set bot hold value, then call press on bot without disconnecting in between

  - <ESPMQTTTopic>/holdPress

send a JSON payload of the device you want to control
      example payloads =
        {"id":"switchbotone", "hold":5}
        {"id":"switchbotone", "hold":"5"}

ESP32 will respond with MQTT on
- <ESPMQTTTopic>/#

                  ESP32 will respond with MQTT on 'status' topic for every configured device
                    - <ESPMQTTTopic>/bot/<name>/status

                    Example reponses:
                      - <ESPMQTTTopic>/bot/<name>/status

                    Example payload:
                      - {"status":"connected", "command":"5"}
                      - {"status":"errorConnect", "command":"5"}
                      - {"status":"errorCommand", "command":"NOTVALID"}
                      - {"status":"commandSent", "command":"5"}
                      - {"status":"busy", "value":3, "command":"5"}
                      - {"status":"failed", "value":9, "command":"5"}
                      - {"status":"success", "value":1, "command":"5"}
                      - {"status":"success", "value":5, "command":"5"}
                      - {"status":"success", "command":"REQUESTSETTINGS"}
                      - {"status":"connected", "command":"PRESS"}
                      - {"status":"errorConnect", "command":"PRESS"}
                      - {"status":"commandSent", "command":"PRESS"}
                      - {"status":"busy", "value":3, "command":"PRESS"}
                      - {"status":"failed", "value":9, "command":"PRESS"}
                      - {"status":"success", "value":1, "command":"PRESS"}
                      - {"status":"success", "value":5, "command":"PRESS"}

ESP32 will Subscribe to MQTT topic setting mode for bots

  - <ESPMQTTTopic>/setMode

send a JSON payload of the device you want to control
      example payloads =
        {"id":"switchbotone", "mode":"MODEPRESS"}
        {"id":"switchbotone", "mode":"MODESWITCH"}
        {"id":"switchbotone", "mode":"MODEPRESSINV"}
        {"id":"switchbotone", "mode":"MODESWITCHINV"}

                  ESP32 will respond with MQTT on 'status' topic for every configured device
                    - <ESPMQTTTopic>/bot/<name>/status

                    Example reponses:
                      - <ESPMQTTTopic>/bot/<name>/status

                    Example payload:
                      - {"status":"connected", "command":"MODEPRESS"}
                      - {"status":"errorConnect", "command":"MODEPRESS"}
                      - {"status":"errorCommand", "command":"NOTVALID"}
                      - {"status":"commandSent", "command":"MODEPRESS"}
                      - {"status":"busy", "value":3, "command":"MODEPRESS"}
                      - {"status":"failed", "value":9, "command":"MODEPRESS"}
                      - {"status":"success", "value":1, "command":"MODEPRESS"}
                      - {"status":"success", "value":5, "command":"MODEPRESS"}

ESP32 will respond with MQTT on ESPMQTTTopic with ESP32 status

  - <ESPMQTTTopic>

  example payloads:
    {status":"idle"}
    {status":"scanning"}
    {status":"boot"}
{status":"controlling"}
{status":"getsettings"}

Errors that cannot be linked to a specific device will be published to

  - <ESPMQTTTopic>


Steps to Install on ESP32 - Using Arduino IDE

  1. Install Arduino IDE

  2. Setup IDE for proper ESP32 type https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/ (Tested working with version 1.0.6 of the ESP32 Core Arduino Library)

  3. Install NimBLE-Arduino library (Tested working with version 1.4.0)

  4. Install EspMQTTClient library (Tested working with version 1.13.3)

  5. Install ArduinoJson library (Tested working with version 6.19.4)

  6. Install CRC32 library (by Christopher Baker) (Tested working with version 2.0.0)

  7. Install ArduinoQueue library (Tested working with version 1.2.5)

  8. Modify code for your Wifi and MQTT configurations and SwitchBot MAC addresses

    Configurations to change can be found in the code under these line...

    /****************** CONFIGURATIONS TO CHANGE *******************/
    
    /********** REQUIRED SETTINGS TO CHANGE **********/
    

    Stop when you see this line...

    /********** ADVANCED SETTINGS - ONLY NEED TO CHANGE IF YOU WANT TO TWEAK SETTINGS **********/
    
  9. Compile and upload to ESP32 (I am using Wemos D1 Mini ESP32)

  10. Reboot ESP32 plug it in with 5v usb (no data needed)



Steps to Install on ESP32 - Using Visual Studio Code - PlatformIO

  1. Install Visual Studio Code

  2. Add the PlatformIO extension to VSCode

  3. Open SwitchBot-BLE2MQTT-ESP32 project from PlatformIO

  4. Modify SwitchBot-BLE2MQTT-ESP32.cpp code for your Wifi and MQTT configurations and SwitchBot MAC addresses

    Configurations to change can be found in the code under these line...

    /****************** CONFIGURATIONS TO CHANGE *******************/
    
    /********** REQUIRED SETTINGS TO CHANGE **********/
    

    Stop when you see this line...

    /********** ADVANCED SETTINGS - ONLY NEED TO CHANGE IF YOU WANT TO TWEAK SETTINGS **********/
    
  5. Choose your ESP32 board type and Upload to ESP32

image

6. Reboot ESP32 plug it in with 5v usb (no data needed)

Steps for OTA update

  1. Download the latest version of the ESP32 code
  2. Edit the code with your Wifi, MQTT, Switchbot device MAC configurations
  3. Compile a .bin file using the IDE you are using
  4. Open the ESP32 IP address in a web browser
  5. Upload the new .bin file from the web browser
  6. Check from the web browser that the version is the correct version


Steps for ESP32 Mesh setup (Look at the EXAMPLES folder for different configuration between Primary and Secondary ESP32s

  1. Decide how many ESP32s you want to use
  2. Choose one ESP32 as the primary and set the host value. Example: static const char* host = "esp32";
  3. Setup the other ESP32s as secondary ESP32s. Set unique host values. Example: static const char* host = "esp32mesh1";
  4. Setup the other ESP32s as secondary ESP32s. Set meshHost to the primary ESP32 host value. Example: static const char* meshHost = "esp32";
  5. Decide on the other configurations:
    • Primary ESP32 can be set to Active and Passive Scan, or Active Scan only (if you are also using switchbot hub/app and what statuses to be synched constantly)
    • Secondary ESP32s can be set to passive scan only, or active scan less than the primary ESP32

NOTES:

In a MESH setup, messages will be routed through the primary ESP32. The primary ESP32 will keep counts of things like contact/motion/button pushes to ensure duplicates messages are not sent out. Each ESP32 will receive the BLE data from the device, so performance is greatly increased. The first ESP32 to detect the data change will result in a faster MQTT data publish

*Meshing only works for motion sensors, contact sensors and temp meters. Add the motion/contact/meter MAC address to all or most meshed ESP32s. Add the Bot and Curtain and Plug MACs only once on the ESP32 closest to the device

Active Scanning:

- Active Scanning uses more battery on switchbot devices. It requests a read response from the switchbot devices
- Active Scanning provides more data like battery info
- Active Scanning is required by Bots and Curtains

Passive Scanning:

- Passive Scanning uses less battery on switchbot devices. It does not request a read response from the switchbot devices
- Passive Scanning does not provide battery info in most cases, but provides state (ON/OFF, temp, contact, motion, humidity ... etc)
- Passive Scanning is good enough for Motion, Contact, Meter and Plugs

Videos and Tutorials on Youtube

by KPeyanski (Language English. based on v6.4. Home Assistant)
   https://www.youtube.com/watch?v=ZskFhma8atc
by CTech&Media (Language German. based on v1.5. Home Assistant)
   https://www.youtube.com/watch?v=HiBZb-IAbD8
by BangerTech (Language German. based on v6.1. OpenHab)
   https://www.youtube.com/watch?v=TmtCwZbDJIU



ESP32 models that I can confirm work

  • Wemos D1 Mini ESP32
  • ESP32-WROOM-32U (With external antenna)
  • ESP32-WROOM-32 (With internal antenna)
  • QuinLED-ESP32-AE
  • QuinLED-ESP32-AB
  • Heltec WiFi Kit 32

ESP32 models/boards that the community has confirmed as working

  • AZ-Delivery ESP32 Dev KitC v2
  • AZ-Delivery ESP32 Dev KitC v4

ESP32 models that may not work

  • ESP32-S2 = No Bluetooth so definitely won't work
  • ESP32-C3 = Less RAM/ROM that the WROOM models
  • ESP32s = Ai-Thinker model. Some users have said they had issues with this model
  • ESP32-solo = Only has one core instead of 2 cores

Known Supported SwitchBot devices and firmware versions

  • Bot = Firmware v6.2
  • Curtain = Firmware v4.6
  • Meter/MeterPlus = Firmware v2.7
  • Contact Sensor = Firmware v1.1
  • Motion Sensor = Firmware v1.3
  • Plug Mini = Firmware v1.3

switchbot-mqtt-ble-esp32's People

Contributors

devwaves avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

switchbot-mqtt-ble-esp32's Issues

SwitchBot Curtain Mode missing

SwitchBot Curtain supports two motion modes: "Silent Mode" and "Performance Mode".
It would be great if these would be available (get and set) through MQTT. Is this possible?

Error compiling

Hi devwaves, I've been trying to implement your awesome project for the last couple of days and I seem to have hit a wall. You see, whenever I try to compile it on my Arduino IDE, I end up with the following message:

exit status 1

comparison with string literal results in unspecified behaviour [-Werror=address]

and the bolded line below marked in red:
}
else {
int value = docIn["sec"];
String secString = String(value);
if (secString.c_str() != "") {
bool isNum = is_number(secString.c_str());
if (isNum) {

I also get errors sucha as the following:

_C:\Users\cdiaz\Documents\GitHub\SwitchBot-MQTT-BLE-ESP32\SwitchBot-BLE2MQTT-ESP32\SwitchBot-BLE2MQTT-ESP32.ino: In function 'void rescanMQTT(std::__cxx11::string)':

SwitchBot-BLE2MQTT-ESP32:2432:30: error: comparison with string literal results in unspecified behaviour [-Werror=address]

 if (secString.c_str() != "") {_

I have checked that I have the libraries installed, and the ESP332 board, and don't know what other options could be causing this, I have tried compiling with my settings but also I tried compiling the example ino without any setting filled, and I get the same error.

I am attaching the full log .

Thanks for any help

arduino error log.txt

Becoming unavailable every ~24 hours

Every ~24 hours my ESP32 device becomes unavailable. I don't know if it's freezing or dropping off the network or what. Replugging it back in, it immediately becomes available again and works great (until it drops off again). I've tried a few different power sources in case something where was going on there, but no luck.

This is the ESP32 device I'm installed on:

HiLetgo ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA for Arduino IDE

Do you have any idea what this may be or if there's a way I could debug the device to find out what could be going wrong?

Reduce update interval when curtain is moved

I have a curtain rail of 5.5mtr with 2x switchBot, which move towards each other so the curtain closes from the center.
When closing or opening the curtains, I am noticing that for each curtain the current_position is updated roughly halfway the motion, so it jumps to a value between 40-60%.
After the motion is complete, the value will stay at this position for several minutes, and then will update to 0 or 100% (depending on open/close state).

So, In summary, the current_position is not in sync with the SwitchBot app for a couple of minutes after the curtains have moved.
I would like to propose to have the position polled more often during and/or after the motion was executed.

Note that I did not change any settings (such as rescanTime), the only things I changed in the code is defining the MAC of the devices.
I will do an experiment later today to see whether calling requestInfo after moving causes the position to update, which could be a good workaround.
Anyway, I think it is nicer if this is handled by the code.

Curtains wont move

Hi guys, let me start by saying that this is my first ESP32 project. Apologies for any dumb questions.

I have 4 x curtainbots in the same room that I would like to control with my M5Stack Atom Lite. I followed all of the instructions on the Git page and also used KPeyanski's youtube video. I am using v6.4. I can see all 4 devices and their entities in HA. The values of all the sensors exactly match the Switchbot app. So it would appear that the M5 is on wifi & BLE is working.

However when I use HA to send an instruction to open, close or even just move the curtains to a % - nothing happens. If I watch the MQTT messages using MQTT Explorer, I can see that a SET topic is generated for the device and the POSITION changes to that value. However the POS in ATTRIBUTES never changes. The curtainbot doesnt move and after about 5-10 seconds the POSITION changes back to its original value.

Of course, I can make the bots move with the Switchbot App so there isnt anything wrong with the devices. Would you mind helping me please? Let me know what details you need and how I generate them please.

Speed of Bot and esp32

Is there a way to increase at which the bot responds to the esp32? With the app and phone it's pretty fast but with home assistant, there is a couple of seconds delay. Is there somewhere in the code I could modify the time it takes? Thank you!

Alexa support?

Do you plan to add Alexa/Google home support?

Maybe with FauxmoESP is easy, even for multiple switchbots

Battery Status as a separate subject

Hello,

Would it be possible to send the battery status as a separate subject?
Also for example /switchbot/esp32/curtain/curtainone/battery

The value is currently stored in the attribute topic with json.

Thank you!

Slow reaction time every now and then

First, many thanks for this great project, I'm doing my first Arduino step with it :)

I only use the push command on a SwitchBot and it works like a charm most of the time, but every now and then it takes a very long time (something like a minute) between the MQTT command and the actual reaction of the SwitchBot.

The SwitchBot is literally next to the esp32, so it shouldn't be related to Bluetooth range.

It's my first time using MQTT as well so I can't be sure if this delay is caused by the broker (I'm using the one provided with Home Assistant) or by the esp32, but if I would guess, I would say a very long process is triggered every now and then on the esp32 which makes it unresponsive for a few minutes.

Is that a know behavior?

Flash an Smartsocket

Hi,

is it possible to flash an socket with your firmware (e.g. Smartplug) to power up the ESP and use the socket as normal?

Ability to control press-hold time dynamically for Bots

I'd like to be able to dynamically control how long a press happens for each push signal.

TL;DR Waiting a period of time between switching it on/off while in Switch mode is not the same as specifying a "Press-hold Time" in the app.

Press-hold Time can be configured in the official app, but via this integration (or even the official app) you can't control this duration for each press.

This behavior could be somewhat achieved with this integration by putting the Bot in Switch mode, sending a signal to turn the switch on, and then waiting a dynamic period of time before sending another signal to turn the switch off. There are two problems with this approach though.

  1. I believe this would still require use of the app to set the mode and it would be nice to work completely independently of the app.
  2. The Press-hold Time seems to work independently of whether the button is being pressed where it remains in a depressed state for the period of time specified in the app.

To elaborate on # 2, there seem to be 3 relevant states when in Switch mode:

  1. The button is in an up state (it's sticking out slightly from the front of the button)
  2. A press-hold state which it will stay in for the period of time that's specified for the Press-hold Time setting in the app. In this state the lever is depressed slightly below the bottom of the button.
  3. A hold state where the lever is down and perpendicular to it's default resting position inside the Bot.

Waiting a period of time does not keep the button in a press-hold state where it's depressed, but rather just perpendicular to the Bot. The time the Bot is in a press-hold state is only for the duration of time specified in the app.

So if I want the button to wait in a "held" state for a period of time, there's no way to do this dynamically.

I'm pretty sure this is possible to do client-side because I've done it using their official node-switchbot library. You can see in the example for moving the arm of the Bot where they call switchbot.wait(5000) after device.down(). When "down", it's in the fully depressed "press-hold" state.

Sorry if this was a bit long winded. I have a use case where a perpendicular lever is not adequate and I need it to go to the more obtuse angle where it's below the bottom plain of the Bot.

What are your thoughts? Happy to elaborate more if needed :)

adding Contact Sensor & Motion Sensor

Hi there,

first of all a huuuge Thank you for the great work!!!

i was wondering if ther would/ will be a way to connect the contact & motion sensor in the near future?

thanks again

greets

sdkconfig.h: No such file or directory

Hello, good morning,

First of all I would like to thank you for the work that you have done, congratulations!

On the other hand, I am trying to install on a Wemos D1 Mini board through the Arduino IDE.

But I have encountered the following error.

Arduino:1.8.15 (Windows 10), Tarjeta:"WeMos D1 R1, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600"

In file included from D:\Documents\Home Assistant\SwitchBot\SwitchBot-MQTT-BLE-ESP32-main\SwitchBot-BLE2MQTT-ESP32\SwitchBot-BLE2MQTT-ESP32.ino:258:0:

NimBLEDevice.h:17:23: fatal error: sdkconfig.h: No such file or directory

#include "sdkconfig.h"

                   ^

compilation terminated.

exit status 1

sdkconfig.h: No such file or directory

Please, Can anyone tell me how I can solve it?

Add MQTT channel/attribute for wifi rssi

Can you please add a MQTT channel or an attribute to an existing channel for wifi rssi.

Here is a code snipped:

String rssi = String(WiFi.RSSI());
client.publish("switchbot/esp32/rssi", rssi);

ESPHome?

Is there a config that works with ESPHome for this?

Turns on at random?

I got this all setup and it works but the one issue is that the ESP randomly sends the command to the SB for a button push. No external triggers are telling it to do so as far as I can tell.

Might be related to loss/reconnect of wifi but I'm not certain

Problem with removed devices

I’ve got a problem with showing switchbot devices in HA.

By mistake I removed a switchbot devices from HA. I changed a config of SwitchBot MQTT but still there is no devices showing in HA.

How to “reset” ESP to show devices in HA?

Flashed to ESP-WROOM-32 and keeps rebooting

Flashed on ESP32 Dev Module (ESP-WROOM-32) and it Keeps rebooting.

it loops over status 'boot','scanning', I don't know where to start :/ .

in Arduino IDE it shows many of these warning:

659:69: warning: converting to non-pointer type 'byte' {aka 'unsigned char'} from NULL [-Wconversion-null]
static byte bArrayPos[] = {0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, NULL};

1295:1: warning: control reaches end of non-void function [-Wreturn-type]
}

Serial Monitor output might be useful.
10:22:42.975 -> ets Jun 8 2016 00:22:57
10:22:42.975 ->
10:22:42.975 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
10:22:42.975 -> configsip: 0, SPIWP:0xee
10:22:42.975 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:22:42.975 -> mode:DIO, clock div:1
10:22:42.975 -> load:0x3fff0030,len:1240
10:22:42.975 -> load:0x40078000,len:13012
10:22:42.975 -> load:0x40080400,len:3648
10:22:42.975 -> entry 0x400805f8
10:22:45.584 -> E (4696) wifi:Association refused temporarily, comeback time 1024 mSec
10:22:57.257 -> Switchbot ESP32 starting...
10:22:57.257 -> Set printSerialOutputForDebugging = true to see more Serial output
10:23:01.638 -> Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
10:23:01.638 ->
10:23:01.638 -> Core 1 register dump:
10:23:01.638 -> PC : 0x40094e8d PS : 0x00060e33 A0 : 0x40092b23 A1 : 0x3ffd5690
10:23:01.638 -> A2 : 0x3ffc5384 A3 : 0x3ffbf278 A4 : 0xb33fffff A5 : 0x00000001
10:23:01.672 -> A6 : 0x3ffc52fc A7 : 0x3ffc5190 A8 : 0x53003ffc A9 : 0x00000000
10:23:01.672 -> A10 : 0x3ffc5300 A11 : 0x00000012 A12 : 0x53140000 A13 : 0x00000048
10:23:01.672 -> A14 : 0x00000000 A15 : 0x00000001 SAR : 0x00000012 EXCCAUSE: 0x0000001c
10:23:01.672 -> EXCVADDR: 0x00000048 LBEG : 0x40096819 LEND : 0x40096828 LCOUNT : 0x00000001
10:23:01.705 ->
10:23:01.705 ->
10:23:01.705 -> Backtrace:0x40094e8a:0x3ffd56900x40092b20:0x3ffd56d0 0x40092bb1:0x3ffd56f0 0x400e7a4a:0x3ffd5710 0x400f19c9:0x3ffd5770 0x400f263f:0x3ffd5940 0x400f2f2f:0x3ffd5a40 0x400f339f:0x3ffd5bd0 0x400fbeae:0x3ffd5c50 0x40121e48:0x3ffd5cb0
10:23:01.705 ->
10:23:01.705 ->
10:23:01.705 ->
10:23:01.705 ->
10:23:01.705 -> ELF file SHA256: 0000000000000000
10:23:01.705 ->
10:23:01.705 -> Rebooting...

Support slider control mode single side

Thanks for providing this awesome code! :-).

I combined two Switchbot Curtains 2 and I would like to have the same options as the app. To control both sides via a single cover entity (in Home Assistant), but also to control both sides separately via cover entities.

Currently I added both mac addresses and the behavior is like this via SwitchBot-MQTT-BLE-ESP32:

  • Left: this will move both sides (as left is the main switchbot in the switchbot app)
  • Right: this will move only the right side

It seems that there is no way to only move the left side anymore via HA/mqtt, while it is possible via the original app.

By the way, I will have a look if I can port parts of the Curtain code to ESPHome as well in the coming months. I just received the Switchbot Curtain Urail 2.

Support ON//OFF State für SwitchBot in Press-Mode

Hi,
I'm controlling my pool heatpump, wich only has a Power press button, with a SwitchBot in Pressmode and your Firmware on an esp32 and it works very well. Now I want to automate it depending on the energy amount of my Solar Power. To do this I need the ON/OFF State of the bot. Can you please enhance your Firmware, so that one could send ON and OFF commands in Pressmode to press the bot and the /state Channel would report the last successful commanded State?

ESP8266 support?

Is there any way you could make this support ESP8266 as well? I'm specifically looking at using a D1 mini pro.

missing sdkconfig.h

Trying to upload to Arduino it fails with the following error:

In file included from /home/user/SwitchBot/SwitchBot.ino:320:
/home/user/Arduino/libraries/NimBLE-Arduino/src/NimBLEDevice.h:17:10: fatal error: sdkconfig.h: No such file or directory
17 | #include "sdkconfig.h"
| ^~~~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

I have found this page, but the sdkconfig.h is 404
https://forum.arduino.cc/t/fatal-error-sdkconfig-h-no-such-file-or-directory/562561

May I know how to fix the problem?
Thanks.

Error when compiling

Traceback (most recent call last):
File "/home/y2kbug/.arduino15/packages/esp32/tools/esptool_py/3.0.0/esptool.py", line 38, in
import serial
ModuleNotFoundError: No module named 'serial'
exit status 1
Error compiling for board NodeMCU-32S.

Last will

Possible to add last will message to be able to monitor MQTT connectivity?

[BUG] Wemos D1 Mini ESP32 Reboots (Crashes?) on commands

I am using the Wemos D1 Mini ESP32 and have a curtain as well as a bot. Both exhibit similar behavior where they will have a new state set, update correctly, and then I can see on my router it disconnects and then reconnects. The MQTT state is then changed back to what it was before. If I check in HA I can see it update to the correct state, become unavailable, and then come back as the state before.

image

It happens almost every time, but has been successful a couple times in the past. I am unsure what is causing the issue, the is less than 10 feet away from both devices so it shouldn't be a connection issue.

Switchbot remote support?

Hello,

Current using two Switchbots and it works great! Thank you. Wondering if you had seen the Switchbot remote ? I am thinking to pick one up on the sale and use it as a physical switch. Would this be easy to support?

LED_BUILTIN Error

Im using version 0.14 today I received second switch curtain and by the way I wish to update, but when I compile I've got this error in Arduino:

In function 'void scanEndedCB(NimBLEScanResults)':
sketch_may17a:484:18: error: 'LED_BUILTIN' was not declared in this scope
     digitalWrite(LED_BUILTIN, LOW);

[Feature request] Monitoring support

Hello there.

I have found the ESP32 stops working periodically.
I think it is due to WIFI connectivity.
May I request to add a feature, to PING a given URL periodically, which the URL and INTERVAL could be specified in settings?
I am using healthchecks.io as service monitor, and via webhook to instruct HomeAssistant to reset the power of the ESP32.

Thanks.

Adding contact sensor breaks curtains

Hi,

I've been using this to control a pair of curtain bots for a few weeks and it's been working mostly okay, except some unexplained delays here and there.

I just added a contact sensor, and the blue LED is now just always on. The contact sensor is working great in HA and updates quickly, but the curtains are now unresponsive.
Is there some conflict there, is the connection to the contact sensor left on all the time and preventing connections to other devices ?

This is what is looping on the output :

Adding Our Service ...
switchbotContactLivingRoomSideDoor
callForInfoAdvDev
Assigned advDevService
// The below repeats, a lot
Advertised Device found: Name: , Address: <some mac>, manufacturer data: ..., serviceUUID: ...
Service Data:
UUID: 0x0d00, Data: cп`2
[...]
//
Adding Our Service ...
switchbotContactLivingRoomSideDoor
callForInfoAdvDev
Assigned advDevService

I shorten it, but the mac(s) it finds there aren't related, likely some other devices somewhere in the house.
Left it for a few minutes and it looks like that's all that repeats. It connects to the curtains once at the very start, but as soon as it connects to the contact sensor that's all it outputs, endlessly.

Thanks

Integrate in esphome label:enhancement

Great job! I would like if it's possible cooperate with esphome to integrate it.
I have a eps32 and I would configure it not only for "SwitchBot-MQTT-BLE-ESP32" but olso for other devices.
Esphome community has already asked to integrate it ( see here ).
Thanks

HomeAssistant warning "Payload is not supported"

Log

2021-09-29 21:36:51 WARNING (MainThread) [homeassistant.components.mqtt.cover] Payload is not supported (e.g. open, closed, opening, closing, stopped): PAUSE

Please add stat_stopped: PAUSE to config topic to remove this warning.

client.publish((home_assistant_mqtt_prefix + "/cover/" + deviceName + "/config").c_str(), ("{\"~\":\"" + (curtainTopic + deviceName) + "\", " +
                 ...
                 + "\"stat_stopped\": \"PAUSE\", " +
                 ...

Thanks!

Infrared support

Is it possible to support infrared via Switchbot hub?
Thanks.

Integration into ESPHome

I'm intrigued by this piece of software, and I would love to be able to integrate it into my CC2652 POE Coordinator, that's running ESP32 with a CC2652 Zigbee module in it as well.

Has anyone attempted this yet?

Delay in actions

Hi,

I just set this up on a Doit dev kit v1, and when I press the buttons in HA the delay between the button press and the switchbot curtains actually moving is very inconsistent.
Sometimes it goes right away but it usually takes a while, I've seen it take up to 15 seconds.

Is there a way to figure out why it's that slow ? I have the board a couple of meters away from the switchbots, I can't get it any closer. Rssi is somewhere between 50 and 70 usually.

The blue LED on the board comes on when the curtains are moving, not when the button is pressed. Does that mean the delay is in mqtt or in ble ?

Thanks

Possibility to reset the switchbot switch status in HA?

Basically, because the switchbot doesn’t have an ON and OFF state the reporting in the dashboard will sometimes do weird things and not trigger correctly.
For those who don’t know, when the switchbot triggers, it’ll press down a button/switch/whatever, and then go back to its original position.
This is fine if you use it on a Lightswitch or similar devices that do have a realistic on and off-state by themselves.
For use cases though where the button is always in a neutral position (for example Touch-sensitive buttons like on a coffee machine etc) the status will keep changing even though the device that’s being controlled by the switchbot doesn’t really match that status.

Direct example to make it a bit more clear:
I use the switchbot on an Intercom device to open the door to our apartment complex. As long as the button is pressed, the entrance door will be unlocked. If I call the automation for it, It will press it, wait for a few seconds (that’s a setting on the switchbot device itself) and then let go.
Now Home Assistant will report the status as “ON” and next time I need to use the intercom automation, I’ll need a to use it twice back to back to turn the status back to “OFF” and then to activate it again.

TL;DR:
Is it possible to make switches go “OFF” (without triggering any actions) automatically after they had been turned on?

HA sees the devices but wont operate them

Hi, I have problem. I set up the esp32 with HA and the switchbot code and everything ran great for weeks. Then around the time Switchbot released their hub firmware update but the HA integration stopped responding. I updated the firmware but still nothing, I then update the esp32 to Switchbot code v6.5 and it started working. But it has gone back to not responding. It shows the devices but when I try and click to turn on a device it doesn't do anything. It is also stating the curtains are closed but they are open.

2021-12-19.11-13-53.mp4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.