I know how to schedule a handler/function to execute and also how to unsubscribe all scheduled handlers within an app, but is there an API call to check to see if a specific handler is currently scheduled by that app?
Scenario is this, I have an app that automates my hot water circulation pump. There are multiple ways that this gets turned on, hence the need for a custom app to manage it. I have code in place that sets a schedule to turn it off after X number of minutes but of course my wife started turning the pump on directly on the keypad which isn't covered by my code to scheduled the auto-turn off. So I would like to update my app for this scenario but before scheduling another Off event, check to see if one exists first.
I don't fully understand all the scenarios and events but I think I sort of know what you're going for. You don't want to continue pushing the turn off handler out further if another event already scheduled a turn off. Using your own state variable would probably be the simplest. Something like set state.turnOffPending to true when scheduling your handler, then check this variable before scheduling and set to false after executing your handler.
Dan thanks. This won’t work for me though because let’s say I have a schedule that will be turning it off in 10 minutes, I don’t want to replace it with one to turn it off in an hour. That is why I was hoping for an API that would allow me to query if there is already a scheduled task before creating a new one. In the ST IDE you can view schedules on an app, unfortunately not in HE but obviously they are stored and linked to apps somewhere. Was hoping an “isScheduled” type API exists.
Thanks for this suggestion. This may be my only option unless the HE staff have an undocumented API for me.
Can you explain exactly what you want to happen? If a schedule already exists, do you want that one to continue? But if it does not exist, create a new one? If your wife turns it on manually, wouldn't you want it to run for at least a certain amount of time (i.e. schedule it again to turn off, overwriting any existing schedule) ?
Obviously, using a state variable is a pretty simple way to handle this scenario. It would be nice to have an API call to return a list of active schedules.
Or, maybe you just need to ask her to stop turning it on manually?
I need to rethink how I have the app written. Kind of makes my head spin with all the scenarios of turning this on and how to best manage it: shower light switches turns on (multiple bathrooms), a "hot water" virtual switch via Alexa or dashboard, or the new found wife way of hitting the button on the water heater controller. And then the off scenarios out of all of this. I need to put more thought into this over this long week/weekend.
I am going to go this route for now as I agree would be the easiest way to manage.
This is really what I wanted to know if there was an API that would return a list of schedules. I guess that doesn't exist. I couldn't find anything in the ST documentation on it so it doesn't exist there but through the IDE there is obvious linkage because I can pull up an app and see its schedules. I would expect something similar in HE.
I don't know if it would help you but I have used a LucidChart free account to sort out such ideas. I have a graphical mind and found flowchartting to be the best approach for me. I did some looking and LucidChart is super intuitive and though the free account is limited it has been enough for me to layout such things.