Simple python questions

I hate date math. I want to check every 5 or 10 minutes to see if an event has cleared, do something and stop checking. I’ve got a simple loop.

def turn_off_lights
if event is active
self.run_at(turn_off_lights,now+10minutes)
else
turn_off(lights)

I could do it with a run_minutely and then cancel the handle when the event clears, but at this point, I’m determined to figure out the math. I see several examples of adding an offset to sunrise or sunset. I’m just having trouble finding one that shows me how to do “now”+10.

you use the wrong statement :wink:
just use:

self.run_in(self.callback,60*10)

if you want something to run in 10 minutes.

offset with Sunrise and sunset is also in seconds. you use it like:

self.run_at_sunset(self.callback,offset=15*60)

isnt it easier to listen to the event with a listen_state or listen_event, the to use a run_minutely and check if it has cleared?

in any other case where you want to calculate with time you can use:

time = datetime.datetime.now() + datetime.timedelta(hours=2)

like i said to you before:
print out the API from appdaemon!
https://github.com/home-assistant/appdaemon/blob/master/API.md

You are right, I did not notice the run_in statement. I have three web browser tabs open all the time. HA, HA Forums, and the AppDeamon API. It would be nice if the API was indexed or had a linked table of contents. The font sizes are so similar it’s easy to skip over something.

im working on that as we speak :wink:

Awesome, let me know if I can help.

not really.
would have liked to have it ready already, but dont think i will make it before Christmas.
if i dont make it tonight it will be Tuesday.

i made it.

http://appdaemon.reot.org/

commandlist now online.

1 Like