ANY or ALL

in the APP routines, one or more devices can be selected and you can choose ANY or ALL option, is this possible (i assume yes) to do in a Rule? i tried the keyword ANY, but it failed…

{
	"name": "testing (any)",
	"actions": [
		{
			"if": {
				"any": {
					"changes": {
						"equals": {
							"left": {
								"device": {
									"devices": [
										"6e2f6f3f-cbf1-44b6-88a0-bc2c387b7aab",
										"310ea468-554c-4f85-bf8a-a444d4447dc1",
										"f2c2a3d0-c1b6-4ff6-a27a-c9c634453fea"
									],
									"component": "main",
									"capability": "switch",
									"attribute": "switch"
								}
							},
							"right": {
								"string": "on"
							}
						}
					}
				},
				"then": [
					{
						"command": {
							"devices": [
								"49d12d5c-3a48-4b3e-8bba-4411d61b79e5"
							],
							"commands": [
								{
									"component": "main",
									"capability": "switch",
									"command": "switch",
									"arguments": [
										{
											"string": "on"
										}
									]
								}
							]
						}
					}
				]
			}
		}
	]
}
? Select a location. 1
    Error: Request failed with status code 422: {"requestId":"673CAA34-DC18-49DB-8F60-DAFC1869552B","error":{"code":"ConstraintViolationError","message":"The request is
    malformed.","details":[{"code":"BodyMalformedError","target":"any","message":"Unrecognized field \"any\" (class v20190122.internal.st.behaviors.IfAction), not marked as ignorable","details":[]}]}}

Use and or or and use an array of conditions below them.

1 Like

My proposal:

Delete this

and add after this

      "aggregation": "Any",

Just to clarify my answer was for combining conditions. It is the equivalent of the ALL and ANY in Routines. There is also a not for negating single conditions and they can all be nested.

@TapioX gave an answer for changing how devices are handled within a condition. So in your example adding an aggregation property at the same level as left and right would give a choice of All of the devices being on or Any of them being on. Any is the default. It is likely to be used in Member Location in Routines for combining presenceSensor devices.

1 Like

i tried the aggregation approach and found that, if i turned on switch 1, then the condition was met and light turn on.
if i left that switch on, but turned off the target light, then turned on switch 2, the target light would not turn on

{
	"name": "testing (any)",
	"actions": [
		{
			"if": {
				"changes": {
					"equals": {
						"left": {
							"device": {
								"devices": [
									"6e2f6f3f-cbf1-44b6-88a0-bc2c387b7aab",
									"310ea468-554c-4f85-bf8a-a444d4447dc1",
									"f2c2a3d0-c1b6-4ff6-a27a-c9c634453fea"
								],
								"component": "main",
								"capability": "switch",
								"attribute": "switch",
                                 "trigger":"Always"
							}
						},
						"right": {
							"string": "on"
						},
						"aggregation": "Any"
					}
				},
				"then": [
					{
						"command": {
							"devices": [
								"49d12d5c-3a48-4b3e-8bba-4411d61b79e5"
							],
							"commands": [
								{
									"component": "main",
									"capability": "switch",
									"command": "on",
									"arguments": []
								}
							]
						}
					}
				]
			}
		}
	]
}

(i removed the 1st rule before continuing) i changed to the OR pattern and found that this is working more completely

{
	"name": "testing (any2)",
	"actions": [
		{
			"if": {
				"or": [
					{
						"changes": {
							"equals": {
								"left": {
									"device": {
										"devices": [
											"6e2f6f3f-cbf1-44b6-88a0-bc2c387b7aab"
										],
										"component": "main",
										"capability": "switch",
										"attribute": "switch",
										"trigger": "Always"
									}
								},
								"right": {
									"string": "on"
								}
							}
						}
					},
					{
						"changes": {
							"equals": {
								"left": {
									"device": {
										"devices": [
											"310ea468-554c-4f85-bf8a-a444d4447dc1"
										],
										"component": "main",
										"capability": "switch",
										"attribute": "switch",
										"trigger": "Always"
									}
								},
								"right": {
									"string": "on"
								}
							}
						}
					},
					{
						"changes": {
							"equals": {
								"left": {
									"device": {
										"devices": [
											"f2c2a3d0-c1b6-4ff6-a27a-c9c634453fea"
										],
										"component": "main",
										"capability": "switch",
										"attribute": "switch",
										"trigger": "Always"
									}
								},
								"right": {
									"string": "on"
								}
							}
						}
					}
				],
				"then": [
					{
						"command": {
							"devices": [
								"49d12d5c-3a48-4b3e-8bba-4411d61b79e5"
							],
							"commands": [
								{
									"component": "main",
									"capability": "switch",
									"command": "on",
									"arguments": []
								}
							]
						}
					}
				]
			}
		}
	]
}

if switch 1 turns on, then light comes on
turn off light, leaving switch 1 on/
turn on switch 2, light comes back on
etc

1 Like

the aggregation pattern would certainly be much simplier to read and maintain, but it doesn’t appear to work as i would hope (perhaps my rule structure is not correct?)

I haven’t looked closely but you should be aware that changes is documented as only being true when the underlying condition transitions from false to true. I don’t think I even use it anywhere.

I shall qualify that as I have seen an example where changes acted on an operand that wasn’t even boolean. That has never been explained.

1 Like

@orangebucket, i read your response closer Graham, and i think i understand it now… using the aggregation of “Any” the condition is satisfied as soon as one of the devices meets the condition. as long as one of them is on, then it will never trigger again when one of the other devices in that list comes on. as you mentioned, this is great for check if at least one user is home (using a presence sensor).

thank you to both @orangebucket and @TapioX for your help. !

I think that it is the changes making you see that behaviour.

1 Like

interesting… the use of ‘changes’ was mentioned by @nayelyz in a different post i made where i had added multiple ‘IF’ in the same file and saw that the light in another room, not specified within the If\Then block was was turning on… in that case it was mentioned that down_2x would remain true for a switch until some other event happened

acting on that, i went back to the aggregation pattern but removed the ‘changes’ tag (which is what @TapioX said to do, but i only removed the ‘any’ tag,and not both that was highlighted :face_with_open_eyes_and_hand_over_mouth:) and now i get identical results to the OR case…

{
	"name": "testing (any)",
	"actions": [
		{
			"if": {
				"equals": {
					"left": {
						"device": {
							"devices": [
								"6e2f6f3f-cbf1-44b6-88a0-bc2c387b7aab",
								"310ea468-554c-4f85-bf8a-a444d4447dc1",
								"f2c2a3d0-c1b6-4ff6-a27a-c9c634453fea"
							],
							"component": "main",
							"capability": "switch",
							"attribute": "switch",
							"trigger": "Always"
						}
					},
					"right": {
						"string": "on"
					},
					"aggregation": "Any"
				},
				"then": [
					{
						"command": {
							"devices": [
								"49d12d5c-3a48-4b3e-8bba-4411d61b79e5"
							],
							"commands": [
								{
									"component": "main",
									"capability": "switch",
									"command": "on",
									"arguments": []
								}
							]
						}
					}
				]
			}
		}
	]
}