Skip to content

Calculate DeepSleepTime wake time #20042

Answered by smhc
smhc asked this question in Q&A
Nov 17, 2023 · 8 comments · 17 replies
Discussion options

You must be logged in to vote

This is a bit of berry code that will sleep until a specific time:

import math
import string
def sleep_until(target)
    var curtime = tasmota.rtc()["local"]

    var ds = 60
    for i: 1 .. 10000
        var wake = (((curtime / ds) + 1) * ds ) + (ds * 0.05)
        if (math.abs(wake - target) < 600)
            # print('sleep time: ', ds, i)
            tasmota.cmd(string.format("DeepSleepTime %d", ds))
            return i
        end
        if (i % 1000 == 0)
            tasmota.yield()
        end
        ds += 60
    end
    print('not found..')
end
# Sleep until 12 hours after the current time
sleep_until(tasmota.rtc()["local"] + (3600 * 12))

It's not that efficient, and would need…

Replies: 8 comments 17 replies

Comment options

You must be logged in to vote
2 replies
@stefanbode
Comment options

@smhc
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
10 replies
@smhc
Comment options

@smhc
Comment options

@stefanbode
Comment options

@smhc
Comment options

@stefanbode
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@sfromis
Comment options

@smhc
Comment options

Answer selected by smhc
Comment options

You must be logged in to vote
3 replies
@stefanbode
Comment options

@stefanbode
Comment options

@stefanbode
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants