Jump to content

Checking Variables After A Reboot


gregkinney

Recommended Posts

Posted

I have a handful of variables that change based on programs. For instance, I have a variable called $evening that sets to a value of 1 if it's sunset and sets to a value of 0 at 10pm.

My question is if I reboot the Polisy at 9pm, or it gets unplugged or I lose power for a bit, the $evening variable will have it's init value of 0 which would be incorrect. Does anyone have ways in which they can handle these situations programmatically? Maybe a second script that runs at startup, is that a thing?

Posted

I'm certain someone with more experience will chime in, but i think the "run at startup" setting in the AC should account for this.

Posted

Thank you both for the suggestions. @PB11 I didn't know the functionality of specifying a program to run at startup existed, that's a great idea. @BamBamF16 setting the init value at the same time - I've been thinking through the logic and I think it would work perfectly. Brilliant idea - I think that's what I'm going to try. I hope someone else chimes in who has experience with either of these ideas to determine if one is better than the other.

Posted
On 10/4/2023 at 6:57 PM, gregkinney said:

Thank you both for the suggestions. @PB11 I didn't know the functionality of specifying a program to run at startup existed, that's a great idea. @BamBamF16 setting the init value at the same time - I've been thinking through the logic and I think it would work perfectly. Brilliant idea - I think that's what I'm going to try. I hope someone else chimes in who has experience with either of these ideas to determine if one is better than the other.

Did you find a satisfactory solution?

If i understand your issue, my work around was to use the "run at startup" and I basing my trigger on a window of time rather then a single point in time. 

By doing this the program is assessed between say 5pm and 9 pm. If power goes out(which it often does in the winter) the program is run on start up between 5-9. 

With that said, I found using "run at startup" for all my programs was problematic given their purpose. I had to be somewhat selective on which programs do "run at startup"

Not sure if that helps or how clear it is

Posted

@gregkinney  Greg , if I understand correctly, your issue is upon restart you lose the value of a varilabe becuase the init value is 0. 

The solution to this is quite simple. Every time you change an important "governing"  variable, add an init line below it to init it to itself. I do this on probably 50% of my variables. It looks like this:

Autolocks - [ID 0121][Parent 01A5]

If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')
 
Then
        $Autolocks  = 1
        $Autolocks Init To $Autolocks
 
Else
        $Autolocks  = 0
        $Autolocks Init To $Autolocks
 

 

To get this option, you need to click on the Arrow as shown below. Continue to click on the arrow to cycle through other options as well. image.thumb.jpeg.5c654e99fbae99290dd609243c78cb43.jpeg

Posted

Thank you @dbwarner5 for confirming that is the best way to go. That is the path that I chose and it's working great. @PB11 basically, each variable has an initial value for when IoX starts up. Since my $evening variable is 0 with the exception of sunset to 10pm, I have it's initial value set at 0. So if, and when, IoX reboots, it will load this value of 0. The problem I was having was if that reboot happened from the hours of sunset to 10pm, then the $evening variable was being loaded as a value of 0, which would be incorrect. I changed my program similar to @dbwarner5's above so when the variable changes to 1 during evening time, it also changes it's initial value to 1. This way, if IoX reboots during this time period, it will be loaded as a value of 1. Then, at 10pm, when I tell the variable to go back to 0, I also change it's initlal value to 0 so that if IoX reboots, it will load the correct value of 0.

Posted
2 hours ago, PB11 said:

@dbwarner5 Hi DB

Are you able to explain what the init line does?

I don't understand what this is doing?

Thanks 

PB

Init just is an abbreviation for Initial Value. so that upon restart, instead of the value default to zero, you can place a value into memory that is sustained during a power outage and then this sets the variable to that value instead of zero upon a restart. 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...