I’m not much of a programmer, but can understand few things. I’m writing a SmartApp to talk with my Alarm system provided by TotalConnect from HoneyWell. Part of this app, requires to login to the service, get a token ID and then used that token ID to perform other calls like arm/disarm.
So far my logic is pretty straight forward i.e. Login with Creds, Get the Token, Send this token to Arm or Disarm function.
The problem is the variable named token is defined in the login() function and only exists there. In programming terms, this is called the scope of the variable.
You want to do something like:
def credentials = login()
This will put the return value from login() into the new variable called credentials. You can then use credentials in the function where it is defined.
If you want to use the same value across multiple functions, you can instead make the token variable part of the global scope:
def armAway() {
log.debug state.token
if(state.token == null) {
log.debug "Need to login"
state.token = login()
// return - don't return here, you want to continue below
}
// ... rest of your function always using state.token here instead of token
}
@mhatrey have you made any progress with this app as of yet? I’m about to start working on the same thing and was wondering if you had working code that could save me from having to start from scratch.
Yes. I have been using this app for a good year now. My wife loves it. I haven’t shared it with the community as its not polished. But it always gets the job done.
I’d be happy to share the code with you and also elaborate on how it works. Will PM you with the code.
= Explaination on Triggers =
In General, Triggers are based on the in built modes (Away, I’m Back, Morning & Night). Of course you can configure them.
I have setup ST to put home in Morning state at 6:30 AM and in Night state at 10:45 AM automatically. Also Away & “I’m back” mode are triggered based on the presence sensor in my case, Mobile Phones of myself and wife. Even if you don’t use your phone as presence sensor, the modes can be triggered from the SmartThings widgets.
At 10:45 PM - Night mode is triggered by ST, which Triggers the ArmStay mode of TotalConnect
At 6:30 AM - Morning Mode is triggered by ST which Triggers the DisArm mode of TotalConnect
When phones are not at home - Away mode is triggered by ST, which Triggers the ArmAway mode of Total Connect. You always need your ST app on phone running in background for location services to work well Or you could use the widgets from the App to set the appropriate Away or ImBack modes.
That all said, there are some quirks that I need to iron out before I could actually publish the app for the community. TotalConnect APIs do not make it easy for me to work on this, and also Im not a programmer by nature of my work. I will explain those quirks in the PM. Hopefully I will get some time to figure out those, some day.
== Some ScreenShots ==
How App looks, What input it accepts, how it logs and How it reflects on the Total Connect web portal. Hope this helps to you and other folks using ST and HoneyWell Total Connect