You’re right this is what it spits out
2018-03-02 11:42:04.404692 INFO AppDaemon Version 2.0.8 starting
Hmm now I wonder how do I update this
You’re right this is what it spits out
2018-03-02 11:42:04.404692 INFO AppDaemon Version 2.0.8 starting
Hmm now I wonder how do I update this
I don’t know, but when you do, you will need to update your configuration to match the later documentation. V3 changes it again, just to confuse everyone - but that is still in beta, so probably best avoided when you are starting.
Well I’m getting closer to having this working. Its now complaining that the name day is not defined on line 36 I must be missing something with my import datetime time to go look at that code example again. I really do appreciate your help with this today you’ve taught me a lot.
Actually, before you go looking to far in to that, there is a better way of writing all the conditions you have, using callback constraints
I have taken the liberty of re-writing your app, avoiding all the if statements, using this method. Basically, the constraints replace your if statements, so that your callback are much cleaner and easier to figure out when you look at it again in six months.
import appdaemon.appapi as appapi
class set_modes(appapi.AppDaemon):
def initialize(self):
self.log("Set the boolean to the appropriate value")
# listen to see if anyone at home
self.listen_state(self.arrive_home, "group.all_devices", new="home")
self.listen_state(self.everyone_out, "group.all_devices", new="not_home")
self.home = "input_boolean.notify_home"
self.day = 'input_boolean.notify_day'
self.night = 'input_boolean.notify_night'
self.sleep = 'input_boolean.notify_sleep'
self.listen_state(self.weekend, self.home, new="on",
constrain_start_time = "04:30:00",
constrain_end_time = "sunset",
constrain_days = "sat,sun",
constrain_presence = "anyone")
self.listen_state(self.weekday, self.home, new="on",
constrain_start_time = "04:30:00",
constrain_end_time = "sunset",
constrain_days = "mon,tue,wed,thu,fri",
constrain_presence = "anyone")
self.listen_state(self.night, self.home, new="on",
constrain_start_time = "sunset",
constrain_end_time = "00:00:00",
constrain_presence = "anyone")
self.listen_state(self.night, self.home, new="on",
constrain_start_time = "00:00:01",
constrain_end_time = "sunrise",
constrain_presence = "anyone")
def weekend(self, entity, attribute, old, new, kwargs):
self.log("weekend")
self.turn_on(self.day)
def weekday(self, entity, attribute, old, new, kwargs):
self.log("weekday")
self.turn_on(self.day)
def night(self, entity, attribute, old, new, kwargs):
self.log("night")
self.turn_on(self.night)
def sleep(self, entity, attribute, old, new, kwargs):
self.log("sleep")
self.turn_on(self.sleep)
def arrive_home(self, entity, attribute, old, new, kwargs):
self.log("arrive_home")
self.turn_on(self.home)
def everyone_out(self, entity, attribute, old, new, kwargs):
self.log("everyone_out")
self.turn_off(self.home)
self.turn_off(self.day)
self.turn_off(self.night)
self.turn_off(self.sleep)
Dude that is just awesome. Thank you very much and I will use those in my apps going forward. That is so neat and clean. Wow I’m just speechless I am so grateful for the rewrite. BTW I did get it to trip the switch I wanted it to when I removed the weekday thing.
I thought the constraints could only be set in the main appdaemon.yaml I didn’t know you could plug them into the app like that. That is just amazing.
If you’re ever out in Colorado I owe ya a beer or something.
You know what the sad part is, learning what I just learned from you, I am realizing that there is little to no value in me using these booleans because these constraints are basically going to accomplish everything I was going to use those booleans for lol. Sigh, however I will have some use for them I’m sure so I definitely am not getting rid of them
so quick question can you do multiple entities in these lines?
self.listen_state(self.weekend, self.home, new="on",
i.e.
self.listen_state(self.weekend, self.home or self.home2, new="on",
btw this is a complete example not something I’m doing here just wondering if I can monitor multiple sensors to make a call to the same function.
Or can you use OR’s with the constraints as well?
I think you would need to put these entities in a group in HA and then listen on the state of the group.