Toggle Switch link to integer tag

Hello everyone,

Thank you in advance for your time and insights on this topic. I am looking to control an integer tag on a PLC that represents different modes of program operation, with values ranging from 1 to 5. Specifically, a value of 2 indicates "Manual Mode."

I need to implement a toggle switch on the user interface that allows users to switch between "Auto" and "Manual." The desired behavior is as follows:

  • When the tag is set to 2, the toggle switch should indicate "Manual."
  • When the tag is set to 1, 3, 4, or 5, the toggle switch should indicate "Auto."

Additionally, I require this link to be bi-directional:

  • If the toggle switch is set to "Auto" and you change it to "Manual," the tag should set to 2.
  • Conversely, if the toggle switch is set to "Manual" and you change it to "Auto," the tag should set to 1.

I would appreciate any guidance on the best approach to establish this functionality.

Thank you!

Use a multi-state button.
Use two states, one with text Manual and value 2, one with text Auto and value 1

For the controlValue bind this to your tag with Bidirectional set to true.
For the indicatorValue, bind it to your tag, add transform, select script, use this script

def transform(self, value, quality, timestamp):
	if value > 2:
		return 1
	return value
1 Like

I agree that a multistate button is the appropriate component for this.

However, I'd change the indicatorValue binding to an expression binding:

if ({this.props.controlValue} = 2, 2, 1)

Thanks Victor, works the best!
I appreciate it.

Thanks Pascal for the hint. I'll use it.