# Group OPC Tag in the same condition

**URL:** <https://forum.inductiveautomation.com/t/group-opc-tag-in-the-same-condition/45698>\
**Category:** Ignition\
**Tags:** ignition81, ignition78, scripting, ignition79, ignition80\
**Created:** [April 16, 2021, 7:40pm UTC](https://forum.inductiveautomation.com/t/group-opc-tag-in-the-same-condition/45698 "2021-04-16T19:40:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![antonio.sanchez](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@antonio.sanchez](https://forum.inductiveautomation.com/u/antonio.sanchez)\
**Post date:** [April 16, 2021, 7:40pm UTC](https://forum.inductiveautomation.com/t/group-opc-tag-in-the-same-condition/45698/1 "2021-04-16T19:40:02Z")

</div>

Hello

I have the following situation,

I have 4 boolean OPC tags that are activated when the PLC goes into error and when it is restored it turns off.

for this I am grouping it with a case

In the case that they are not activated the status would be = 1 but if some or all are activated the status would be = 3

but it is not respecting the second condition even if it is met

```auto
case(true,{[.]On_Off_FBW}&&(!{[.]Falla safety fance open 1}||!{[.]AreaSafety Fence Open2}||!{[.]Emergency Stop}||!{[.]PLC Errror}),1,
({[.]Falla safety fance open 1}||{[.]AreaSafety Fence Open2}||{[.]Emergency Stop}||{[.]PLC Errror})&&{[.]On_Off_FBW},3,10)

```

In some cases, two or one can be turned on, or all the tags can be turned on.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [April 16, 2021, 7:54pm UTC](https://forum.inductiveautomation.com/t/group-opc-tag-in-the-same-condition/45698/2 "2021-04-16T19:54:42Z")

</div>

I don’t believe you are using a case correctly. The spot that you have ‘true’ would need to be a value of some sort that you are matching to. That could be a string. Then the spot where your trying to test your bool’s would be a corresponding value that your looking for to match where you have ‘true’. the 1 or 3 is what would then be returned.

In this example it would return ‘five’:

```auto
case(5
	,1,'one'
	,2,'two'
	,3,'three'
	,4,'four'
	,5,'five'
	,'error')

```

This one would return ‘error’:

```auto
case(6
	,1,'one'
	,2,'two'
	,3,'three'
	,4,'four'
	,5,'five'
	,'error')

```

I’m returning a string but you can also return an integer or other value.

I’d look into using [binEnc()](https://docs.inductiveautomation.com/display/DOC81/binEnc). Your bools that you want to test you can put into there. That will return a value based on which bools are true. Then you can use that where you have ‘true’ in your case and have it return the 1 or 3 your looking for based on the value returned from the binEnc().

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 16, 2021, 9:44pm UTC](https://forum.inductiveautomation.com/t/group-opc-tag-in-the-same-condition/45698/3 "2021-04-16T21:44:41Z")

</div>

Putting everything on a single line is also asking for trouble, as it becomes incredibly difficult to read and work out exactly what the conditions are. Code for your future self who has forgotten what the project does

```auto
If(
    {[.]On_Off_FBW} && 
    (
     !{[.]Falla safety fance open 1} || 
     !{[.]AreaSafety Fence Open2} || 
     !{[.]Emergency Stop} ||
     !{[.]PLC Errror}
    ), 
    1,
If(
    (
     {[.]Falla safety fance open 1} ||
     {[.]AreaSafety Fence Open2} ||
     {[.]Emergency Stop} ||
     {[.]PLC Errror}
    ) &&
    {[.]On_Off_FBW}, 
    3,
// else
    10
)) 

```

---

<div class="post-metadata">

**Author:** ![antonio.sanchez](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@antonio.sanchez](https://forum.inductiveautomation.com/u/antonio.sanchez)\
**Post date:** [April 19, 2021, 8:30pm UTC](https://forum.inductiveautomation.com/t/group-opc-tag-in-the-same-condition/45698/4 "2021-04-19T20:30:29Z")

</div>

Thank you very much for the advice, only that testing the code does not change when the condition is met, it remains at 1 only.

---

<div class="post-metadata">

**Author:** ![antonio.sanchez](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@antonio.sanchez](https://forum.inductiveautomation.com/u/antonio.sanchez)\
**Post date:** [April 19, 2021, 9:23pm UTC](https://forum.inductiveautomation.com/t/group-opc-tag-in-the-same-condition/45698/5 "2021-04-19T21:23:52Z")

</div>

it only changes from condition 1 to condition 10 but condition 3 does not take it when it meets it

```auto
case(
	true,{[.]On_Off_FBW}&&
	(
	 !{[.]Falla safety fance open 1}||
	 !{[.]AreaSafety Fence Open2}||
	 !{[.]PLC Errror}||
	 !{[.]Emergency Stop}||
	 !{[.]Boton_paro_Rim}
	),
	1,
(
	 {[.]Falla safety fance open 1}||
	 {[.]AreaSafety Fence Open2}||
	 {[.]PLC Errror}||
	 {[.]Emergency Stop}||
	 {[.]Boton_paro_Rim}
	)&&
	{[.]On_Off_FBW},
	3,
//else
	10
)

```

```auto
If(
	{[.]On_Off_FBW}&&
	(
	 !{[.]Falla safety fance open 1}||
	 !{[.]AreaSafety Fence Open2}||
	 !{[.]PLC Errror}||
	 !{[.]Emergency Stop}||
	 !{[.]Boton_paro_Rim}
	),
	1,
If(
	(
	 {[.]Falla safety fance open 1}||
	 {[.]AreaSafety Fence Open2}||
	 {[.]PLC Errror}||
	 {[.]Emergency Stop}||
	 {[.]Boton_paro_Rim}
	)&&
	{[.]On_Off_FBW},
	3,
//else
	10
))

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 19, 2021, 9:51pm UTC](https://forum.inductiveautomation.com/t/group-opc-tag-in-the-same-condition/45698/6 "2021-04-19T21:51:05Z")

</div>

Looking at it again, the logic is flawed and could be simplified. I assume the condition with the fault tags being True has higher precedence than when they’re off? Currently if any of them are off, that condition will win. I think it should be the other way around. You should also try to group conditions together if they have a common element such as the running tag condition. Try this instead:

```auto
If({[.]On_Off_FBW}, 
    If(
         {[.]Falla safety fance open 1} || 
         {[.]AreaSafety Fence Open2} || 
         {[.]Emergency Stop} ||
         {[.]PLC Errror}
       , 3
       , 1
    )
   // else
   , 10
)

```
