Timer script not working

Hello everyone, had this working and don’t know what I did. I am probably over thinking it.

I have a script to auto logout users. logout@1,000ms. script located in timer script section. timer is located on nav and has tags for certain values. here is the time script:

# Log user out once timer runs out
TimerValue = system.tag.read("System1/BadgeSystem/LogoutTimerValue")

if TimerValue.value == 180:
	system.nav.swapTo('Logged Off')
	system.security.switchUser("Testuser", "Testuser")
	system.tag.writeToTag("System2/BadgeSystem/DisplayCountdown", 0)
	system.tag.writeToTag("System2/BadgeSystem/LogoutTimerRunning", 0)

I can see the tag cycle and hit the value of 180, not sure why it is not executing.

Thank you in advance for any help.

I got it to work, by switching from delay to fixed rate.

What is System1/BadgeSystem/LogoutTimerValue, I assume a expression tag you made that counts up?

One thing I would note - TimerValue.value == 180 if the tag value of 180 for some reason gets skipped, this then script will never work again, so perhaps TimerValue.value >= 180 is more appropriate.

However, instead of making your own timer expression tag, you can also use system.util.getInactivitySeconds - Ignition User Manual 8.0 - Ignition Documentation to directly get the number of seconds since the user last touched the keyboard or mouse. So then you could do

inactiveSeconds = system.util.getInactivitySeconds()

if inactiveSeconds > 180:
    # Logout

Assuming you are working in vision.

I did not make an expression that counts up. I just monitor a value of a timer

I don’t like the inactivity because it resets every time someone touches the screen

Oh so are you saying you want to log them out no matter what after 3 minutes? Ok then yes don't use my method.

I did not make an expression that counts up. I just monitor a value of a timer

Ok, I don't see that tag on my projects, so I assume it must have been created. Can you check the tag definition to see if its an expression of some sort?

Again though the major problem as I see it is with TimerValue.value == 180 you are relying on your Timer Script which is running every 1 second to run through and reads the tag at the same exact moment your tag hits 180 - there is no guarantee of that. What happens if you do TimerValue.value >= 180? Does that fix the problem?