# Timer Script for Active Alarms

**URL:** <https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821>\
**Category:** Ignition\
**Created:** [July 14, 2021, 12:07pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821 "2021-07-14T12:07:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@tim1](https://forum.inductiveautomation.com/u/tim1)\
**Post date:** [July 14, 2021, 12:07pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821/1 "2021-07-14T12:07:53Z")

</div>

I am using Ignition version 8.1.3 and Vision.

The customer wants Ignition to tell the PLC if there are alarms active so that a buzzer/horn will sound when there are active alarms. A discussion with a coworker produced the following script:

```auto
#tag.quality needs to be "Good" or else the value cannot be trusted
#tag.value is the 'value' you would proceed to use, if the .quality was found to be "Good"

#logger = system.util.getLogger("MiscDebug")
#logger.info("Misc -Start-")

tagPath = "[Modicon]HR1005.2" #Flat Robot E Stop
tagPath2 = "[Modicon]HR1005.3" #Vial Robot E Stop
tagPath3 = "[Modicon]HR1005.4" #PB2519 E Stop
tagPath4 = "[Modicon]HR1005.5" #PB2520 E Stop
tagPath5 = "[Modicon]HR1005.6" #PB2521 E Stop
tagPath6 = "[Modicon]HR1005.7" #PB2522 E Stop
tagPath7 = "[Modicon]HR1005.8" #PB2532 E Stop
tagPath8 = "[Modicon]HR1005.9" #PB2533 E Stop
tagPath9 = "[Modicon]HR1005.10" #PB2534 E Stop
tagPath10 = "[Modicon]HR1005.11" #PB2535 E Stop
tagPath11 = "[Modicon]HR1005.12" #PB2536 E Stop
tagPath12 = "[Modicon]HR1000.8" #Label Printer Fault
tagPath13 = "[Modicon]HR1000.9" #Label Printer Out of Ink
tagPath14 = "[Modicon]HR1004.9" #Safety Enabled
tagPath15 = "[Modicon]HR1004.3" #Tray with No ID
tagPath16 = "[Modicon]HR1005.0" #HMI Alarm Present (Tells PLC there is an alarm)

#read tag
readTag = system.tag.readBlocking(tagpath)

if str(readTag.quality) == "Good":

	tagValue = readTag.value
	#logger.info("tagValue : " + str(tagValue))
	
	if tagValue: #if true or non-zero
	
		#update value to be written to tagPath16
		result = true
	
		#write tag
		system.tag.writeBlocking("[Modicon]HR1005.0", 1)
	
	else:
		#update value to be written to tagPath16
		result = false
		
		#write tag
		system.tag.writeBlocking("[Modicon]HR1005.0", 0)
		
#logger.info("Misc -Done-")

```

I’ve tried it as a Gateway Timer Script and a Client Timer Script. Both set to run every 1,000 ms or 1 second. We make an alarm go off and nothing happens as far as the audible for alarms being active.  
My questions are  
A) should this be in the gateway or the client?  
B) what is wrong with the code or what code should I be using?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 14, 2021, 12:19pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821/2 "2021-07-14T12:19:58Z")

</div>

A) Gateway for sure. If in the client, and no client is running, your code won’t run. If you have multiple clients running, they’ll _ **all** _ be running this code and hammering the PLC.

B) You are mis-using readBlocking. It takes a _ **list** _ of tagPaths and returns a _ **list** _ of `QualifiedValue` results.

---

<div class="post-metadata">

**Author:** ![tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@tim1](https://forum.inductiveautomation.com/u/tim1)\
**Post date:** [July 14, 2021, 12:35pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821/3 "2021-07-14T12:35:55Z")

</div>

> [@pturmel](#):
>
> You are mis-using readBlocking. It takes a _ **list** _ of tagPaths and returns a _ **list** _ of `QualifiedValue` results.

Instead of using readBlocking, what should I be using?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 14, 2021, 12:40pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821/4 "2021-07-14T12:40:07Z")

</div>

You’re using the correct function, you are just not using it correctly.

```auto
tagQVs = system.tag.readBlocking(['tagPath','tagPath1','tagPath2'])

for tagValue in tagQVs:
    print tagValue.value

```

NOTE: I used generic strings to represent the tag paths, this code will not function.

---

<div class="post-metadata">

**Author:** ![tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@tim1](https://forum.inductiveautomation.com/u/tim1)\
**Post date:** [July 14, 2021, 12:52pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821/5 "2021-07-14T12:52:09Z")

</div>

> [@lrose](#):
>
> ```auto
> tagQVs = system.tag.readBlocking(['tagPath','tagPath1','tagPath2'])
> 
> for tagValue in tagQVs:
> print tagValue.value
> 
> ```

Ok. Do I insert this at my readBlocking point and put in each tagpath where you used generic strings for tag paths?

Do I need all the stuff in my code about the quality being "good"?

I don't see any documentation on "tagQVs" could you elaborate please?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 14, 2021, 1:24pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821/6 "2021-07-14T13:24:50Z")

</div>

> [@tim1](#):
>
> Ok. Do I insert this at my readBlocking point and put in each tagpath where you used generic strings for tag paths?

You can do this, or you can build a list and supply that to the functioin.

> [@tim1](#):
>
> Do I need all the stuff in my code about the quality being “good”?

That is dependent upon your specific use case. If you care that you only do something when a tag's quality is good then leave it.

> [@tim1](#):
>
> I don’t see any documentation on “tagQVs” could you elaborate please?

tagQVs is just a vairiable. I name my variables base on the type or types that it holds, in this case a list of Qualified Values.

---

<div class="post-metadata">

**Author:** ![tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@tim1](https://forum.inductiveautomation.com/u/tim1)\
**Post date:** [July 14, 2021, 1:44pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821/7 "2021-07-14T13:44:53Z")

</div>

> [@lrose](#):
>
> You can do this, or you can build a list and supply that to the function.

Can I use the list I've already created by modifying it somehow or do I need another list?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 14, 2021, 2:09pm UTC](https://forum.inductiveautomation.com/t/timer-script-for-active-alarms/48821/8 "2021-07-14T14:09:29Z")

</div>

Okay, so I would recommend that you do some research into python, there are several great resources out there for that.

Technically speaking you haven't created a list (even though it may look that way) instead you have created several variables holding string values.

In python a 'list' is a type of data sequence denoted by surrounding comma separated values with square brackets `[]`.

For instance a list of integers could be `[1,2,3,4]`.

In my code I created a list _ **inline** _ by surrounding the strings with `[]`. You could also create the list separately and hold it in a variable.

```auto
 tagPaths = ["[Modicon]HR1005.2","[Modicon]HR1005.3","[Modicon]HR1005.4","[Modicon]HR1005.5" , "[Modicon]HR1005.6","[Modicon]HR1005.7","[Modicon]HR1005.8","[Modicon]HR1005.9","[Modicon]HR1005.10","[Modicon]HR1005.11","[Modicon]HR1005.12", "[Modicon]HR1000.8","[Modicon]HR1000.9","[Modicon]HR1004.9", "[Modicon]HR1004.3","[Modicon]HR1005.0"]

tagQVs = system.tag.readBlocking(tagPaths) #NOTE the missing [], because tagPaths is already a list

```

Alternatively you can also use the append function of the list to add elements

```auto
tagPaths = []
tagPaths.append('New Tag Path')

```

Again, I would highly recommend that you work on getting a better understanding of python. Not only will it help you in writing the code but also in understanding replies to questions on the forum. Because despite our best efforts our answers can be somewhat cryptic to the uninitiated. 😉

Here's a good post on where to hone your skills, also I can't recommend [Inductive University](https://inductiveuniversity.com/) enough.

> [@How Can I (EE Student) Practice and Work on My Ignition Skills?](http://forum.inductiveautomation.com/t/how-can-i-ee-student-practice-and-work-on-my-ignition-skills/35564):
>
> Hello there, I have somewhat of a weird question. I’m currently headed into my Junior year of school to become an EE. Ideally, I would like to go into controls and automation so I’ve been learning Ignition and got my core certification about a month ago. My issue is that I don’t have any internships or a job in the field yet so I don’t want to lose all of the valuable information with Ignition that I’ve learned so far. I do have an internship lined up for next summer, but that still being a year…
