Multistate Button Expression

Been trying to create an expression for a multistate button. Essentially, I want the indicator to work off two tags not just one.
So, Hand=2, Off=1, and Auto=0 indicator value would be controlled by two boolean tags.
Tag 1=1 and Tag 2=0 then indicatorValue=2
Tag 1=0 and Tag 2=1 then indicatorValue=0
Tag 1=1 and Tag 2=1 then indicatorValue=1
Tag 1=0 and Tag 2=0 then indicatorValue=1
Been working on it but I keep getting a syntax error using the if statement option.

So, I think you just need to properly get the Expession syntax correct. You want to evaluate the 2 boolean tags into a single integer tag that returns, 0, 1, or 2. The code should be as simple as this:

if({[.]Tag1.value} && !{[.]Tag2.value}, 2, if(!{[.]Tag1.value} && {[.]Tag2.value}, 0,1))
2 Likes

That's a frankly wacky truth table - you aren't able to enforce this logic in the PLC somewhere? That'll likely be more maintainable ultimately.

Otherwise, as @Herbie posted, you definitely can do this with multiple ifs, but maintainability goes a bit out the window.

1 Like

Yes, it would be much easier through the PLC, but we are upgrading the HMI from WW to Ignition and don't want to touch PLC's, so I'm just copying what's already in place.

1 Like

Herbie,

So, looks like my syntax was slightly off, but with your response I was able to do exactly what I needed to do. Thank you very much!

1 Like