Jump to content

State variables and programs


landolfi
Go to solution Solved by MrBill,

Recommended Posts

A basic question on using state variables with programs when the state variable increases or decreases: I know a change in a state variable causes an event that can trigger a program, but I am stuck trying to figure out how that works when the change is an increment or decrement. Say I have state variable X and I want to trigger a program A when X changes in value + or -, how do I link that value change to a program?

EDIT: After I wrote the above, it occurred to me that a simple > 0 test would probably be enough because it will get checked anytime the state variable change event occurs, is that right?

Edited by landolfi
Link to comment
  • Solution
1 hour ago, landolfi said:

EDIT: After I wrote the above, it occurred to me that a simple > 0 test would probably be enough because it will get checked anytime the state variable change event occurs, is that right?

this is exactly the answer... sometime tho I write programs like

IF
      $sX is not -999999999
then

which to me immediately means "for any change in $sX" without analyzing.

 

Pro-tip: name variables with the first character being s, i, or c... S for State Variables, i Integer variables, or c for Constant which is an integer variable that never changes values... i.e. $cTrue which is always 1 or $cFalse which is always zero.  Using these conventions will make your programs easier to read.

Pro-Tip, also when used in a If statement: a "state" variable is like a trigger, and an "integer" variable is like a filter.

  • Like 3
Link to comment
14 hours ago, landolfi said:

A basic question on using state variables with programs when the state variable increases or decreases: I know a change in a state variable causes an event that can trigger a program, but I am stuck trying to figure out how that works when the change is an increment or decrement. Say I have state variable X and I want to trigger a program A when X changes in value + or -, how do I link that value change to a program?

EDIT: After I wrote the above, it occurred to me that a simple > 0 test would probably be enough because it will get checked anytime the state variable change event occurs, is that right?

Yes.

BTW: a state variable value change always causes a trigger in the If section of an Enabled  program. Depending on outcome of the If section logic, Then or Else is run.

Link to comment

@C Martin This would be a good place to start.

https://www.universal-devices.com/start/

Anything here talking about ISY programming which is most of it, applies equally to the Polisy and eisy.

The ISY cookbook has a lot of examples in it, but don't ignor the other aids, they are very helpful as well.

If you have a specific issue, feel free to ask here on the forum, people often chime in with example code.

Edited by kzboray
  • Like 1
Link to comment

A follow-up question on state variable behavior: I thought state variables were supposed to have their values persist until changed by a program or a restart, and that init values were permanent until changed? I ask because on firmware 5.5.4, init values have been reset to zero for a couple state variables and there are no programs capable of resetting them to those values. So I assume it had to be IoP? I just added the init values back and took a screenshot for my own sanity to confirm they were there at one time.

This reset also happened to all state variables when I upgraded to 5.4.4, but that I suppose is to be expected when the firmware gets updated.

Link to comment
4 minutes ago, landolfi said:

A follow-up question on state variable behavior: I thought state variables were supposed to have their values persist until changed by a program or a restart, and that init values were permanent until changed? I ask because on firmware 5.5.4, init values have been reset to zero for a couple state variables and there are no programs capable of resetting them to those values. So I assume it had to be IoP? I just added the init values back and took a screenshot for my own sanity to confirm they were there at one time.

This reset also happened to all state variables when I upgraded to 5.4.4, but that I suppose is to be expected when the firmware gets updated.

A few versions back the last variable defined was getting changed to 0 on my system but IIRC, that was corrected and all state variables should be secure again. However the jump to a different O/S may still have some minor bugs in it as UDI had to change to the other endian system and there still could be some quirks hiding.

Watch carefully and report results to UDI. They will want to know about it.

Link to comment
24 minutes ago, larryllix said:

A few versions back the last variable defined was getting changed to 0 on my system but IIRC, that was corrected and all state variables should be secure again. However the jump to a different O/S may still have some minor bugs in it as UDI had to change to the other endian system and there still could be some quirks hiding.

Watch carefully and report results to UDI. They will want to know about it.

Thanks! Will keep an eye on it. Meanwhile, I set up a startup program to set the current values just in case the init fails.

  • Like 1
Link to comment
11 minutes ago, landolfi said:

Thanks! Will keep an eye on it. Meanwhile, I set up a startup program to set the current values just in case the init fails.

Trouble with that is you may never discover if it is needed. I would leave it for manual discovery of the init value failure. Actually you may be able to set up a delay and then examine the running values in order to trigger an automatic value reset. Then you could examine the last run time to determine if it triggered. On second thought, send yourself a notification if it does run.

  • Like 1
Link to comment
1 hour ago, larryllix said:

Trouble with that is you may never discover if it is needed. I would leave it for manual discovery of the init value failure. Actually you may be able to set up a delay and then examine the running values in order to trigger an automatic value reset. Then you could examine the last run time to determine if it triggered. On second thought, send yourself a notification if it does run.

i can’t get a notification for an inIt value change, can I? I had one set for a value change that I could reinstate.

Link to comment
1 hour ago, landolfi said:

i can’t get a notification for an inIt value change, can I? I had one set for a value change that I could reinstate.

try something like this:

[disabled] [Run on Startup]

If
    $variable = 0                      //* init value failed *//
then
    notify InitValueFailed
    $variable = 42
    $variable init value = $variable

 

Edited by MrBill
  • Like 1
Link to comment
43 minutes ago, MrBill said:

try something like this:

[disabled] [Run on Startup]

If
    $variable = 0                      //* init value failed *//
then
    notify InitValueFailed
    $variable = 42
    $variable init value = $variable

 

I assume 42 is just a random value, or does it have to be 42?

Does [disabled][Run on Startup] do the same thing as enabling Run on Startup on the Summary tab?

Link to comment
2 hours ago, landolfi said:

I assume 42 is just a random value, or does it have to be 42?

Yep the program is only an example.... use whatever value your init value should be...  Why did I randomly throw in 42?  It's the answer to everything.

2 hours ago, landolfi said:

Does [disabled][Run on Startup] do the same thing as enabling Run on Startup on the Summary tab?

It needs to be both "disabled" and set “run at startup".  Both can be adjusted on the summary page (as well as other ways).  (technically it would only need to be disabled for a State Variable but it doesn't hurt for any and all like this to be disabled.)

Edited by MrBill
  • Haha 2
Link to comment
12 hours ago, landolfi said:

A follow-up question on state variable behavior: I thought state variables were supposed to have their values persist until changed by a program or a restart, and that init values were permanent until changed? I ask because on firmware 5.5.4, init values have been reset to zero for a couple state variables and there are no programs capable of resetting them to those values. So I assume it had to be IoP? I just added the init values back and took a screenshot for my own sanity to confirm they were there at one time.

This reset also happened to all state variables when I upgraded to 5.4.4, but that I suppose is to be expected when the firmware gets updated.

One thing I do for any variable that has a longer "shelf life" of any real time, where a power outage could occur, in the THEN or ELSE, where you change the variable, also Init it to itself immediately in the next line. These options are in the AC under the arrow.  Example for VAR1

IF xxx

THEN 

Var1 =14

Var1 Init to Var1

This will set the Start up value to 14 for the variable that you want to preserve/

Link to comment

We have requested UDI consider program read access to the "init to" values in variables.

However, in any case, this should not be happening.

For my single variable problem I just extended my variable list to a spare dummy at the end of the list. However I leave no unused variable holes in my variable list. Every variable is labelled, even if not used. My groups of variable functions stay together. Yeah it takes a lot of homework at times.

Link to comment

The init value got reset to zero again sometime between yesterday and today. I have no idea when because the nifty code MrBill suggested only runs at startup and is otherwise disabled and I haven't restarted the Polisy.

I opened a ticket, but the error logs show nothing. The only thing that has changed is I updated firmware to 5.5.4.

Link to comment
15 hours ago, landolfi said:

The init value got reset to zero again sometime between yesterday and today. I have no idea when because the nifty code MrBill suggested only runs at startup and is otherwise disabled and I haven't restarted the Polisy.

I opened a ticket, but the error logs show nothing. The only thing that has changed is I updated firmware to 5.5.4.

How many variables?

Link to comment
16 hours ago, landolfi said:

The init value got reset to zero again sometime between yesterday and today. I have no idea when because the nifty code MrBill suggested only runs at startup and is otherwise disabled and I haven't restarted the Polisy.

I opened a ticket, but the error logs show nothing. The only thing that has changed is I updated firmware to 5.5.4.

I misunderstood the problem. I didn't see above which hardware this is running on, but it's was posted in the 994 section of the forum (Geddy just moved this thread to IoX based on my comment).. if it's a 994 then you need to replace the SD card... On the other hand you say you upgraded the firmware to 5.5.4 so that implies it's NOT a 994.

 

Another thought.... could you have another program that's modifying the init value, you can use the search feature to find out.  right click any program name and choose find/replace and then variable. 

unfortunately there's no good way to monitor and init value with a program, while a variables init value can be set, there's no way to load an init into a variable except at startup.

Edited by MrBill
  • Like 2
Link to comment

I j

1 hour ago, MrBill said:

Another thought.... could you have another program that's modifying the init value, you can use the search feature to find out.  right click any program name and choose find/replace and then variable.

I had in parallel had the same thought. The only program that has a reference to that variable's init value is the startup one, and I still haven't restarted. Regardless, if that program had run the variable would be nonzero.

It happened again between yesterday and today, whatever the problem is. This time both init and current value were zero.

Could this be some bad memory  in the Polisy?

Link to comment
4 minutes ago, landolfi said:

I j

I had in parallel had the same thought. The only program that has a reference to that variable's init value is the startup one, and I still haven't restarted. Regardless, if that program had run the variable would be nonzero.

It happened again between yesterday and today, whatever the problem is. This time both init and current value were zero.

Could this be some bad memory  in the Polisy?

You need to open a ticket, if there is no other program references, then this is either a hardware issue or an IoX bug.

https://www.universal-devices.com/my-tickets/

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

×
×
  • Create New...