if event.propertyName == 'Tag2' and event.newValue > event.oldValue:
event.source.state = 0
elif event.propertyName == 'Tag1' and event.newValue > event.oldValue:
event.source.state = 1
This is the script I'm using to trigger two states based on which one changes. If I add a third state which is "empty" and only supposed to come on when Tag1 and Tag2 are 0. How do I add the third tag in there.
if event.propertyName == "Tag2":
#If new value is 0 and other tag value is 0, mark as empty state
if not event.newValue and not event.source.Tag1:
event.source.state = 2
#Mark as state 0 if new value is larger than old
elif event.newValue > event.oldValue:
event.source.state = 0
elif event.propertyName == "Tag1":
#If new value is 0 and other tag value is 0, mark as empty state
if not event.newValue and not event.source.Tag2:
event.source.state = 2
#Mark as state 1 if new value is greater than old
elif event.newValue > event.oldValue:
event.source.state = 1
Tag 1 and Tag 2 correspond to state 1(fail) and 2(pass) respectively. But I have a tag 3 which in itself turns 1 when tag 1 and 2 are 0. So I can now use tag 3 to dictate the state 3(hide), or use the condition when tag 1 and 2 equals 0, event.source = 2.
The code I provided in my previous reply would check for the tag firing the event and other tag (tag 1 and tag2) to both be zero and set the state to 2 if they were both 0. Otherwise it would follow the normal logic you had originally.
If you want it to look at the value of Tag 3 instead, add the following to the end of your original script:
elif event.propertyName == "Tag3" and event.newValue:
event.source.state = 2
Consider ditching all scripting and adding an additional custom property using the binEnc
expression function:
https://docs.inductiveautomation.com/display/DOC81/binEnc
2 Likes
I tried your previous code and the added the last code to my original code as well. But it does not toggle to the third state. Only displays the pass and fail indicator.
I don't think any other option should be considered other than using an expression here
binEnc({Tag1}, {Tag2}, {tag3} )
Will get you a binary encoded integer from 0 to 7 where Tag1 on = 1, Tag2 on = 2, tag3 on = 4
3 Likes