|  Developer
Updated on June 24, 2022

compareValues

  • The comparison method allows comparing values of the same item value type using chosen comparator. For any value types, it supports at least two comparators: and . For those value types, that support ordering and have operation defined, the also supports comparators: , , , .
  • This event arises when the of an item corresponds to a condition set in this block for the first time. In the case, when the change doesn’t lead to comparison result change, the event won’t be raised.
  • An type can be used instead of a constant item value. Type of value in an expression should match to the value type of block.
  • The method fixes the value type of values it can compare. In case, when the data source (item, expression) value type has changed and stops correspond to the value set in the block, the event will stop working.
Edit
Field Type Required Description
blockOptions.method.args.item
blockOptions.method.args.expression
string + Argument declaration of value source name. The value should be in the block with name or expression.
blockOptions.method.args.value string + Argument declaration of a value to compare with. Could be a constant value or an expression reference. The value should be in the block with name.
blockOptions.method.args.valueType string + Argument declaration of a value type to restrict arguments value types with. The value should be in the block with name . Both sides of a comparison should be of that type.
blockOptions.method.args.comparator string Argument declaration of comparator state. The value, if any, should be in the block with name . Optional. Default value: . Possible comparators for any value type: , . Possible comparators for linearly ordered value types (value types with operation defined: , , , , , .
  • Note: If a constant part of a when block doesn’t correspond to the value of a property, the scene creation will end with an error . If an item or expression value type won’t match the property, the comparison will fail in run time.

This feature is available since advanced_scenes/1.26.

Edit
				
					"when" : [
    {
        "blockType":"when",
        "blockOptions":{
            "method":{
                "name":"compareValues",
                "args":{
                    "item":"item",
                    "valueType":"valueType",
                    "comparator":"comparator",
                    "value":"value"
                }
            }
        },
        "fields":[
            {
                "name":"item",
                "type":"item",
                "value":"5de64f6a70c7be0541cc0853"
            },
            {
                "name": "valueType",
                "type": "string",
                "value": "bool"
            },

            {
                "name":"comparator",
                "type":"string",
                "value": "!="
            },
            {
                "name":"value",
                "type":"string",
                "value": true
            }
        ]
    }
]				
			

In a case of expression, the field should reference the existing expression by name:

				
					{
    "name":"value",
    "type":"expression",
    "value":"<expressionName>"
}