Auto restart app


#1

I have a highly customized version of the Smart Lights app that I’ve bee using for a few years. I’m currently running on 525 for my deployed HA but will be moving to 1.1.15 or later after I’m comfortable enough that it’s stable.

I noticed an issue yesterday on 525 where my app was running but not in the correct mode resulting in things not working. When running correctly the icon is green. In this case the ocon was yellow. Some apps have a blue icon, but all 3 are valid program tun states.

My question is, will the auto-restart code that’s been added to 1.1.15 be able to detect the wrong run state and restart the app?


#2

Hmm, I need to check all these states, but as far as I remember program will be restarted on failure (there was an exception during program execution).


#3

So if the program is yellow and should be green, that might not be considered a failure I assume.


#4

As I see from the code, yellow is for enabled but not running program (just created/compiled). The program switches to this status after it finishes its work.

For reference:

color meaning
green program runs in foreground
blue program runs in background
yellow program is enabled but is not running at the moment
red program is enabled and has errors
brown program is disabled and has errors
gray program is disabled

#5

The smart lights code watches for module activity so it must run in the foreground or background. Yellow would mean the user has to select “run” for it to work which would make it useless (also a good reason it wasn’t functioning).


#6

No, if the program is yellow - that means that it’s not running and it don’t have to.
To prevent this add Program.GoBackground(); at the very end of your program.
If we talk about Smart Lights program, in stock variant it has

while (Program.IsEnabled)
{
  smart_devices.Each((mod)=> {
    var timeout = mod.Parameter(TURNOFF_TIMEOUT).DecimalValue;
      //...
  });
  Pause(5);
}

block, that evaluates module’s parameters every 5 seconds. And this means that program is running in the foreground and should be green. If an error occurs - it should become red. And because of .Run() command in the program’s startup code it runs immediately after enabling.
So I think you did something special with your customized version of Smart Lights. You can post it’s code (both program code and startup code here) and we’ll able to discuss what may be wrong with it and why the program falls to the “yellow” state.


#7

The code is published on github.

The last line of code is

Program.GoBackground();

#8

It’s really strange program has switched from green to yellow.
It could happen if you accidentally clicked the button that toggles enabled status of the program:

Also try to look for Runtime.Error parameter of the program.
image


#9

Programs dont always start when i restart HG. I believe I manually started it and it went to yellow for some reason. I disabled and enabled it and it went green.


#10

FWIW, I was referring to HG 525 when it didn’t restart correctly. I don’t know how your code works in that regard. It might already be perfect!