How to say "make sure the light is on when the sun is down"?

I am using AppDaemon to manage my home scenarios and would like to ensure that a light is off when the sun is down.

I know about:

  • run_at_sunset() which starts a callback once at the moment the sun sets down. This is fine if AppDaemon happens to run at that moment, but if for some reason the sun set is missed, the callback is not called.
  • sun_down() which checks whether the sun is down. It has to be called periodically in my scenario.

Is the solution to “make sure the light is on when the sun is down” to check every sun_down() or is there a concept of “state warranty” which would do the job?

if you use appdaemon for automations then appdaemon is running all the time unless you have done something wrong.

in theory you could start a minutely check if you had a problem before, but you shouldnt.
if you did take appdaemon offline to do something and it misses the call, do it manually
if you have an error correct it.
if appdaemon stopped because you did something terribly wrong it wont check anything anyway.

I think what you want to do is add a startup trigger. That way when HA starts up, you can check your conditions (is the sun down and the light off) and update the state. I haven’t tried it but I think you can just add that code to your initialize() method which is called at start up.