# Timer script not working

**URL:** <https://forum.inductiveautomation.com/t/timer-script-not-working/52893>\
**Category:** Ignition\
**Created:** [November 9, 2021, 6:44pm UTC](https://forum.inductiveautomation.com/t/timer-script-not-working/52893 "2021-11-09T18:44:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [November 9, 2021, 6:44pm UTC](https://forum.inductiveautomation.com/t/timer-script-not-working/52893/1 "2021-11-09T18:44:51Z")

</div>

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:

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [November 9, 2021, 6:58pm UTC](https://forum.inductiveautomation.com/t/timer-script-not-working/52893/2 "2021-11-09T18:58:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 9, 2021, 6:59pm UTC](https://forum.inductiveautomation.com/t/timer-script-not-working/52893/4 "2021-11-09T18:59:29Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC80/system.util.getInactivitySeconds) to directly get the number of seconds since the user last touched the keyboard or mouse. So then you could do

```auto
inactiveSeconds = system.util.getInactivitySeconds()

if inactiveSeconds > 180:
    # Logout

```

Assuming you are working in vision.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [November 9, 2021, 7:11pm UTC](https://forum.inductiveautomation.com/t/timer-script-not-working/52893/5 "2021-11-09T19:11:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [November 9, 2021, 7:12pm UTC](https://forum.inductiveautomation.com/t/timer-script-not-working/52893/6 "2021-11-09T19:12:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 9, 2021, 7:16pm UTC](https://forum.inductiveautomation.com/t/timer-script-not-working/52893/7 "2021-11-09T19:16:10Z")

</div>

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?
