# Alarm Scripting - Add alarms to existing tags

**URL:** <https://forum.inductiveautomation.com/t/alarm-scripting-add-alarms-to-existing-tags/104432>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 30, 2025, 8:31pm UTC](https://forum.inductiveautomation.com/t/alarm-scripting-add-alarms-to-existing-tags/104432 "2025-03-30T20:31:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbernauer](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@sbernauer](https://forum.inductiveautomation.com/u/sbernauer)\
**Post date:** [March 30, 2025, 8:31pm UTC](https://forum.inductiveautomation.com/t/alarm-scripting-add-alarms-to-existing-tags/104432/1 "2025-03-30T20:31:22Z")

</div>

I am working on some alarming in perspective. I have a tag provider setup to hold my tags that I would like to create alarms on. I have added my tags to the tag browser via the OPC browse device feature.

I would like to create alarms on specific tag structures. Something along the lines of if the tag names tags this, add this type of alarm.

I started scripting this as I need to do it for lots of these guys. I noticed that the alarm would not create on the tag.

The script I have so far is below. It does not apply the alarm to the tag when I check in the tag browser, I can manually apply the alarm no problem...

```python
def addAlarmToSpecificTag():
    """
    Adds a basic alarm to the tag target tag
    """
    tagName = "[Alarming]Test/ER200_LIT21_TEST/bHAlm" # The tag we want to update

    try:
        # Get the current tag configuration, including alarms
        tagConfig = system.tag.getConfiguration(tagName, True)

        # Define the alarm name and configuration
        alarmName = "ER200_LIT21 TEST"
        alarms = [
            {
                "name": alarmName,  
                "mode": "AboveValue",  
                "setpointA": 1.0  
            }
        ]

        # Ensure alarms exist in the tag configuration
        if 'alarms' not in tagConfig[0]:
            tagConfig[0]['alarms'] = []

        # Add the alarm to the list of alarms (or replace if needed)
        tagConfig[0]["alarms"].append({
            "name": alarmName,
            "mode": "AboveValue",
            "setpointA": 1.0
        })

        # config tag with the modified alarm settings
        system.tag.configure(tagName, tagConfig, overwrite=True)

        # Check
        updatedTagConfig = system.tag.getConfiguration(tagName, True)
        print("Updated configuration for tag " + tagName + ": " + str(updatedTagConfig))

    except Exception as e:
        print("Error configuring alarm for tag " + tagName + ": " + str(e))

addAlarmToSpecificTag()

```

I based the structure for this off the _system.tag.configure_  
[system.tag.configure](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-configure)

---

<div class="post-metadata">

**Author:** ![sbernauer](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@sbernauer](https://forum.inductiveautomation.com/u/sbernauer)\
**Post date:** [March 30, 2025, 8:54pm UTC](https://forum.inductiveautomation.com/t/alarm-scripting-add-alarms-to-existing-tags/104432/2 "2025-03-30T20:54:57Z")

</div>

I found another post that discussed writing to the child vs parent tag.

[Script for adding tag alarm](https://forum.inductiveautomation.com/t/script-for-adding-tag-alarm/94639/3)

I was able to write to a specific tag using the below code.

```python
foo = system.tag.getConfiguration("[Alarming]Test/ER200_LIT21_TEST/bHAlm")[0]

foo['alarms'] = [
    {
    "name": "TEST ALARM",
    "enabled": True,
    "Priority": "Medium",
    "Mode": "Equal",
    "setpointA": 1.0,
    }
]

system.tag.configure("[Alarming]Test/ER200_LIT21_TEST/", foo)

```

Looks like I may have been over complicating it. I will tinker with the script from here.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 30, 2025, 11:48pm UTC](https://forum.inductiveautomation.com/t/alarm-scripting-add-alarms-to-existing-tags/104432/3 "2025-03-30T23:48:46Z")

</div>

> [@sbernauer](#):
>
> ```python
> # Ensure alarms exist in the tag configuration
> if 'alarms' not in tagConfig[0]:
> tagConfig[0]['alarms'] = []
> 
> ```

the pythonic way to do this is:

```python
alarms = tagConfig[0].setdefault('alarms', [])
alarms.append(...)

```

However, if your configuration does have an "alarms", then this will append a new alarm which may not be what you want, and simply replacing the alarms kay value with a new list as you do in your second post is the way to go.

> [@sbernauer](#):
>
> `system.tag.getConfiguration`

Just a caution when using getConfiguration with tags in a UDT instance: this will get all of the overridden prop configuration for the tag(s), including those from the UDT Definition, and writing this back with `tag.configure` will apply overrides at the instance for those props which you most likely don't want. Using it for standard tags not part of udt instances is fine though
