Run at sunset and time travel - Hassio

HI,
Getting a little lost and frustrated here:

  1. I have an AD app for running some lights at sunset, should be straightforward but it is not firing at sunset. All yaml automation work at sunset so I know it is not a HA issue
def initialize(self):
    self.handle = None

    self.run_at_sunset(self.sunset_trigger)

def sunset_trigger(self, entity, attribute, old, new):
    rnd_brightness = random.randint(80, 200)
    delay = self.args["delayoff"]
    if self.args["rgb"] == "random":
      rgb = self.getLightColour()
    else:
      rgb = self.args["rgb"]
    self.log("color {}".format(rgb))
    for light in self.args["lights"]:
        device, entity = self.split_entity(light)
        if device == "light":
            #rgb_color = rand_rgb_color
            self.turn_on(
                light,
                rgb_color = rgb,
                effect = "solid",
                brightness=rnd_brightness)
        else:
            self.turn_on(light)
        self.log("It is sunset - Turned on {}".format(light))
    self.cancel_timer(self.handle)
    self.handle = self.run_in(self.turnOff(), delay)

the other frustrating thing is I am not sure how to get Time Travel working on Hassio - which will help me debug the issue above. The command appdaemon -s “2018-02-16 19:16:00” doesn’t work. How do I run this under Hassio

i dont think that options like timetravel will work on a hassio environment.
you have to be able to run a terminal in the appdaemon docker and stop the appdaemon process from hassio and run appdaemon manually to use timetravel.

you have chosen hassio which is a platform for inexperienced users and advanced options from a lot off programs are not available on that.

can you show us

  1. the complete app,
  2. what is in the yaml and where
  3. what is in the logs from the moment you start up appdaemon
  4. what is in appdaemon.yaml

Hi, thanks for the fast reply.
I am going from the next level with HA. I have embraced AppDaemon and converted most of my automation and finding it really great.
here is the detail as requested
complete App:

import appdaemon.appapi as appapi
import datetime
import random
#
#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 AutoTurnOnOffSunset(appapi.AppDaemon):

def initialize(self):
    self.handle = None

    self.run_at_sunset(self.sunset_trigger)

def sunset_trigger(self, entity, attribute, old, new):
    rnd_brightness = random.randint(80, 200)
    delay = self.args["delayoff"]
    if self.args["rgb"] == "random":
      rgb = self.getLightColour()
    else:
      rgb = self.args["rgb"]
    self.log("color {}".format(rgb))
    for light in self.args["lights"]:
        device, entity = self.split_entity(light)
        if device == "light":
            #rgb_color = rand_rgb_color
            self.turn_on(
                light,
                rgb_color = rgb,
                effect = "solid",
                brightness=rnd_brightness)
        else:
            self.turn_on(light)
        self.log("It is sunset - Turned on {}".format(light))
    self.cancel_timer(self.handle)
    self.handle = self.run_in(self.turnOff(), delay)

def turnOff(self, entity, attribute, old, new):
    for light in self.args["lights"]:
        self.turn_off(light)
        self.log("It is after sunset - Turned off {}".format(light))
def getLightColour():
    # determine a random RGB value for Fun to set the light this color
      random.seed()
      R = random.randint(1, 254)
      B = random.randint(1, 254)
      G = random.randint(1, 254)
      rgb = [R,G,B]
      return rgb  
def cancel(self):
    self.cancel_timer(self.handle) 

app.yaml

auto_turn_on_off_front_garden_lights:
  module: auto_turn_on_off_sunset
  class: AutoTurnOnOffSunset
  lights:
    - switch.front_garden_light
    - light.study_strip_light
    - light.garage_color_light
  delayoff: 9000
  rgb: "random"   

appdaemon.yaml

AppDaemon:
  logfile: STDOUT
  errorfile: STDERR
  threads: 10
  app_dir: /config/appdaemon/apps
HASS:
  ha_url: https://XXXX.duckdns.org
  ha_key: redacted
HADashboard:
  dash_url: http://127.0.0.1:5050
  dash_dir: /config/appdaemon/dashboards

the log as it appears after a restart - dod notice some new entries related to this app

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Hass.io Add-on: AppDaemon2 v1.0.0
 Python Apps and HADashboard using AppDaemon 2.x for Home Assistant
 From: Community Hass.io Add-ons
 By: Franck Nijhof <[email protected]>
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
Log level is set to INFO
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] 02-updates.sh: executing... 
INFO: You are running the latest version of this add-on
[cont-init.d] 02-updates.sh: exited 0.
[cont-init.d] 03-version-requirements.sh: executing... 
INFO: Supervisor version requirements checks passed.
[cont-init.d] 03-version-requirements.sh: exited 0.
[cont-init.d] 20-init-configuration.sh: executing... 
[cont-init.d] 20-init-configuration.sh: exited 0.
[cont-init.d] 21-compiled-dir.sh: executing... 
[cont-init.d] 21-compiled-dir.sh: exited 0.
[cont-init.d] 50-compiled-symlink.sh: executing... 
[cont-init.d] 50-compiled-symlink.sh: exited 0.
[cont-init.d] 80-system-packages.sh: executing... 
[cont-init.d] 80-system-packages.sh: exited 0.
[cont-init.d] 81-python-packages.sh: executing... 
[cont-init.d] 81-python-packages.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
starting version 3.2.4
[services.d] done.
2018-02-16 22:03:34.565343 WARNING ------------------------------------------------------------
2018-02-16 22:03:34.566223 INFO Loading Module: /config/appdaemon/apps/auto_turn_on_off_motion.py
2018-02-16 22:03:34.570522 INFO Loading Object auto_turnoff_motion_upstairs_toilet1 using class AutoTurnOnOffLightsMotion from module auto_turn_on_off_motion
2018-02-16 22:03:34.572349 INFO Loading Object auto_turnoff_motion_upstairs_toilet2 using class AutoTurnOnOffLightsMotion from module auto_turn_on_off_motion
2018-02-16 22:03:34.574080 INFO Loading Module: /config/appdaemon/apps/._auto_turn_on_off_sunset.py
2018-02-16 22:03:34.575194 WARNING ------------------------------------------------------------
2018-02-16 22:03:34.576106 WARNING Unexpected error during loading of ._auto_turn_on_off_sunset.py:
2018-02-16 22:03:34.577157 WARNING ------------------------------------------------------------
2018-02-16 22:03:34.579084 WARNING Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 901, in read_app
    conf.modules[module_name] = importlib.import_module(module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 121, in import_module
    raise TypeError(msg.format(name))
TypeError: the 'package' argument is required to perform a relative import for '._auto_turn_on_off_sunset'

as you can see in the log is the app that isnt working never started because off an import error.
i dont know if it is the random or the datetime causing trouble, but it seems that 1 of those isnt imported as usual because of hassio.

i really have no idea what this error means and how to solve it.

TypeError: the ‘package’ argument is required to perform a relative import

i suggest to edit out the random function and import to see if the app will start without errors.