So I’m working on getting this to work with appdaemon.
I don’t want to really pass in any args to the script kinda just want it to fire off on its own as time happens or presence changes. It passes the sanity checks when appdaemon loads it up but for the life of me I can’ get it to toggle the various input_booleans that I need it to toggle. My idea with these is to use them as I guess for lack of a better word a scene setter. Like if the night is active then we can do certain things or if sleep is active lets do this or that. I’m still no expert at python so a lot of this has been me studying other python examples to piece this together. The script makes sense to me it looks like it should work but I guess I’m missing something with it.
import appdaemon.appapi as appapi
import datetime
class set_modes(appapi.AppDaemon):
def initialize(self):
self.log("Set the boolean to the appropriate value")
self.listen(self.someone_home_function, get_state.anyone_home)
self.listen(self.set_mode_function, "input_boolean.notify_home")
# input booleans
home = ['input_boolean.notify_home']
day = ['input_boolean.notify_day']
night = ['input_boolean.notify_night']
sleep = ['input_boolean.notify_sleep']
# Days of the week
WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
WEEKEND = ['Saturday', 'Sunday']
def someone_home_function (self, entity, attribute, old, new, kwargs):
someone_home_function = self.get_state.anyone_home
if self.someone_home_function == 'true':
self.log("Setting the mode to home")
self.turn_on("home")
else:
self.log("Setting the mode to away")
self.turn_off("home")
self.turn_off("day")
self.turn_off("night")
self.turn_off("sleep")
def set_mode_function (self, entity, attribute, old, new, kwargs):
set_mode_function = self.get_state()
if home == 'on' and self.now_is_between("04:30:00","sunset") and day.strftime('%A') in WEEKDAYS:
self.log("Setting mode to day")
self.turn_on("day")
elif home == 'on' and self.now_is_between("04:30:00","sunset") and day.strftime('%A') in WEEKEND:
self.log("Setting mode to day")
self.turn_on("day")
elif home == 'on' and self.now_is_between("sunset","00:00:00"):
self.log("Setting mode to night")
self.turn_off("day")
self.turn_on("night")
elif home == 'on' and self.now_is_between("00:00:00","sunrise"):
self.log("Setting mode to sleep")
self.turn_off("night")
self.turn_on("sleep")
I know once I get this figured out I can then go back to some of my other ones that I’m having issues with and probably fix them as well. I took a break from them since I thought this would be simpler. Guess I was wrong thank you all for your help with this.