Will this help us? I read one of the issue reported for SSEClient.
Its a little vague but it might fit the bill. You could try by editing the SSEClient line to look like:
messages = SSEClient("{}/api/stream".format(conf.ha_url), verify = False, headers = headers, retry = 3000, timeout = 1)
That should be round about line 844 in appdaemon.py
I will try it not sure though how to test this. May be I can stop HA and see how it behaves.
Got a new challenge… I need the callback to only run M-F, which currently works, but I also need it to only run when an input Boolean is “off”. Can you chain constraints together?
def initialize(self):
morning_time_on = datetime.time(6, 0, 0)
self.run_daily(self.my_morning_callback_on, morning_time_on, constrain_days = "mon,tue,wed,thu,fri", input_boolean.school_holiday = "off")
that wont work for sure.
i would try:
self.run_daily(self.my_morning_callback_on, morning_time_on, constrain_days = "mon,tue,wed,thu,fri", constrain_input_boolean ="school_holiday")
Yep, you should be able to chain constraints, they all have to match.
Awesome!!! That did the trick.
Thank you very much!!!
Now I see something strange. If I start AppDaemon with the input boolean off, it works perfectly. If I start it with the boolean on and then turn it off before the the scheduled time, it does not run.
I am using time travel (for testing) to start it up 20 seconds before the event fires and then a few seconds later I switch the boolean to off and it does not fire.
Are the callback constraints not dynamic?
i dont know why its working in one moment and not in the other moment, but i think you need the reverse logic version.
(see API)
but i dont know how that would go into the code.
you could also set the constraints in the config file. (thats where i would put it)
The logic seems to be right. Here’s the config entry…
[toggle_inside_lights]
module = toggleinsidelights
class = ToggleInsideLights
constrain_input_boolean = input_boolean.school_holiday,off
So when appdaemon starts with the boolean “off”, the code executes properly. If I start appdaemon with the boolean “on” at 5:59 AM and then turn it “off” before it gets to 6 AM, the code does not excute.
Hopefully I am making sense…
It just seems that the constraints values are applied at time of creation and not updated when a state changes, at least based on my limited testing and knowledge.
Maybe I am doing something wrong??
Quick update… I ran the test again, but gave it a bit more time. I set it to start 5 minutes before 6AM with the boolean set to “on”. I then turned it to “off”, and the code executed at 6AM which is what I wanted.
I guess from now on, I should give it more time than just a few seconds.
Again, thanks for all of your help with this!!!
Cool - when using time travel, times become less accurate depending on the rate you are using.
Will remember that next time
Did you see any difference with the timeout parameter?
Sorry, not yet, but sure will do before this Wed evening and report back my findings.
Thank you for your work on Appdaemon, it’s really great to have all the automation in python!
Last night I ran into some trouble with the get_trackers method. It seems to return all devices (including those which are not being tracked in ha). This is also a problem with the convenience methods (Noone_home, anyone_home) since they also seem to check the states of the devices not being tracked.
Is this the intended functionality of these functions? If so, is it possible to get only the devices currently being tracked in another way? And then possibly override the convenience methods.
That’s interesting - I just ran a quick check and I have one device tracker that is not being tracked and I don’t see state changes for it, and it isn’t returned by get_trackers() either - what type of devices are you using?
I am trying this but looks like some how my updated appdaemon.py is not getting executed, what I meant is my changes are not reflected. To make sure I have modified info text where it says “App initialization complete” I added more text to make sure I did modify correct file but I don’t see these changes on console-log, I did modify both places where it says “App initialization complete” as well as call to SSEClinet with additional parameter with timeout and added exception handling code to see when it throws exception and handle it nicely with log message and still continue execution.
I am running all in test environment (so not to disturb production) on same Windows 10 computer but HA is running as command prompt and AppDaemon in Bash command but I did verify in bash command with cat appdaemon.py which showed my changes but not getting executed.
Any idea?
How are you running AppDaemon? To run it from the command line you need something like:
python3 -m appdaemon.appdaemon -c conf/appdaemon.cfg
That would be from the top level AppDaemon directory.