# Write an expression using a script on alarm

**URL:** <https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [January 9, 2026, 4:36am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171 "2026-01-09T04:36:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 9, 2026, 4:36am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/1 "2026-01-09T04:36:10Z")

</div>

Hi everyone,

I would like to be able to create a script that changes the alarm expression, I managed to get it this far but it only accepts integers or floats if I do an expression it doesnt work:

```python
def rebuild_alarm_with_expression(tag_path):
    configs = system.tag.getConfiguration(tag_path, True)
    if not configs:
        return

    config = configs[0]

    
    config["alarms"] = []

    alarm = {
        "name": "Critical",
        "mode": "OutsideValues",
        "priority": "Critical",
        "enabled": True,

        
        "setpointA": '{[.]temp_1_sp} - 25',
        "setpointB": '{[.]temp_1_sp} + 25'
        
    }

    config["alarms"].append(alarm)

    parent_path = tag_path.rsplit("/", 1)[0]
    config["name"] = tag_path.rsplit("/", 1)[1]

    system.tag.configure(parent_path, [config], "o")

rebuild_alarm_with_expression("[default]HMIs/test/tag_temp_1")

```

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [January 9, 2026, 4:57am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/2 "2026-01-09T04:57:48Z")

</div>

what is not working about the expression? Are you getting any errors?

---

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 9, 2026, 4:58am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/3 "2026-01-09T04:58:53Z")

</div>

No errors just wont change the value, if I put in a 20 for instance it’ll show 20 but if I then put this '{[.]temp\_1\_sp} - 25', it’ll still show the 20 so it wont accept it

---

<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:** [January 9, 2026, 7:14am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/4 "2026-01-09T07:14:10Z")

</div>

Create the tag alarm with the expression you want, or an example at least, and see check the tag json. It's going to have an object value instead of a string

---

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 9, 2026, 7:30am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/5 "2026-01-09T07:30:11Z")

</div>

This would be the json of a test tag with what I would want to be written in the script:

`{`  
`"valueSource": "memory",`  
`"alarms": [`  
`{`  
`"mode": "OutsideValues",`  
`"name": "Critical",`  
`"label": "Test Tag 1 Critical",`  
`"priority": "High",`  
`"displayPath": "Test Tag 1 Critical",`  
`"setpointA": {`  
`"bindType": "Expression",`  
`"value": "{[.]TestSP} - 5"`  
`},`  
`"setpointB": {`  
`"bindType": "Expression",`  
`"value": "{[.]TestSP} + 5"`  
`}`  
`}`  
`],`  
`"name": "testTag",`  
`"value": 1,`  
`"tagType": "AtomicTag"`  
`}`

---

<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:** [January 9, 2026, 7:48am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/6 "2026-01-09T07:48:28Z")

</div>

> [@scadafan](#):
>
> `{`  
> `"bindType": "Expression",`  
> `"value": "{[.]TestSP} + 5"`  
> `}`

So you can see that this is the value of setpoint A, which is what you need to configure it with

---

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 9, 2026, 7:50am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/7 "2026-01-09T07:50:52Z")

</div>

I tried this but it still isnt working

```python
def rebuild_alarm_with_expression(tag_path):
    configs = system.tag.getConfiguration(tag_path, True)
    if not configs:
        return

    config = configs[0]

    
    config["alarms"] = []

    alarm = {
      "mode": "OutsideValues",
      "name": "Critical",
      "label": "Test Tag 1 Critical",
      "priority": "High",
      "displayPath": "Test Tag 1 Critical",
      "setpointA": {
        "bindType": "Expression",
        "value": "{[.]TestSP} - 5"
      },
      "setpointB": {
        "bindType": "Expression",
        "value": "{[.]TestSP} + 5"
      }
    }

    config["alarms"].append(alarm)

    parent_path = tag_path.rsplit("/", 1)[0]
    config["name"] = tag_path.rsplit("/", 1)[1]

    system.tag.configure(parent_path, [config], "o")

rebuild_alarm_with_expression("[default]HMIs/test/tag_temp_1")

```

---

<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:** [January 9, 2026, 8:17am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/8 "2026-01-09T08:17:24Z")

</div>

Any errors? I’d add print statements to see what it's doing

---

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 9, 2026, 8:28am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/9 "2026-01-09T08:28:24Z")

</div>

no errors but it also isnt actually writing anything the new tag

---

<div class="post-metadata">

**Author:** ![Nol](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Nol](https://forum.inductiveautomation.com/u/Nol)\
**Post date:** [January 9, 2026, 4:37pm UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/10 "2026-01-09T16:37:17Z")

</div>

Curious so I asked the AI overlords. Seems to be an issue with configure trying to overwrite read-only values when you write it back in. It suggested to only build alarms and name in config and then use "m" to merge instead of overwrite. There is also an example #3 in the documentation you can reference as an example though that's for creating one rather than modifying one.

> **[system.tag.configure | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-configure)**
>
> Creates tags from a given list of Python dictionaries or from a JSON source string.

> This code fails silently because of how `system.tag.getConfiguration` and `system.tag.configure` interact.
> 
> You are fetching the **entire** configuration of the tag (including read-only properties like `lastModified`, `quality`, `tagPath`, `accessRights`, etc.) and feeding it straight back into `configure`.
> 
> When `system.tag.configure` sees these read-only properties in "Overwrite" (`"o"`) mode, it often rejects the update or behaves unpredictably because it cannot overwrite those system-managed properties.
> 
> **Collision Policy "m" (Merge):**
> 
> - Using `"o"` (Overwrite) on a tag when you only provide the `alarms` property is dangerous. It might convert your tag into a generic Folder or remove its Data Type.
> - Using `"m"` (Merge) ensures we only update the `alarms` list without touching the rest of the tag configuration.

---

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 9, 2026, 5:02pm UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/11 "2026-01-09T17:02:51Z")

</div>

I saw this too, the problem is that it works fine if I just write an integer but if I write an expression that is when it does nothing

---

<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:** [January 9, 2026, 6:23pm UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/12 "2026-01-09T18:23:55Z")

</div>

Expressions are only auto-interpreted in the designer. In a configure script, you have to provide the **object** (dictionary, typically) that represents the binding expression, and it cannot be set with `system.tag.write*()`.

---

<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:** [January 10, 2026, 10:08pm UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/13 "2026-01-10T22:08:02Z")

</div>

I would typically use merge here as well, instead of overwrite, but both should work here

---

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 11, 2026, 12:23am UTC](https://forum.inductiveautomation.com/t/write-an-expression-using-a-script-on-alarm/113171/14 "2026-01-11T00:23:21Z")

</div>

Could you give me an example of this in action? I'm still confused on what you mean
