Having trouble with AppDaemon and sunsets

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.

Appreciate the help!

I don’t have an answer for you but I have the same issue with the same setup, Appdaemon in a docker container.

In my case the time is out by about 10 hours:

2017-08-13 01:03:55.068671 INFO frontyardlighton: Next sunset at 2017-08-13 07:43:06

What are your timezones? The time zone is usually derived from homeassistant

My timezone is America/Denver – as you note, I’m not defining that in appdaemon.yaml, so I assume it’s coming directly from HASS?

mine is Australia/Melbourne

you can override with the time zone directive in the AppDaemon section of the config file, have you tried that?

Yes sir – didn’t seem to make a difference: the logs seems to show the same strange distance.

I have also tried that.

My current time is 11:24am and I just updated appdaemon.yaml and the log file showed the following if this helps.

2017-08-13 01:24:22.008205 INFO /conf/appdaemon.yaml modified

just as an FYI

HASS is also running in a docker container and it’s log files also show it’s 1:30am

but the logbook in HASS is correct …

@bachya I just found some information that may work :slight_smile:

when running your container add the following on the command line

  -v /etc/localtime:/etc/localtime:ro

this now gives me the following in the log

2017-08-13 12:50:04.338891 INFO frontyardlighton: Next sunset at 2017-08-13 17:43:31

which is my correct sunset time :slight_smile:

@aimc you might want to add this to your docker comments

Darn, unfortuntely, I’m already using that:

volumes:
  - /etc/docker/appdaemon:/config
  - /etc/localtime:/etc/localtime:ro

(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.

mine is running on a Synology NAS with the OS being DSM 6.1.3-15152 Update 1

what do your HASS log files say ?

Nothing out of the ordinary; all of the timestamps appear in my local timezone.

I assume that on your NAS, date outputs the same thing on the host and in the container?

no, it appears only the container’s are not in sync with the OS, HASS shows the same datetime as Appdaemon, eg: 10hrs behind

Interesting! Still hunting…

Thanks - I will :slight_smile:

Well, my automation fired at the correct time today. Walking away slowly… :joy:

1 Like

good to hear :slight_smile:

1 Like

@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.

@aimc, does that make any sense?

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.