diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 4b394dc79..bdc84b6ea 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,7 @@ /* 6.5.0.11 20190517 * Add command SetOption64 0/1 to switch between "-" or "_" as sensor index separator impacting DS18X20, DHT, BMP and SHT3X sensor names (#5689) * Add initial support for Scripts as replacement for Rules. Default disabled but can be enabled in my_user_config.h (#5689) + * Add rule System#Save executed just before a planned restart * * 6.5.0.10 20190513 * Enable ADC0 by default in my_user_config.h (#5671) diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 142f3f234..7b3e4d316 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -587,6 +587,16 @@ void RulesEverySecond(void) } } +void RulesSaveBeforeRestart(void) +{ + if (Settings.rule_enabled) { // Any rule enabled + char json_event[32]; + + strncpy_P(json_event, PSTR("{\"System\":{\"Save\":1}}"), sizeof(json_event)); + RulesProcessEvent(json_event); + } +} + void RulesSetPower(void) { rules_new_power = XdrvMailbox.index; @@ -1279,6 +1289,9 @@ bool Xdrv10(uint8_t function) case FUNC_RULES_PROCESS: result = RulesProcess(); break; + case FUNC_SAVE_BEFORE_RESTART: + RulesSaveBeforeRestart(); + break; #ifdef SUPPORT_MQTT_EVENT case FUNC_MQTT_DATA: result = RulesMqttData();