Expression bool tag, Latch/Unlatch

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

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:

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?

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

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

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

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

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

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.

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

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

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

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

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

Fixed that for you

3 Likes

Diagnostic level alarm on the value.

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

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

That was how it worked when I tested it.

1 Like