Trigger UDT alarm based on two UDT values

we have a device with a multifunction input. when in digital mode, it can sample 4-20mA (Hi/Lo) or it can count flow pulses. the kink is the device reports either voltage OR the pulse count as a float; there is no discrete values for either one. just reports to MQTT as value. there is a boolean that determines this state: isPulseCount and a string that reports port type: din or curr_mA.

the alarm needs to be triggerable when the isPulseCount is 0 AND when port type is din. i flat out do not know how to set this up correctly. at present, this is what i have attempted in my UDT settings:

Screenshot 2024-02-15 131529

i know this is wrong, because it's not really the setpoint i'm trying to configure here, but i had to build the expression somewhere. now, i am very new to building alarms themselves, so be gentle. :face_with_peeking_eye: as i'm typing this, i don't think this is the even the right place to have this logic, but since it's tied to the UDT tag, i'm expecting some greater logic capability. can someone please guide me here?

EDIT: i think i found it. i can create a binding on the Enabled property and then just set the Mode to Equal and set the Setpoint value to 1. am i correct?

Make an expression tag that evaluates both source tags and yields the desired boolean. Then define the alarm on the expression.

1 Like

ooh! is that better than what i found?

Yes, it's better, because bindings in tag definitions don't actually subscribe to other tags. They evaluate only on tag restart, or for alarm properties, only when the alarm fires. So once your binding disables the alarm, it'll never fire again, and therefore won't ever re-evaluate whether it should be enabled again.

Arguably, you could make a change event script on the portType tag write to the alarm enable property on the other tag.

2 Likes

um, yeah. that's... uh... way better. :stuck_out_tongue: i much prefer 'it works' over 'it worked once and never again good luck debugging me you filthy casual'.

1 Like

so this is what i built:

is that what you were talking about? from my understanding, when that expression evaluates to true, the alarm can then be triggered. otherwise, it will just function as 'usual'.

1 Like

Looks right. (Didn't do a deep dive.)

works well, so thank you very much! :100:

This is a micro-optimization, but there's no point in an if(condition, true, false) in expressions, especially if the return value is boolean. By definition, the equality operator returns a boolean, and even if it didn't, the expression's output value would be coerced to a boolean by the tag system after it was evaluated.
That is:
if(condition, true, false)
Is always a more verbose, slightly less efficient way of writing:
condition

3 Likes

i'm always looking out for these kind of things. they satisfy an obscure itch deep in my nerd-brain. thank you! :+1:

so just {[.]portType} = 'din' && !{[.]isPulseCount} will do the do. nice. :100: