# Expression bool tag, Latch/Unlatch

**URL:** <https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720>\
**Category:** Ignition\
**Created:** [June 13, 2022, 9:30pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720 "2022-06-13T21:30:45Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darrell\_Henley](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Darrell\_Henley](https://forum.inductiveautomation.com/u/Darrell_Henley)\
**Post date:** [June 13, 2022, 9:30pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/1 "2022-06-13T21:30:45Z")

</div>

I’m trying to create a expression tag that becomes true when a value drops below a setpoint and becomes false when the tag value rises above a second setpoint.

If tag-x \< 140.0 then 1 if tag-x \> 140.5 then 0

I’m thinking it’s a nested if statement but I can’t seem to get it right.

Thanks in advance for you help

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 13, 2022, 10:08pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/2 "2022-06-13T22:08:04Z")

</div>

The only way I can think of doing this is to create two monitoring expression tags, the output tag and a couple of gateway event scripts to monitor those.

Tags:

```auto
tag_x
tag_x_high {[~]tag_x.value} > 140.5
tag_x_low {[~]tag_x.value} < 140.0
tag_x_hysteresis set by gateway tag event script

```

Then create a pair of gateway event tag change scripts on `tag_x_high` and `tag_x_low` and have these set or reset the `tag_x_hysteresis` tag.

It’s a bit complicated for what you want.  
I’m wondering if there’s some trick to using a tag’s deadband?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [June 13, 2022, 10:25pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/3 "2022-06-13T22:25:39Z")

</div>

Maybe i am missing something, but wouldn’t something like this do it?

```auto
if({[~]tag_x} < 140, 1 ,if({[~]tag_x} > 140.5, 0, null))

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 13, 2022, 10:45pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/4 "2022-06-13T22:45:22Z")

</div>

That will return `null` when between the limits. Bind a slider to the tag to try it out.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [June 13, 2022, 10:56pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/5 "2022-06-13T22:56:34Z")

</div>

instead of null couldn’t they just use the current value of the tag the expression is on?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [June 13, 2022, 10:57pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/6 "2022-06-13T22:57:10Z")

</div>

That is correct, since the OP did not specify what the value was to be when between points, i just assumed null.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 14, 2022, 10:00am UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/7 "2022-06-14T10:00:36Z")

</div>

What are you trying to do ? I mean, what’s the purpose of this ?

There might be easier, built-in ways to achieve it.

edit - Didn’t mean to reply to you, @Transistor, this was aimed at OP but I kinda missed the mark.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 14, 2022, 12:52pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/8 "2022-06-14T12:52:08Z")

</div>

> [@Matthew.gaitan](#):
>
> instead of null couldn’t they just use the current value of the tag the expression is on?

I think that will generate a circular reference (red triangle warning on the property editor).

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [June 14, 2022, 1:57pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/9 "2022-06-14T13:57:10Z")

</div>

Just put a third state(value) instead of null?  
Without knowing how it is being used though we are all just playing golf… 🙂

```auto
if({[~]tag_x} < 140, 1 ,if({[~]tag_x} > 140.5, 0, 3))

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 14, 2022, 2:12pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/10 "2022-06-14T14:12:20Z")

</div>

I hate nested `IFs` in expressions, they are too hard to read.

```auto
case(True,
    {[~]tag_x} < 140, 1
    {[~]tag_x} > 140.5, 0,
    3
)

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 14, 2022, 2:22pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/11 "2022-06-14T14:22:30Z")

</div>

> [@dkhayes117](#):
>
> I hate nested `IFs` ~~in expressions~~

Fixed that for you

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 14, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/12 "2022-06-14T15:29:02Z")

</div>

Diagnostic level alarm on the value.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/c/accd241357d26dd054db14335a5ec29ed807aace.png)

---

<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:** [June 14, 2022, 3:51pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/13 "2022-06-14T15:51:00Z")

</div>

I would use the `state` variable in my `objectScript()` expression function.

---

<div class="post-metadata">

**Author:** ![Darrell\_Henley](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Darrell\_Henley](https://forum.inductiveautomation.com/u/Darrell_Henley)\
**Post date:** [June 16, 2022, 3:38pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/14 "2022-06-16T15:38:54Z")

</div>

Thank you all for the input. I will try out some of your suggestions and see if I can get one to work for what I am after.

Jordan - I’m liking the alarm solution. Does the deadband only apply to the clearing of the alarm? I had thought about that but wasn’t sure.

What I am doing it creating a trigger (BOOL) for a transaction that automatically creates a note in Note Chart when the temperature drops below 140.0 and resets when the temp rises above 140.5 to prevent multiple triggers for basically the same event if it is bouncing at 140.001. My other option is to create the logic in PLC and just use a latch and unlatch but I try not to do Ignition logic in PLC.

I appreciate everyone’s time. I will be back on this project next week and will update on which way I went.  
Thanks again,  
Darrell

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 16, 2022, 5:18pm UTC](https://forum.inductiveautomation.com/t/expression-bool-tag-latch-unlatch/60720/15 "2022-06-16T17:18:55Z")

</div>

> [@Darrell\_Henley](#):
>
> Jordan - I’m liking the alarm solution. Does the deadband only apply to the clearing of the alarm? I had thought about that but wasn’t sure.

That was how it worked when I tested it.
