Hello – trying out AppDaemon with a basic “turn on the lights at sunset app”:
"""Define automations for evening-time lighting."""
import appdaemon.appapi as appapi
class LivingRoomLights(appapi.AppDaemon):
"""Define a class to represent the app."""
def initialize(self):
"""Initialize."""
self.log('Next sunset at ' + str(self.sunset()))
self.run_at_sunset(self.sunset_cb)
def sunset_cb(self, kwargs):
"""Turn on the lights when the correct time hits."""
self.log('LivingRoomLights: Sunset triggered')
self.turn_on('group.living_room_lights')
After running in both real time and using Time Travel, the callback never fires. Looking at the logs, it seems like the sunset calculation is off:
2017-08-12 23:33:05.482905 INFO evening_living_room_lights: Next sunset at 2017-08-14 01:58:10
Looking at the timestamps (which I understand to be in UTC and derived from the timezone set in the HASS config file), it looks like the next sunset is more than 24 hours away (when, in reality, it’s only 2 hours away).
FYI, I’m running AppDaemon in a Docker container whose timestamp shows my correct local time.
(I’m using docker-compose, but the idea is the same)
Here’s what’s interesting: if I look at my log file, it looks like it starts out with my local time, but when AppDaemon actually connects, it switches over to UTC. Sadly, the sunset timing still appears really off:
2017-08-12 17:32:53.927921 WARNING Unable to connect to Home Assistant, retrying in 5 seconds
2017-08-12 17:32:58.953285 WARNING Unable to connect to Home Assistant, retrying in 5 seconds
2017-08-12 23:33:05.217525 INFO Got initial state
2017-08-12 23:33:05.220544 INFO Loading Module: /config/apps/evening_lights.py
2017-08-12 23:33:05.223265 INFO Loading Object evening_living_room_lights using class LivingRoomLights from module evening_lights
2017-08-12 23:33:05.482905 INFO evening_living_room_lights: Next sunset at 2017-08-14 01:58:10
2017-08-12 23:33:05.483910 INFO App initialization complete
2017-08-12 23:33:05.485120 INFO Dashboards are disabled
2017-08-12 23:33:05.732843 INFO Connected to Home Assistant 0.50.2
Can I ask: what hardware is your container running on? I’m a Raspberry Pi 3 and am wondering if something is off with regard to locales, etc.
@drak41 and @aimc – this evening, my sunset automation didn’t fire. I was doing some work earlier in the evening and restarted AppDaemon; wondering if, after the reload, AppDaemon somehow skipped over this evening’s sunset and now sees tomorrow’s sunset as the next.
That’s not how it is designed - when you restart AD, all apps will have their initialise() called, which should recreate the scheduler entry for Sunset.