case(
true,
valveOpenedTag, "Opened",
valveClosedTag, "Closed",
FailtocloseTag, "Failed to Close",
"Unknown"
)
That's an interesting use of the case()
function. At first glance I thought it wouldn't work. It does - but there may be a problem.
From case:
It takes the value argument and compares it to each of the case1 through caseN expressions. If value is equal to caseX, then case returns valueX. If value is not equal to any of the case1..N, then returnDefault is returned.
That means that if more than one status tag is true that it will return the first.
I would use binEnc to generate a unique integer for any combination of status bits and use that in the case()
expression.
case(
binEnc(
{[~]valveOpen}, // 1 (LSB)
{[~]valveClosed}, // 2
{[~]failedToClose}, // 4 (MSB)
),
0, "Valve moving",
1, "Opened",
2, "Closed",
4, "Failed to Close",
"Error"
)
This way we get an "Error" if more than two states are on and the 0
option suppresses the error while the valve is changing state normally until the failedToClose turns on.
@Ryan_Hankins note that you have no failedToOpen
warning.
Expressions are much faster than scripts. Use them in preference where possible.