Error with run at Sunrise

Hi seeing this error just recently for an app that runs at sunrise.
the error is

2019-10-20 12:55:00.709087 WARNING AppDaemon: ------------------------------------------------------------
2019-10-20 13:50:42.150298 WARNING AppDaemon: ------------------------------------------------------------
2019-10-20 13:50:42.169408 WARNING AppDaemon: Unexpected error running initialize() for auto_turn_on_motion_senors_sunrise
2019-10-20 13:50:42.170964 WARNING AppDaemon: ------------------------------------------------------------
2019-10-20 13:50:42.197463 WARNING AppDaemon: Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py”, line 1581, in init_object
init()
File “/conf/apps/auto_turn_on_sunrise.py”, line 17, in initialize
self.run_at_sunrise(self.sunrise_t)
File “/usr/local/lib/python3.6/site-packages/appdaemon/appapi.py”, line 442, in run_at_sunrise
handle = self.schedule_sun(name, “next_rising”, callback, **kwargs)
File “/usr/local/lib/python3.6/site-packages/appdaemon/appapi.py”, line 420, in schedule_sun
event = self.calc_sun(type
)
File “/usr/local/lib/python3.6/site-packages/appdaemon/appapi.py”, line 261, in calc_sun
return self.AD.calc_sun(type
)
File “/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py”, line 897, in calc_sun
return self.sun[type_].timestamp()
KeyError: ‘next_rising’

my app is below

import appdaemon.plugins.hass.hassapi as hass
import datetime
import random
import globals
#
# App to turn lights on after sunset then turn off a time later
#
# Args:
#lights : entity to turn on
#delayoff: time after sunset to turn off


class AutoTurnOnSunrise(hass.Hass):

    def initialize(self):
        self.handle = None
        self.run_at_sunrise(self.sunrise_t)
        self.utility = self.get_app("utilities")
    def sunrise_t(self, kwargs):

        for light in self.args["lights"]:
            self.turn_on(light)
            notifymessage = "{} turned on standard Light at sunset".format(light)
            self.sendNotifcation(notifymessage)

    def turnOff(self, kwargs):
        for light in self.args["lights"]:
            self.turn_off(light)
            notifymessage = "It is late - Turned off {}".format(light) 
            self.sendNotifcation(notifymessage)

    def sendNotifcation(self, notifyMessage):
        
        self.utility.send_notification(notifyMessage)      


auto_turn_on_motion_senors_sunrise:
   module: auto_turn_on_sunrise
   class: AutoTurnOnSunrise
   global_dependencies: globals
   dependencies: 
     - utilities
  lights:
    - input_boolean.emily_motion_sensor
    - input_boolean.zara_motion_sensor
    - input_boolean.laura_motion_sensor

This is a timing issue, home assistant is not ready when AppDaemon starts.

Take a look at this issue:

https://github.com/home-assistant/appdaemon/issues/411

There are solutions in there.

1 Like