Rule involving capability attributes that are 'maps'

Looking at the create rule api, it is possible to create an ‘equals’ condition that compares attributes that are maps.

I managed to create the rule (took me a few gos) but the comparison does not seem to recognise equality

Should this be working?

Hi, @Davec!
Can you provide a sample of this Rule, please?

Ok…will take me a day or two as I hacked a solution that flattened the map.

I will sort it out and post. thanks for your attention

ok, thank you, this would be helpful to replicate the issue, you can also share the capability you used and the content on the “equals” section, not the complete rule.

Sorry it took me soooo long…I wanted to recreate the problem and try and provide enough info.

If you need more info, please let me know

So first, if we look at the events emitted and the rules for the scenario that works. ie I flatten my attribute into a string and compare that with rules
The rule is

{
	"name": "TestA Rule 3 string on rule 1 on",
	"actions": [
		{
			"if": {
				"equals": {
					"left": {
						"device": {
							"devices": [
								"81b6f7f7-7af8-400d-973d-124d7363a9e1"
							],
							"component": "main",
							"capability": "instantreason60524.mqttrelayv0",
							"attribute": "relayString"
						}
					},
					"right": {
						"string": "3b50f5ae-c7c4-4305-bfbf-42e412d48c27$main$switch$on$Rules result 2$none"
					}
				},
				"then": [
					{
						"command": {
							"devices": [
								"d247e498-412d-439e-b36a-e1bef0f83363"
							],
							"commands": [
								{
									"component": "main",
									"capability": "switch",
									"command": "on"
								}
							]
						}
					}
				]
			}
		},
		{
			"if": {
				"equals": {
					"left": {
						"device": {
							"devices": [
								"81b6f7f7-7af8-400d-973d-124d7363a9e1"
							],
							"component": "main",
							"capability": "instantreason60524.mqttrelayv0",
							"attribute": "relayString"
						}
					},
					"right": {
						"string": "3b50f5ae-c7c4-4305-bfbf-42e412d48c27$main$switch$off$Rules result 2$none"
					}
				},
				"then": [
					{
						"command": {
							"devices": [
								"d247e498-412d-439e-b36a-e1bef0f83363"
							],
							"commands": [
								{
									"component": "main",
									"capability": "switch",
									"command": "off"
								}
							]
						}
					}
				]
			}
		}
	]
}

The event emitted that triggered the rule is

<Device: 81b6f7f7-7af8-400d-973d-124d7363a9e1 (MQTT_relay)> emitting event: 
{
	"attribute_id": "relayString",
	"capability_id": "instantreason60524.mqttrelayv0",
	"component_id": "main",
	"state": {
		"value": "3b50f5ae-c7c4-4305-bfbf-42e412d48c27$main$switch$on$Rules result 2$none"
	}
}


Now the rule that does not work is

{
	"name": "TestA Rule 4 Map on rule 1 on",
	"actions": [
		{
			"if": {
				"equals": {
					"left": {
						"device": {
							"devices": [
								"81b6f7f7-7af8-400d-973d-124d7363a9e1"
							],
							"component": "main",
							"capability": "instantreason60524.mqttrelayv0",
							"attribute": "relayDetails"
						}
					},
					"right": {
						"map": {
							"targetCapability": {
								"string": "switch"
							},
							"targetCommand": {
								"string": "on"
							},
							"targetComponent": {
								"string": "main"
							},
							"targetDeviceID": {
								"string": "3b50f5ae-c7c4-4305-bfbf-42e412d48c27"
							},
							"targetDeviceName": {
								"string": "Rules result 2"
							}
						}
					}
				},
				"then": [
					{
						"command": {
							"devices": [
								"d247e498-412d-439e-b36a-e1bef0f83363"
							],
							"commands": [
								{
									"component": "main",
									"capability": "switch",
									"command": "on"
								}
							]
						}
					}
				]
			}
		}
	]
}

And the event that I was hoping would trigger the rule is

<Device: 81b6f7f7-7af8-400d-973d-124d7363a9e1 (MQTT_relay)> emitting event: 

{
	"attribute_id": "relayDetails",
	"capability_id": "instantreason60524.mqttrelayv0",
	"component_id": "main",
	"state": {
		"value": {
			"targetCapability": "switch",
			"targetCommand": "on",
			"targetComponent": "main",
			"targetDeviceID": "3b50f5ae-c7c4-4305-bfbf-42e412d48c27",
			"targetDeviceName": "Rules result 2"
		}
	}
}

No problem, I now understand better the use case. Thanks!
I’m already checking with the engineering team about what we can do in this case.

@Davec, following up on this issue, the team mentioned your format is correct so, there’s a bug when the comparison is made. They already created a report to investigate it.
I’ll keep you updated.

Thanks for bringing this up!

Thank you!