diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index cb72ff407..b220dc4b3 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -4,6 +4,7 @@ * Add support for PCA9685 12bit 16pin hardware PWM driver (#3866) * Add power value below 5W to Sonoff Pow R2 and S31 (#3745) * Add force_update to Home Assistant discovery (#3873) + * Fix rule trigger POWER1#STATE execution after restart and SetOption0 is 0 (#3856) * * 6.2.1.5 20180921 * Add authentication to HTTP web pages diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 80356d475..c3d514f0c 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -203,7 +203,7 @@ enum LichtSubtypes {LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_R enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX}; enum XsnsFunctions {FUNC_PRE_INIT, FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, FUNC_PREP_BEFORE_TELEPERIOD, - FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SHOW_SENSOR, + FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_RULE_INIT_POWER, FUNC_SHOW_SENSOR, FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM}; const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 }; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index b5d752a3b..a405fe47b 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -335,7 +335,8 @@ void SetDevicePower(power_t rpower, int source) } } - XdrvSetPower(rpower); + XdrvMailbox.index = rpower; + XdrvCall(FUNC_SET_POWER); if ((SONOFF_DUAL == Settings.module) || (CH4 == Settings.module)) { Serial.write(0xA0); @@ -2613,6 +2614,9 @@ void setup() } } + XdrvMailbox.index = power; + XdrvCall(FUNC_RULE_INIT_POWER); + blink_powersave = power; snprintf_P(log_data, sizeof(log_data), PSTR(D_PROJECT " %s %s (" D_CMND_TOPIC " %s, " D_FALLBACK " %s, " D_CMND_GROUPTOPIC " %s) " D_VERSION " %s-" ARDUINO_ESP8266_RELEASE), diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 930bde7d5..5ef59c037 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -628,6 +628,7 @@ boolean Xdrv10(byte function) case FUNC_EVERY_SECOND: RulesEverySecond(); break; + case FUNC_RULE_INIT_POWER: case FUNC_SET_POWER: RulesSetPower(); break; diff --git a/sonoff/xdrv_interface.ino b/sonoff/xdrv_interface.ino index 43a391076..a88d3b5f8 100644 --- a/sonoff/xdrv_interface.ino +++ b/sonoff/xdrv_interface.ino @@ -153,14 +153,6 @@ boolean XdrvCommand(uint8_t grpflg, char *type, uint16_t index, char *dataBuf, u return XdrvCall(FUNC_COMMAND); } -void XdrvSetPower(power_t mpower) -{ -// XdrvMailbox.valid = 1; - XdrvMailbox.index = mpower; - - XdrvCall(FUNC_SET_POWER); -} - boolean XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf) { XdrvMailbox.index = stopicBuf;