diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index e581d887..eeb042b8 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -196,6 +196,9 @@ PROGMEM const char* const custom_reset_string[] = { // Pulse with in milliseconds for a latched relay #define RELAY_LATCHING_PULSE 10 +// Do not save relay state after these many milliseconds +#define RELAY_SAVE_DELAY 1000 + //------------------------------------------------------------------------------ // I18N //------------------------------------------------------------------------------ diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 0bdb26d4..d2dd39ae 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -29,6 +29,7 @@ typedef struct { } relay_t; std::vector _relays; bool recursive = false; +Ticker _relaySaveTicker; #if RELAY_PROVIDER == RELAY_PROVIDER_DUAL unsigned char _dual_status = 0; @@ -528,7 +529,7 @@ void relayLoop(void) { if (!recursive) { relayPulse(id); relaySync(id); - relaySave(); + _relaySaveTicker.once_ms(RELAY_SAVE_DELAY, relaySave); #if WEB_SUPPORT relayWS(); #endif