Dynamic Background Binding based on Limits

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.

What version of Ignition are you using?


8.0.2 to be exact

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

Thanks in Advance…

Im back

Any ideas?

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.

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

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.

Thanks Ill give this a go.

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

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

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…

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


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.

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.

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

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

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>)))