Jump to content

Increment Var Value Via API?


FrayAdjacent

Recommended Posts

So I use the crap out of variables to control things, and I use the API to set variables from my Android phone with Tasker. Easy enough. 

Well, I switched to a new phone today, which has no method of gaining root access, so a couple of my programs that involve variables on my ISY aren't working. These ones are a little more complicated, basically they get a variable value and then Tasker evaluates it and does an if/else. What it ends up doing is if the variable on the ISY is 0, then set it to 1, if it's 1, then set it to 0. I accomplished this by getting the variable value from an API call, writing it to a file, then having Tasker read the file into a variable (for some reason, Tasker wouldn't just take the output of the API call and put it directly into a variable...)

 

So I know you GET the value of a variable, and you can SET the a variable value, but is there a way to actually increment a variable value? 

Link to comment

Did you want to do this increment in Tasker or ISY?

 

With ISY, Tasker could set a state variable to non-zero value, triggering an ISY program to increment another variable, and then set the Tasker controlled variable back to zero.

 

Tasker could monitor the variable to control further action if confirmation is required.

Edited by larryllix
Link to comment

Well, I've figured out a way to do what I want to do without having to increment a variable by an API call. 

 

I'll just use a new variable on the ISY. Then use that variable with the original variable I want to toggle as the condition for a program... like this:

 

IF NewVar = 1 

   AND

    OrigVar = 0

THEN

   set OrigVar to 1

   set NewVar to 0

Else

   set OrigVar to 0

   set NewVar to 0

 

 

That way, any time I set NewVar to 1 via an API call, it essentially toggles the OrigVar between 0 and 1. 

Link to comment

Well, I've figured out a way to do what I want to do without having to increment a variable by an API call. 

 

I'll just use a new variable on the ISY. Then use that variable with the original variable I want to toggle as the condition for a program... like this:

 

IF NewVar = 1 

   AND

    OrigVar = 0

THEN

   set OrigVar to 1

   set NewVar to 0

Else

   set OrigVar to 0

   set NewVar to 0

 

 

That way, any time I set NewVar to 1 via an API call, it essentially toggles the OrigVar between 0 and 1. 

If you set NewVar =1 then OrigVar will flash 1 and then immediately back to 0.

 

Since the Else clause also sets OrigVar back to 0, you avoid continuous oscillation. OTOH, OrigVar should only stay 1 for a few milliseconds as it will then trigger the Else clause to run. This may be  OK if your logic at the other end can handle  the quick logic changes.

Link to comment

Yeah, I figured out that made a loop. I just made two separate programs. When one matches and executes, the variable change won't trigger the other, because the conditions won't be evaluated again until after the first program is complete. Works like a charm now. 

 

So all I need to do is make an API call to set NewVar to 1, and OrigVar will get toggled between 0 and 1. This basically turns on/off a lamp. 

Link to comment
Guest
This topic is now closed to further replies.

×
×
  • Create New...