Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b5026a5
[GPIO][P001] Added “Wake on Button Press” functionality.
chromoxdor Mar 20, 2026
b1abf4a
[P001] Switched to EXT1 for all devices for lowest power consumption
chromoxdor Mar 21, 2026
cedc78d
[P001] changed a line according to Tons suggestion
chromoxdor Mar 21, 2026
6f3544a
[GPIO] Setting moved to Hardware tab
chromoxdor Mar 22, 2026
9cdac4d
[GPIO] Setting moved to Hardware tab (removes unnecessary functions)
chromoxdor Mar 22, 2026
3b5d8c7
[GPIO] add check for gpiowake event
chromoxdor Mar 22, 2026
ac6ece0
[GPIO] fixed a c&p mistake
chromoxdor Mar 22, 2026
2365dff
[GPIO] adding details expansion + rules-keywords
chromoxdor Mar 23, 2026
3e6c299
[GPIO] adding all the missing bits and pieces.
chromoxdor Mar 28, 2026
1ca3eb5
[GPIO] adding all the missing bits and pieces part 2
chromoxdor Mar 28, 2026
90a2071
[GPIO] adding all the missing bits and pieces part 3
chromoxdor Mar 29, 2026
e21f2ca
[GPIO] adding all the missing bits and pieces part 4
chromoxdor Mar 29, 2026
22a1649
[GPIO] adding all the missing bits and pieces part 5
chromoxdor Mar 29, 2026
1a5be1f
[GPIO] adding all the missing bits and pieces part 6
chromoxdor Mar 29, 2026
77a6f2b
[GPIO] adding all the missing bits and pieces part 7
chromoxdor Mar 29, 2026
749d9a3
[GPIO] adding all the missing bits and pieces part 8
chromoxdor Mar 30, 2026
37eaa99
[GPIO] adding all the missing bits and pieces part 9
chromoxdor Mar 30, 2026
839d30e
[GPIO] adding all the missing bits and pieces part 10
chromoxdor Mar 30, 2026
50f9811
[GPIO] adding all the missing bits and pieces part 11
chromoxdor Mar 30, 2026
f74635f
Merge branch 'mega' into GPIO]-P001]-add-wake-from-sleep-option
chromoxdor Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/_P001_Switch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

# include "src/PluginStructs/P001_data_struct.h"

# ifdef ESP32
# include "esp_sleep.h"
# if defined(CONFIG_IDF_TARGET_ESP32) || \
defined(CONFIG_IDF_TARGET_ESP32S2) || \
defined(CONFIG_IDF_TARGET_ESP32S3)
# include "driver/rtc_io.h"
# endif // if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
void setupGpioWakeup(uint8_t pin,
bool wakeOnLow = true); // if ever needed we can also add support for wakeOnHigh, but for now
// when using a switch/button, the wakeup will be triggered by the pin going low (active
// low)
# endif // ifdef ESP32

// #######################################################################################################
// #################################### Plugin 001: Input Switch #########################################
// #######################################################################################################
Expand Down Expand Up @@ -125,6 +138,14 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
P001_LP_MIN_INT,
P001_SAFE_BTN);

# ifdef ESP32

if (esp_sleep_is_valid_wakeup_gpio((gpio_num_t)CONFIG_PIN1)) {
Comment thread
chromoxdor marked this conversation as resolved.
Outdated
addFormCheckBox(F("Wake from sleep"), F("sw_wake"), P001_WAKE_BTN);
addFormNote(F("Make sure to enable the internal pull-up resistor or add an external pull-up resistor!"));
}
# endif // ifdef ESP32

# if FEATURE_MQTT_DISCOVER && FEATURE_MQTT_DEVICECLASS

if (switchtype != PLUGIN_001_TYPE_DIMMER) {
Expand Down Expand Up @@ -160,6 +181,13 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
P001_LP_MIN_INT,
P001_SAFE_BTN);

# ifdef ESP32

if (esp_sleep_is_valid_wakeup_gpio((gpio_num_t)CONFIG_PIN1)) {
P001_WAKE_BTN = isFormItemChecked(F("sw_wake"));
}
# endif // ifdef ESP32

# if FEATURE_MQTT_DISCOVER && FEATURE_MQTT_DEVICECLASS
P001_MQTT_DEVICECLASS = getFormItemInt(F("devcls"));
# endif // if FEATURE_MQTT_DISCOVER && FEATURE_MQTT_DEVICECLASS
Expand Down Expand Up @@ -190,10 +218,34 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{

// apply INIT only if PORT is in range. Do not start INIT if port not set in the device page.
if (validGpio(CONFIG_PIN1))
{
success = initPluginTaskData(event->TaskIndex, new (std::nothrow) P001_data_struct(event));

# ifdef ESP32

// https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/api-reference/system/sleep_modes.html#external-wakeup-ext0
# if defined(CONFIG_IDF_TARGET_ESP32) || \
defined(CONFIG_IDF_TARGET_ESP32S2) || \
defined(CONFIG_IDF_TARGET_ESP32S3)
Comment thread
chromoxdor marked this conversation as resolved.
Outdated

// this would need adaption if we ever want to support wakeOnHigh as well
// if (wakeOnLow) {
rtc_gpio_pullup_dis((gpio_num_t)CONFIG_PIN1);

// } else {
// rtc_gpio_pulldown_dis(gpio);
// }
rtc_gpio_deinit((gpio_num_t)CONFIG_PIN1);
# endif // if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)

if (P001_WAKE_BTN) {
setupGpioWakeup(CONFIG_PIN1, true);
}
# endif // ifdef ESP32

}
break;
}
Expand Down Expand Up @@ -248,4 +300,44 @@ boolean Plugin_001(uint8_t function, struct EventStruct *event, String& string)
return success;
}

# ifdef ESP32

void setupGpioWakeup(uint8_t pin, bool wakeOnLow) {
Comment thread
chromoxdor marked this conversation as resolved.
Outdated
gpio_num_t gpio = static_cast<gpio_num_t>(pin);

pinMode(pin, wakeOnLow ? INPUT_PULLUP : INPUT_PULLDOWN);

if (esp_sleep_is_valid_wakeup_gpio(gpio)) {
# if defined(CONFIG_IDF_TARGET_ESP32) || \
defined(CONFIG_IDF_TARGET_ESP32S2) || \
defined(CONFIG_IDF_TARGET_ESP32S3)

// Configure RTC pull resistors
if (wakeOnLow) {
rtc_gpio_pullup_en(gpio);
} else {
rtc_gpio_pulldown_en(gpio);
}

esp_sleep_enable_ext0_wakeup(gpio, wakeOnLow ? 0 : 1);

# elif defined(CONFIG_IDF_TARGET_ESP32C2) || \
defined(CONFIG_IDF_TARGET_ESP32C3) || \
defined(CONFIG_IDF_TARGET_ESP32C6)

uint64_t mask = 1ULL << gpio;

esp_deep_sleep_enable_gpio_wakeup(
mask,
wakeOnLow ? ESP_GPIO_WAKEUP_GPIO_LOW : ESP_GPIO_WAKEUP_GPIO_HIGH
);

# else // if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
# warning "Unknown ESP32 target — GPIO wakeup not configured"
# endif // if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
}
}

# endif // ifdef ESP32

#endif // USES_P001
4 changes: 3 additions & 1 deletion src/src/Helpers/_Plugin_Helper_GPIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ GPIO_plugin_helper_data_t::GPIO_plugin_helper_data_t(
bool safeButton,
bool sendBootState,
uint8_t switchType,
uint8_t dimmerValue) :
uint8_t dimmerValue,
bool wakeButton) :
_portStatus_key(createKey(pluginNumber, pin)),
_debounceInterval_ms(debounceInterval_ms),
_doubleClickMaxInterval_ms(doubleClickMaxInterval_ms),
Expand All @@ -32,6 +33,7 @@ GPIO_plugin_helper_data_t::GPIO_plugin_helper_data_t(
_switchType(switchType),
_dimmerValue(dimmerValue),
_safeButton(safeButton),
_wakeButton(false),
Comment thread
chromoxdor marked this conversation as resolved.
Outdated
_sendBootState(sendBootState),
_longpressFired(false)
{
Expand Down
4 changes: 3 additions & 1 deletion src/src/Helpers/_Plugin_Helper_GPIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct GPIO_plugin_helper_data_t {
bool safeButton,
bool sendBootState,
uint8_t switchType = SWITCH_TYPE_NORMAL_SWITCH,
uint8_t dimmerValue = 0);
uint8_t dimmerValue = 0,
bool wakeButton = false);

~GPIO_plugin_helper_data_t();

Expand Down Expand Up @@ -66,6 +67,7 @@ struct GPIO_plugin_helper_data_t {
const uint8_t _dimmerValue;
const bool _safeButton;
const bool _sendBootState;
const bool _wakeButton;
bool _longpressFired;
};

Expand Down
3 changes: 2 additions & 1 deletion src/src/PluginStructs/P001_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ P001_data_struct::P001_data_struct(struct EventStruct *event) :
P001_SAFE_BTN != 0,
P001_BOOTSTATE,
(P001_getSwitchType(event) == PLUGIN_001_TYPE_DIMMER) ? SWITCH_TYPE_DIMMER : P001_BUTTON_TYPE,
P001_DIMMER_VALUE)
P001_DIMMER_VALUE,
P001_WAKE_BTN)
{
uint8_t pinModeValue = PIN_MODE_INPUT;

Expand Down
1 change: 1 addition & 0 deletions src/src/PluginStructs/P001_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# define P001_LONGPRESS PCONFIG(5)
# define P001_LP_MIN_INT PCONFIG_FLOAT(2)
# define P001_SAFE_BTN PCONFIG_FLOAT(3)
# define P001_WAKE_BTN PCONFIG_FLOAT(7)

# if FEATURE_MQTT_DISCOVER && FEATURE_MQTT_DEVICECLASS
# define P001_MQTT_DEVICECLASS PCONFIG(6)
Expand Down