Skip to content

Commit

Permalink
Restart 9 support deepsleep with TIMER based wakeup (arendst#20165)
Browse files Browse the repository at this point in the history
* Allow restart 9 to use TIMERS for wakeup

* support for restart 9

allow restart 9 to use any defined TIMER to restart a a specific time.
  • Loading branch information
stefanbode authored Dec 5, 2023
1 parent 728f91b commit f19d156
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions tasmota/tasmota_support/support_wifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,12 @@ void EspRestart(void) {
}
}
else if (TasmotaGlobal.restart_deepsleep) { // Restart 9
#ifdef USE_DEEPSLEEP
DeepSleepStart();
// should never come to this line....
#endif
ESP.deepSleep(0); // Deep sleep mode with only hardware triggered wake up

}
else {
ESP_Restart();
Expand Down
8 changes: 5 additions & 3 deletions tasmota/tasmota_xdrv_driver/xdrv_29_deepsleep.ino
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void DeepSleepCalculate()
// day_bitarray>0 otherwhise no weekday selected
// rule keyword "Wakeup"
// Timer action: rule
if (xtimer.arm && day_bitarray && GetRule(0) == "Wakeup" && bitRead(Settings->rule_enabled | Settings->rule_once, 0) && POWER_BLINK == xtimer.power) {
if (xtimer.arm && day_bitarray && GetRule(0) == "Wakeup" && (TasmotaGlobal.restart_deepsleep || bitRead(Settings->rule_enabled | Settings->rule_once, 0)) && POWER_BLINK == xtimer.power) {
#ifdef USE_SUNRISE
if ((1 == xtimer.mode) || (2 == xtimer.mode)) { // Sunrise or Sunset
ApplyTimerOffsets(&xtimer);
Expand Down Expand Up @@ -210,7 +210,7 @@ void DeepSleepStart(void)
AddLog(LOG_LEVEL_DEBUG, PSTR("DSL: Time %ld, next %ld, slip %ld"), timeslip, RtcSettings.nextwakeup, RtcSettings.deepsleep_slip );
// It may happen that wakeup in just <5 seconds in future
// In this case also add deepsleep to nextwakeup
if (RtcSettings.nextwakeup <= (LocalTime() + DEEPSLEEP_MIN_TIME)) {
if (RtcSettings.nextwakeup <= (LocalTime() + DEEPSLEEP_MIN_TIME) && Settings->deepsleep > 0 ) {
// ensure nextwakeup is at least in the future, and add 5%
RtcSettings.nextwakeup += (((LocalTime() + DEEPSLEEP_MIN_TIME - RtcSettings.nextwakeup) / Settings->deepsleep) + 1) * Settings->deepsleep;
//RtcSettings.nextwakeup += Settings->deepsleep * 0.05;
Expand All @@ -223,7 +223,9 @@ void DeepSleepStart(void)
}
// Limit sleeptime to DEEPSLEEP_MAX_CYCLE
// uint32_t deepsleep_sleeptime = DEEPSLEEP_MAX_CYCLE < (RtcSettings.nextwakeup - LocalTime()) ? (uint32_t)DEEPSLEEP_MAX_CYCLE : RtcSettings.nextwakeup - LocalTime();
deepsleep_sleeptime = tmin((uint32_t)DEEPSLEEP_MAX_CYCLE ,RtcSettings.nextwakeup - LocalTime());
deepsleep_sleeptime = tmin((uint32_t)DEEPSLEEP_MAX_CYCLE ,RtcSettings.nextwakeup>0?RtcSettings.nextwakeup - LocalTime():0);



// Sending Deepsleep parameters to automation for react
Response_P(PSTR("{\"" D_PRFX_DEEPSLEEP "\":{\"" D_JSON_TIME "\":\"%s\",\"" D_PRFX_DEEPSLEEP "\":%d,\"Wakeup\":%d}}"), (char*)dt.c_str(), LocalTime(), RtcSettings.nextwakeup);
Expand Down

0 comments on commit f19d156

Please sign in to comment.