Merci pour l’info.
Je vous transmet le début du fichier de configuration que j’utilise car j’ai essayé d’insérer les lignes de commande pour les reconnexions automatiques mais quand je fait la vérification du code avant l’injection j’obtiens des erreurs.
Si vous pouvez m’orienter pour l’insertion des commande merci.
/** SwitchBot-MQTT-BLE-ESP32:
https://github.com/devWaves/SwitchBot-MQTT-BLE-ESP32
**does not use/require switchbot hub
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 **
v7.1
Created: on Aug 17 2022
Author: devWaves
Contributions from:
HardcoreWR
vin-w
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, and motion sensors
- It works for button press/on/off, set mode, set hold seconds
- 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 more 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
- Supports passwords on bot
- 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)
- 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
- Curtain position will move as curtain moves when controlled from MQTT
- Mesh 2 or more ESP32s together if you have motion or contact or meter. Mesh does not apply for bots or curtains
- Active Scan (uses more battery of BLE devices) vs Passive Scan (uses less battery of BLE devices). Motion/Contact Sensors support Passive Scanning. Bot/Curtain/Meter require active scanning
<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
- "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 requestInfo
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 response 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"}
Example attribute responses per device are detected:
- <ESPMQTTTopic>/bot/<name>/state
- <ESPMQTTTopic>/curtain/<name>/state
- <ESPMQTTTopic>/meter/<name>/state
- <ESPMQTTTopic>/contact/<name>/state (contact sensor has motion and contact. state = contact)
- <ESPMQTTTopic>/motion/<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 response 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"
// REQUESTSETTINGS WORKS FOR BOT ONLY - DOCUMENTATION NOT AVAILABLE ONLINE FOR CURTAIN
ESP32 will Subscribe to MQTT topic for device settings information
- <ESPMQTTTopic>/requestSettings
send a JSON payload of the device you want to requestSettings
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}
// SET HOLD TIME ON BOT
ESP32 will Subscribe to MQTT topic setting hold time on bots
- <ESPMQTTTopic>/setHold
send a JSON payload of the device you want to set hold
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"}
// holdPress = set bot hold value, then call press on bot (without disconnecting in between)
ESP32 will Subscribe to MQTT topic to action a holdPress on bots
- <ESPMQTTTopic>/holdPress
send a JSON payload of the device you want to set hold then press
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 response 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"}
// SET MODE ON BOT
ESP32 will Subscribe to MQTT topic setting mode for bots
- <ESPMQTTTopic>/setMode
send a JSON payload of the device you want to set mode
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>
*/
#include <NimBLEDevice.h>
#include <EspMQTTClient.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Update.h>
#include <CRC32.h>
#include <ArduinoQueue.h>
/****************** CONFIGURATIONS TO CHANGE *******************/
/********** REQUIRED SETTINGS TO CHANGE **********/
/* If using one ESP32 */
/* Enter all the switchbot device MAC addresses in the lists below */
/* If using multiple ESP32s - ESP32 can be meshed together for better motion/contact/meter performance */
/* Bot and Curtains and Plugs: (CANNOT BE MESHED) Enter the MAC addresses of the switchbot devices on the ESP32 closest to the switchbot device */
/* Motion and Contact and Meter: (CAN BE MESHED) Enter the MAC addresses of the switchbot devices into all or most of the ESP32s */
/* Wifi Settings */
static const char* host = ""; // Unique name for ESP32. The name detected by your router and MQTT. If you are using more then 1 ESPs to control different switchbots be sure to use unique hostnames. Host is the MQTT Client name and is used in MQTT topics
static const char* ssid = ""; // WIFI SSID
static const char* password = ""; // WIFI Password
/* MQTT Settings */
/* MQTT Client name is set to WIFI host from Wifi Settings*/
static const char* mqtt_host = ""; // MQTT Broker server ip
static const char* mqtt_user = ""; // MQTT Broker username. If empty or NULL, no authentication will be used
static const char* mqtt_pass = ""; // MQTT Broker password
static const int mqtt_port = 1883; // MQTT Port
static const std::string mqtt_main_topic = "switchbot"; // MQTT main topic
/* Mesh Settings */
/* Ignore if only one ESP32 is used */
static const bool enableMesh = true; // Ignore if only one ESP32 is used. Set to false
static const char* meshHost = ""; // Ignore if only one ESP32 is used. Ignore if you don't have either meter/contact/motion. Enter the host value of the primary ESP32 if you are using multiple esp32s and you want to mesh them together for better contact/motion
static const bool meshMeters = true; // Mesh meters together if meshHost is set. The meter values will use the meshHost MQTT topics
static const bool meshContactSensors = true; // Mesh contact sensors together if meshHost is set. The contact values will use the meshHost MQTT topics.
static const bool meshMotionSensors = true; // Mesh motion sensors together if meshHost is set. The motion values will use the meshHost MQTT topics
static const bool onlyAllowRootESPToPublishContact = true; // All meshed messages for contact and motions sensors will pass through the root mesh host ESP32. Only the root host will send contact and motion messages
static const bool onlyAllowRootESPToPublishMotion = false; // All meshed messages for motion will pass through the root mesh host ESP32. Only the root host will send motion messages
static const bool onlyAllowRootESPToPublishLight = false; // All meshed messages for illuminance will pass through the root mesh host ESP32. Only the root host will send illuminance messages
static const bool countContactToAvoidDuplicates = true; // count the number of open/close/timeout over all esp32s so that none are duplicated
static const bool countMotionToAvoidDuplicates = false; // count the number of motion/no motion over all esp32s so that none are duplicated
static const bool countLightToAvoidDuplicates = false; // count the number of dark/bright over all esp32s so that none are duplicated
static const int timeToIgnoreDuplicates = 10; // if a duplicate is determined, ignore it within X seconds
/* Switchbot Bot Settings */
static std::map<std::string, std::string> allBots = {
{ "switchbotone", "" },
{ "switchbottwo", "" },
{ "switchbotthree", "" },
{ "switchbotfour", "" }
};
/* Switchbot Curtain Settings */
static const int curtainClosedPosition = 10; // When 2 curtains are controlled (left -> right and right -> left) it's possible one of the curtains pushes one of the switchbots more open. Change this value to set a position where a curtain is still considered closed
static std::map<std::string, std::string> allCurtains = {
/*{ "curtainone", "xX:xX:xX:xX:xX:xX" },
{ "curtaintwo", "yY:yY:yY:yY:yY:yY" }*/
};
/* Switchbot Meter Settings */
static std::map<std::string, std::string> allMeters = {
{ "meterone", "" },
{ "metertwo", "" }
};
/* Switchbot Contact Sensor Settings */
static std::map<std::string, std::string> allContactSensors = {
/*{ "contactone", "xX:xX:xX:xX:xX:xX" },
{ "contacttwo", "yY:yY:yY:yY:yY:yY" }*/
};
/* Switchbot Motion Sensor Settings */
static std::map<std::string, std::string> allMotionSensors = {
/*{ "motionone", "xX:xX:xX:xX:xX:xX" },
{ "motiontwo", "yY:yY:yY:yY:yY:yY" }*/
};
/* Switchbot Plug Mini Settings */
static std::map<std::string, std::string> allPlugs = {
/*{ "plugone", "xX:xX:xX:xX:xX:xX" },
{ "plugtwo", "yY:yY:yY:yY:yY:yY" }*/
};
/* Switchbot Bot Passwords */
static std::map<std::string, std::string> allPasswords = {
// Set all the bot passwords (setup in app first). Ignore if passwords are not used
/*{ "switchbotone", "switchbotonePassword" },
{ "switchbottwo", "switchbottwoPassword" }*/
};
/* Switchbot Bot Device Types - OPTIONAL */
/* Options include: "switch", "light", "button" */
static std::map<std::string, std::string> allBotTypes = {
// OPTIONAL - (DEFAULTS to "switch" if bot is not in list) - Will create HA entities for device types
{ "switchbotone", "switch" },
{ "switchbottwo", "switch" },
{ "switchbotthree", "switch" },
{ "switchbotfour", "switch" }
};
/*** Bots in PRESS mode to simulate ON/OFF - ESP32 will try to keep track of the ON/OFF state of your device while in PRESS mode***/
// Add bots while in PRESS mode that will simulate ON/OFF. Default state will be used if no MQTT retained on state topic
// false = default state = OFF
// true = default state = ON
// If the state is incorrect, call set STATEOFF or STATEON
static std::map<std::string, bool> botsSimulateONOFFinPRESSmode = {
{ "switchbotone", false },
{ "switchbottwo", false },
{ "switchbotthree", false },
{ "switchbotfour", false }
};
//Add bots OFF hold time for simulated ON/OFF, if not in list, the current hold value will be used. Device must be in botsSimulateONOFFinPRESSmode list
static std::map<std::string, int> botsSimulatedOFFHoldTimes = {
/*{ "switchbotone", 0 },
{ "switchbottwo", 10 }*/
};
//Add bots ON hold time for simulated ON/OFF, if not in list, the current hold value will be used. Device must be in botsSimulateONOFFinPRESSmode list
static std::map<std::string, int> botsSimulatedONHoldTimes = {
/*{ "switchbotone", 15 },
{ "switchbottwo", 1}*/
};
/********************************************/
/********** ADVANCED SETTINGS - ONLY NEED TO CHANGE IF YOU WANT TO TWEAK SETTINGS **********/
/* ESP32 LED Settings */
#ifndef LED_BUILTIN
#define LED_BUILTIN 2 // If your board doesn't have a defined LED_BUILTIN, replace 2 with the LED pin value
#endif
static const bool ledHighEqualsON = true; // ESP32 board LED ON=HIGH (Default). If your ESP32 LED is turning OFF on scanning and turning ON while IDLE, then set this value to false
static const bool ledOnBootScan = true; // Turn on LED during initial boot scan
static const bool ledOnScan = true; // Turn on LED while scanning (non-boot)
static const bool ledOnCommand = true; // Turn on LED while MQTT command is processing. If scanning, LED will blink after scan completes. You may not notice it, there is no delay after scan
/* Webserver Settings */
static const bool useLoginScreen = false; // use a basic login popup to avoid unwanted access
static const String otaUserId = "admin"; // user Id for OTA update. Ignore if useLoginScreen = false
static const String otaPass = "admin"; // password for OTA update. Ignore if useLoginScreen = false
static WebServer server(80); // default port 80
/* Home Assistant Settings */
static const bool home_assistant_mqtt_discovery = true; // Enable to publish Home Assistant MQTT Discovery config
static const std::string home_assistant_mqtt_prefix = "homeassistant"; // MQTT Home Assistant prefix
static const bool home_assistant_expose_seperate_curtain_position = true; // When enabled, a seperate sensor will be added that will expose the curtain position. This is useful when using the Prometheus integration to graph curtain positions. The cover entity doesn't expose the position for Prometheus
static const bool home_assistant_use_opt_mode = true; // For bots in switch mode assume on/off right away. Optimistic mode. (Icon will change in HA). If devices were already configured in HA, you need to delete them and reboot esp32
/* Switchbot General Settings */
static const int tryConnecting = 60; // How many times to try connecting to bot
static const int trySending = 30; // How many times to try sending command to bot
static const int initialScan = 120; // How many seconds to scan for bots on ESP reboot and autoRescan. Once all devices are found scan stops, so you can set this to a big number
static const int infoScanTime = 60; // How many seconds to scan for single device status updates
static const int rescanTime = 10800; // Automatically perform a full active scan for device info of all devices every X seconds (default 3 hours). XXXXActiveScanSecs will also active scan on schedule
static const int queueSize = 50; // Max number of control/requestInfo/rescan MQTT commands stored in the queue. If you send more then queueSize, they will be ignored
static const int defaultBotWaitTime = 2; // wait at least X seconds between control command send to bots. ESP32 will detect if bot is in press mode with a hold time and will add hold time to this value per device
static const int defaultCurtainWaitTime = 0; // wait at least X seconds between control command send to curtains
static const int waitForResponseSec = 20; // How many seconds to wait for a bot/curtain response
static const int noResponseRetryAmount = 5; // How many times to retry if no response received
static const int defaultBotScanAfterControlSecs = 10; // Default How many seconds to wait for state/status update call after set/control command. *override with botScanTime list
static const int defaultCurtainScanAfterControlSecs = 30; // Default How many seconds to wait for state/status update call after set/control command. *override with botScanTime list. Also used by scanWhileCurtainIsMoving
static const int defaultBotMQTTUpdateSecs = 600; // Used only when alwaysMQTTUpdate = false. Default MQTT Update for bot every X seconds. Note: a change in state will be always be published either way during active scanning
static const int defaultCurtainMQTTUpdateSecs = 600; // Used only when alwaysMQTTUpdate = false. Default MQTT Update for curtain every X seconds. Note: a change in state will be always be published either way during active scanning
static const int defaultMeterMQTTUpdateSecs = 600; // Used only when alwaysMQTTUpdate = false. Default MQTT Update for meter temp sensors every X seconds. Note: a change in state will be always be published either way at all times (active or passive)
static const int defaultMotionMQTTUpdateSecs = 600; // Used only when alwaysMQTTUpdate = false. Default MQTT Update for motion sensors every X seconds. Note: a change in state will be always be published either way at all times (active or passive)
static const int defaultContactMQTTUpdateSecs = 600; // Used only when alwaysMQTTUpdate = false. Default MQTT Update for contact temp sensors every X seconds. Note: a change in state will be always be published either way at all times (active or passive)
static const int defaultPlugMQTTUpdateSecs = 600; // Used only when alwaysMQTTUpdate = false. Default MQTT Update for motion sensors every X seconds. Note: a change in state will be always be published either way at all times (active or passive)
static const int defaultBotActiveScanSecs = 1800; // Default Active Scan for bot every X seconds if not active scanned since X seconds. *override with botScanTime list.
static const int defaultCurtainActiveScanSecs = 1800; // Default Active Scan for curtain every X seconds if not active scanned since X seconds. *override with botScanTime list.
static const int defaultMeterActiveScanSecs = 3600; // Default Active Scan for meter temp sensors every X seconds if not active scanned since X seconds. *override with botScanTime list.
static const int defaultMotionActiveScanSecs = 3600; // Default Active Scan for motion sensors every X seconds if not active scanned since X seconds. *override with botScanTime list.
static const int defaultContactActiveScanSecs = 3600; // Default Active Scan for contact temp sensors every X seconds if not active scanned since X seconds. *override with botScanTime list.
static const int defaultPlugActiveScanSecs = 3600; // Default Active Scan for motion sensors every X seconds if not active scanned since X seconds. *override with botScanTime list.
static const int waitForMQTTRetainMessages = 10; // On boot ESP32 will look for retained MQTT state messages for X secs, otherwise default state is used. This is for bots in simulate ON/OFF, and when ESP32 mesh is used
static const int missedDataResend = 120; // Experimental. If a motion or contact is somehow missed while controlling bots, send the MQTT messages within X secs of it occuring as a backup. requires sendBackupMotionContact = true. Note: Not used if multiple ESP32s are meshed
static const int missedContactDelay = 30; // Experimental. If a contact is somehow missed while controlling bots, compare lastcontact from esp32 with contact sensor lastcontact. If different is greater than X, send a contact message. Note: Not used if multiple ESP32s are meshed
static const int missedMotionDelay = 30; // Experimental. If a motion is somehow missed while controlling bots, compare lastmotion from esp32 with motion/contact sensor lastmotion. If different is greater than X, send a motion message. Note: Not used if multiple ESP32s are meshed
static const bool sendBackupMotionContact = false; // Experimental. Compares last contact/motion time value from switchbot contact/motion devices against what the esp32 received. If ESP32 missed one while controlling bots, it will send a motion/contact message after. Note: Not used if multiple ESP32s are meshed
static const bool autoRescan = true; // perform automatic rescan (uses rescanTime and initialScan).
static const bool activeScanOnSchedule = true; // perform an active scan on decice types based on the scheduled seconds values for XXXXActiveScanSecs
static const bool scanAfterControl = true; // perform requestInfo after successful control command (uses botScanTime).
static const bool waitBetweenControl = true; // wait between commands sent to bot/curtain (avoids sending while bot is busy)
static const bool getSettingsOnBoot = true; // Currently only works for bot (curtain documentation not available but can probably be reverse engineered easily). Get bot extra settings values like firmware, holdSecs, inverted, number of timers. ***If holdSecs is available it is used by waitBetweenControl
static const bool retryBotOnBusy = true; // if bot responds with busy, the last control command will retry until success
static const bool retryCurtainOnBusy = true; // if curtain responds with busy, the last control command will retry until success
static const bool retryPlugOnBusy = true; // if plug responds with busy, the last control command will retry until success
static const bool retryBotActionNoResponse = false; // Retry if bot doesn't send a response. Bot default is false because no response can still mean the bot triggered.
static const bool retryPlugActionNoResponse = true; // Retry if plug doesn't send a response. Default is true. It shouldn't matter if plug receives the same command twice (or multiple times)
static const bool retryBotSetNoResponse = true; // Retry if bot doesn't send a response when requesting settings (hold, firwmare etc) or settings hold/mode
static const bool retryCurtainNoResponse = true; // Retry if curtain doesn't send a response. Default is true. It shouldn't matter if curtain receives the same command twice (or multiple times)
static const bool immediateBotStateUpdate = true; // ESP32 will send ON/OFF state update as soon as MQTT is received. You can set this = false if not using Home Assistant Discovery.
static const bool immediatePlugStateUpdate = true; // ESP32 will send ON/OFF state update as soon as MQTT is received. You can set this = false if not using Home Assistant Discovery.
static const bool immediateCurtainStateUpdate = true; // ESP32 will send OPEN/CLOSE and Position state update as soon as MQTT is received. You can set this = false if not using Home Assistant Discovery.
static const bool assumeNoResponseMeansSuccess = true; // Only for bots in simulated ON/OFF: If the ESP32 does not receive a response after sending command (after noResponseRetryAmount reached and retryBotActionNoResponse = true) assume it worked and change state
static const bool alwaysMQTTUpdate = false; // If the ESP32 is scanning, always publish MQTT data instead of using set times. ***Note: This creates a lot of MQTT traffic
static const bool onlyActiveScan = false; // Active scanning requires more battery from the BLE switchbot devices. If false, passive scanning is used when possible for contact/motion
static const bool onlyPassiveScan = false; // If this ESP32 is a mesh ESP32 or you only have motion/contact/meter sensors. Passive scanning uses less battery from BLE switchbot devices. Passive scanning provides less data then active scanning, but uses less battery
static const bool alwaysActiveScan = false; // No battery optimizations. If you are using the switchbot hub or app to control devices also and you want immediate state updates for bot and curtains in MQTT set to true
static const bool scanWhileCurtainIsMoving = true; // The ESP32 will scan for defaultCurtainScanAfterControlSecs seconds after control to keep the position slider in sync with the actual position
static const bool printSerialOutputForDebugging = false; // Only set to true when you want to debug an issue from Arduino IDE. Lots of Serial output from scanning can crash the ESP32