AppDaemon Q&A

Cool! Glad you got it working :slight_smile:

On to my next question…

Is it possible with AppDaemon to schedule something to run only during the week days? I want to be able to turn on some lights every morning at 6 AM but only M-F?

Looking thru the API, I don’t see where I can do that.

in the code:

    days = self.args["days"].split(",")
    if str(self.date().isoweekday()) in days:

and in the config:

days = 1,2,3,4,5

will run only on weekdays.

There is a much easier way - check on constraints in the API doc - I’ll post an example when I am not on my phone.

OK, now I am back at my desktop …

The feature yo uare looking for is called constraints - they are fullly documented in the API doc, but basically they are a shorthand way of preventing apps from running or firing callbacks under certain conditions.

You can either constrain the entire App by adding arguments in the config file, or you can do it for individual callbacks when you register them so they will only affect that callback.

For example, if you want a particular callback to fire at 6am every day but only on weekdays you could do the following to register it:

time = datetime.time(6, 0, 0)
self.run_daily(self.my_morning_callback, runtime, constrain_days = "mon,tue,wed,thu,fri")

EDIT: The days constraint was not documented - will be fixed in the next version.

Perfect!! Exactly what I was looking for.

1 Like

thats why i didnt think of it :wink:

so it does also work to put constrain_days in the config?

1 Like

Yes it does, but depending on how the App is constructed that may or may not be what you want.

For instance if you rely on a callback to set a new callback, you may break things by using constrain_days at the App level - some thought is required.

i am not that complex :wink:

i have no callbacks in callbacks :wink:

at this moment i cant even think off what use i would have for that.

i use daily actions, minutly actions, sunset actions, actions for input booleans, and sensorbased actions.

That is fine - you are my every day sensible user that keeps me from getting too complicated and mixed up!

1 Like

thx :wink:

even my apps are straight forward.
i use daily.py for every daily action. so there are several classes in it but all with daily actions.
minutly.py for minutly actions, sunset.py for sunset based actions, etc.

by the way isnt it actually the wrong way round?

if i use constrain_days = “sat,sun”
i would expect that on sat and sun the action would be constraint (so that would mean not done)
or is it my languagebarriere that lets me think that?

Mmm, it is arguable … even to a native speaker :slight_smile: I had to pick one way and it seemed more logical to list the days it would work for - it is constrained to run on those days.

yeah, if i look closely i see that all constrains work just the other way then i would expect :stuck_out_tongue:
at least it is documented right.
so i will get use to it :wink:

1 Like

Hi

Had to reinstall my SD card and install HASS and AppDaemon as well.
This is where the problems started.

When i run -

pi@RPi3:~/appdaemon/conf $ appdaemon -c appdaemon.cfg
Traceback (most recent call last):
  File "/usr/local/bin/appdaemon", line 9, in <module>
    load_entry_point('appdaemon==1.3.6', 'console_scripts', 'appdaemon')()
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 995, in main
    efh = RotatingFileHandler(conf.errorfile, maxBytes=1000000, backupCount=3)
  File "/usr/lib/python3.4/logging/handlers.py", line 150, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python3.4/logging/handlers.py", line 57, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python3.4/logging/__init__.py", line 1006, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python3.4/logging/__init__.py", line 1030, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/home/pi/appdaemon/logs/error.log'

Is this a user permission or something else?
And the error.log is empty as well.

Yes, it can’t write to the log file, what user were you running it as, and who owns the log file?

I am using the user pi not sure who owns the log folder.

Well its a permissions problem - you need to make sure the pi user has access to the file. If you ran it at startup as root it probably created the files owned by root.

Sorry i am a Noob but how do i make pi as the user of those files/folders?

Google the chown command. You can also use ls -l to check the current ownership.