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 Issues

[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.

[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.

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?

ESP8266 support?

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

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

ESPHome?

Is there a config that works with ESPHome for this?

Alexa support?

Do you plan to add Alexa/Google home support?

Maybe with FauxmoESP is easy, even for multiple switchbots

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!

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);

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?

Infrared support

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

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!

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?

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?

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!

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.

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?

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.

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?

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?

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

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 :)

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?

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?

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.

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);

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

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

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...

Last will

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

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

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

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

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.

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.