Run daily at sunset

I know I’ve seen this out here before, but for the life of me I can’t find it right now.

I want to schedule something to run every night at sunset.

self.tun_daily(“begin_nighttime”,self.sunset()) Right???

It didn’t work??

what is it that you need to run? easier for me to write you something.

https://community.home-assistant.io/t/appdaemon-q-a/3028/61

import appdaemon.appapi as appapi
             
class sunrise_sunset(appapi.AppDaemon):

  def initialize(self):
    self.log("Night Setup")
    self.run_daily("begin_nighttime",self.sunset())
    self.run_daily("begin_morning",self.sunrise())

  def begin_nighttime(self, kwargs):
    self.log("Sunset")
    self.turn_on("switch.garage_carriage_lights")

  def begin_morning(self, kwargs):
    self.log("Sunrise")
    self.turn_off("switch.garage_carriage_lights")
(hass) hass@hass:~/appdaemon/conf/apps$

duuuuh callback shouldn’t be in quotes should it. LOL

print the API or set it in your favs :wink:

Yea, that’s what happens when you think you remember it and are typing fast trying to get it finished before sunset.

1 Like

You can also use the run_at_sunset() api

but I think run_at_sunset is a one time event, you would have to re-schedule it every time it runs. by using run_daily, it registers when the app starts and I don’t have to re-schedule it later. Right??

I thought so too but @ReneTode proved that is not the case, just the documentation isn’t really clear on that, look at his schedule example in the forums.

run_at_sunset, run_at_sunrise, run_daily, run_hourly, run_minutely, run_every, are all schedulars that keep on running untill stopped.
only run_at and run_once are schedulars that run 1 time.

those out of the first list are best for in the initialize.
the last 2 are very good for inside the call_backs.

Awesome,
thanks