Dynamic Background Binding based on Limits

#1

I have been searching for examples of binding the background color of a field to limit values.
Have not had any luck.

I am trying to establish color(?,?,?) based on

If (PV < H_Level Then color (WHITE)
If (PV > H_Level) && (PV < HH_Level) Then color(ORANGE)
Else If (PV > HH_Level) Then color (RED)…

Seems like it should be straight forward but I am getting nowhere…

Any help would be appreciated.

0 Likes

#2

What version of Ignition are you using?

0 Likes

#3

8.0

0 Likes

#4

8.0.2 to be exact

0 Likes

#5

I have to run to a production issue.
I’ll check back later…

Thanks in Advance…

0 Likes

#6

Im back

0 Likes

#7

Any ideas?

0 Likes

#8

Could you provide more information regarding your script; where does this script reside? Are you trying to conditionally change the background via an expression binding or a script?

Assuming you’re writing the script in an expression binding have a look at these pages in the help manual.
expression if statement: https://docs.inductiveautomation.com/display/DOC80/if
expression toColor(): https://docs.inductiveautomation.com/display/DOC80/toColor

you’re syntax:

(PV < H_Level Then color (WHITE)
If (PV > H_Level) && (PV < HH_Level) Then color(ORANGE)
Else If (PV > HH_Level) Then color (RED)…

transforms into:

if (PV < H_Level, // first if condition
	"white", // true
	if (PV > H_Level && PV < HH_Level, // else if
		"orange", // true
		if( PV > HH_Level, // else if
			"red", // true
			"gray" // else
		)
	)
)

Keep in mind you’ll need to point your conditionals (PV, H_Level, HH_Level) to tags or properties.
Cheers.

0 Likes

#9

Yes. I was looking to do this in the background binding of a numerical display field…

0 Likes

#10

if({pv} < {H_Level}, color(255,255,255), if({pv} < {HH_Level}, color(255,153,51), color(255,0,0)))
(pseudo-code - please provide the correct interpolation assignments)
as an expression in Vision. If you’re using Perspective, I can provide a mapping solution, but I have a meeting so it will be a bit before I can do so.

0 Likes

#11

Thanks Ill give this a go.

0 Likes

#12

The following screenshot is a Perspective binding with transforms which would do what you want without needing to create the colors from expressions.

0 Likes

#13

OK. That would be a cleaner method.
It’s the syntax that is new to me.

0 Likes

#14

I am not sure but I think there is an issue because this in in a UDT

IF ({Report_Static.SILO_ID::AMOUNT} < {Report_Static.SILO_ID::H_Warn}),0
IF ({Report_Static.SILO_ID::AMOUNT} > {Report_Static.SILO_ID::H_Warn} &&
({Report_Static.SILO_ID::AMOUNT} < {Report_Static.SILO_ID::HH_Alarm})1
IF ({Report_Static.SILO_ID::AMOUNT} > {Report_Static.SILO_ID::HH_Alarm},2

Does not compile…

0 Likes

#15

IF ({Report_Static.SILO_ID::AMOUNT} < {Report_Static.SILO_ID::H_Warn}),0
IF ({Report_Static.SILO_ID::AMOUNT} > {Report_Static.SILO_ID::H_Warn} &&
({Report_Static.SILO_ID::AMOUNT} < {Report_Static.SILO_ID::HH_Alarm}),1
IF ({Report_Static.SILO_ID::AMOUNT} > {Report_Static.SILO_ID::HH_Alarm},2

Actually

0 Likes

#16

Perhaps because you’re missing the closing parentheses? Could you make sure you’ve copied the entire expression function, then paste it between triple ticks? “```your code here```”
Also, you’re missing commas after values.
Also also, the final expression requires three arguments and you’ve only supplied two.

0 Likes

#17
IF ({Report_Static.SILO_ID::AMOUNT} < {Report_Static.SILO_ID::H_Warn},0,
IF ({Report_Static.SILO_ID::AMOUNT} > {Report_Static.SILO_ID::H_Warn} &&
{Report_Static.SILO_ID::AMOUNT} < {Report_Static.SILO_ID::HH_Alarm},1,
IF ({Report_Static.SILO_ID::AMOUNT} > {Report_Static.SILO_ID::HH_Alarm},2, 3)))

Evaluates for me. I added closing parentheses to the end, I removed unnecessary parentheses, I added commas, and I added a final argument to the final expression.

0 Likes

#18

Also, you should be careful because you’re excluding instances where {Report_Static.SILO_ID::AMOUNT} is EQUAL TO your H_XXXXX values.

0 Likes

#19

Ignition 8.0.3 does not seem to have access to add the relationship for the binding transforms for the background color of a numerical label. Was away on a commissioning so still working through this background color change issue

0 Likes

#20

Transforms are available in Perspective, not Vision, so you would not have the Mapping transform available to you, and would need to supply the color values within the expression, instead of supplying numeric values which would be transformed by the Mapping transform into colors.

IF ({Report_Static.SILO_ID::AMOUNT} < {Report_Static.SILO_ID::H_Warn}, <good_color_here>,
IF ({Report_Static.SILO_ID::AMOUNT} > {Report_Static.SILO_ID::H_Warn} &&
{Report_Static.SILO_ID::AMOUNT} < {Report_Static.SILO_ID::HH_Alarm},<warning_color_here>,
IF ({Report_Static.SILO_ID::AMOUNT} > {Report_Static.SILO_ID::HH_Alarm},<critical_color_here>, <fallback_color_here>)))
0 Likes