ISY-994i: the difference between state and integer variables

Last week when covering MobiLinc’s geo-fencing feature, I mentioned how MobiLinc will change a state variable based on whether you are inside our outside your “geo-fence“. If you’re a programmer, the use of variables is pretty obvious – and even if you’ve never actually written code, programming the ISY-994i is still pretty simple. But, there’s a bit of a rub with variables in the ISY-994i: there are two different types of them, integer variables and state variables.

Both types are identical, except that when the value of a state variable changes, a program event is raised. In other words, if a state variable is used in an “If” condition, the program will be run every time that variable changes, which may cause unexpected results.

For example, let’s consider a simple location program based on the geo-fence state variable. Let’s say our Kitchen motion sensor is configured to go ON when it detects motion and time out to OFF after 5 minutes. We want to get a text message when motion is detected inside the house and we are not home, so we write a program like this:

If
      Status 'Kitchen-Motion' is On
  And $Matts_iPhone_home_100_meters is 0
Then
      Send Notification to 'TextMessage' content 'Motion_detected_when_not_home'

The problem with this program isn’t obvious, but if we used this program, most likely we will ALWAYS be getting text messages every time we walked to the corner bar. Why? Because we are using a state variable, the conditions of this program are checked every time the value changes. Since the geo-fence is only 100 meters, the status of the motion sensor is likely to still be ON when the variable goes to 0, so both conditions are met, and the text message will be sent.

While it’s not a practical solution, changing the variable to an Integer Variable would solve the problem because it would mean the program only ran when the status of the motion sensor changed (and not the value of the variable). But, because we do actually want an event to fire when we leave our geo-fence, the better solution to this problem would be to change the first condition to:

      Control 'Kitchen-Motion' is switched On

That way, while the program is run every time our geo-fence is crossed, both conditions are only true when the motion sensor actually activates.

Some things to keep in mind about variables:

  • Remember both variable types behave the same, except state variables cause events to be sent, which may cause programs to run.
  • Remember to set the Init value of your variable if you need the value of the variable to be preserved through power outages.
  • If you don’t need a changing variable to start a program, use Integer variables. State Variables are slower because they require the ISY to check all those program conditionals.
  • There’s a great forum post describing the nuances of the program variables on the UDI Forum.
  • Universal Devices recently posted a video explaining the use of variables that I found very helpful:

Posted by Matt Chiste
October 7
 Subscribe to HomeAutomationGuru.com
    Add to Google Reader or Homepage

Enter your email address to subscribe: