devWaves / SwitchBot-MQTT-BLE-ESP32

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
MIT License
549 stars 68 forks source link

Add functionality to push all switchbots with ESP32 BOOT button #70

Open TheHolyRoger opened 2 years ago

TheHolyRoger commented 2 years ago

I have to admit I'm not hugely familiar with cpp yet but here is a PR that's working for me to use the ESP32 BOOT button to toggle all switchbots :)

Useful for me so thought I'd share

devWaves commented 2 years ago

lol. I barely know c++. It is not one of the languages I work with daily. But knew just enough to get this project going

that's a neat idea and I could probably add something like that, but I would probably make a few code changes. Good work though

things I would change: 1) create another list for bots to control with the esp32 button (instead of all bots) 2) add the command to control the bot to the queue of commands instead of sending the command directly. This will ensure the retry logic works etc and doesn't interfere with MQTT commands coming in. Like this...

struct QueueCommand queueCommand;
queueCommand.payload = "OFF";
queueCommand.topic = ESPMQTTTopic + "/control";
queueCommand.device = aDevice;
queueCommand.disconnectAfter = true;
queueCommand.priority = false;
queueCommand.currentTry = 1;
commandQueue.enqueue(queueCommand);

instead of .. controlMQTT(aDevice, "OFF", true);

3) This could also technically apply to curtains

I am working on getting the v7.0 release, which is here https://github.com/devWaves/SwitchBot-MQTT-BLE-ESP32/tree/v7alpha The only remaining issue in v7.0 is related to mesh stuff I added, but it includes a bunch of other changes. So I will be releasing it soon either way

Once I get v7.0 out, I will try to take a look a this

thanks for sharing

TheHolyRoger commented 2 years ago

@devWaves thanks man! I might come back to this when you release v7 if you haven't done your own implementation :D

Thanks to you I just successfully ripped this code apart and created a working ESP32 keypad to arm/disarm my HASS alarm :) thank you!!!

TheHolyRoger commented 2 years ago

@devWaves updated it :)