|  Developer
Updated on December 2, 2022

compareValues

  • The comparison method allows comparing values of the same 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/expression 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 or type can be used instead of a constant item value. Type of value in an expression/item 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.
  • When the data source is a device/item group, the event is stateless. It arises every time the condition is true, no matter which value of an event was previously. See Stateless comparison.
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.deviceGroup string Value source for the left part of the comparison operator. References a device group by its ID. The parameter is required.
blockOptions.method.args.itemGroup string Value source for the left part of the comparison operator. References an item group by its ID. The parameter is required.
blockOptions.method.args.value string + Argument declaration of a value to compare with. Could be a constant value or an expression reference or an item id. 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
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>"
}				
			
Edit

Define a device group, define an item group, make a condition block to make a comparison of an hub.item.updated broadcast with the condition value.

The comparison is stateles s. It doesn’t have information about previous value of any item in the group.

Comparison type: stateless

				
					{
    "blockType":"when",
    "blockOptions":{
        "method":{
            "name":"compareValues",
            "args":{
                "deviceGroup":"deviceGroup",
                "itemGroup":"itemGroup",
                "comparator":"comparator",
                "valueType":"valueType",
                "value":"value"
            }
        }
    },
    "fields":[
        {
            "name":"deviceGroup",
            "type":"device_group",
            "value":"5de64f6a70c7be0541cc0853"
        },
        {
            "name":"itemGroup",
            "type":"item_group",
            "value":"5de64f6a70c7be0541cc0854"
        },
        {
            "name":"comparator",
            "type":"string",
            "value": ">"
        },
        {
            "name": "valueType",
            "type": "string",
            "value": "int"
        },
        {
            "name":"value",
            "type":"int",
            "value": 51
        }
    ]
}				
			
Available since: Group operations filtering is available since