Posted October 4, 20232 yr 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?
October 4, 20232 yr 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.
October 4, 20232 yr Can you set is init value at the same time to the variable value? Edited October 4, 20232 yr by BamBamF16
October 4, 20232 yr Author 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.
October 8, 20232 yr 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
October 8, 20232 yr @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.
October 8, 20232 yr @dbwarner5 Hi DB Are you able to explain what the init line does? I don't understand what this is doing? Thanks PB
October 8, 20232 yr Author 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.
October 8, 20232 yr 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.