|  Developer
Updated on December 2, 2022

compareNumbers

  • When the data source is an or , this event arises when the of an item or expression corresponds to a condition set in this block. For example, if the is , value is equal to and item value is , then an event arises. If the condition is , then the event arises only once after the threshold was exceeded (see Stateful comparison). For example, if the item value is and after that item value becomes , then an event arises. When item value becomes the event doesn’t arise. The event will arise again when the threshold is exceeded again. Similar situation is for other comparators ( , , ).
  • 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.
  • An or type can be used instead of a constant item value.
Edit
Field Type Required Description
blockOptions.method.args.item string Value source for the left part of the comparison operator. References the item by its ID. The name of the source should have a corresponding block with a matching source name.
blockOptions.method.args.expression string Value source for the left part of the comparison operator. References an expression by its .
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 item value. The value should be in block with name .
blockOptions.method.args.comparator string + Argument declaration of comparator state. The value should be in block with name . Possible comparators are , , , , , .

One of , , or a pair of / is required.

The block should have a value source declaration: , or /.

The / define a single data value source for a comparison method.

Edit
Edit
Example 1: compare value of an item with numeric type:
				
					{
        "blockType":"when",
        "blockOptions":{
            "method":{
                "name":"compareNumbers",
                "args":{
                    "item":"item",
                    "comparator":"comparator",
                    "value":"value"
                }
            }
        },
        "fields":[
            {
                "name":"item",
                "type":"item",
                "value":"5de64f6a70c7be0541cc0853"
            },
            {
                "name":"comparator",
                "type":"string",
                "value": ">"
            },
            {
                "name":"value",
                "type":"int",
                "value": 51
            }
        ]
    }				
			
Edit
Example 2: compare item with expression:

Use an expression value to compare with an item updated value. The event will raise in a situation when an item value meet the expression value: – the item value is changed; – the expression value is changed.

				
					{
        "blockType": "when",
        "blockOptions":{
            "method": {
                "name": "compareNumbers",
                "args": {
                    "item": "item",
                    "comparator": "comparator",
                    "value": "value"
                }
            }
        },
        "fields": [
            {
                "name": "item",
                "type": "item",
                "value": "5de64f6a70c7be0541cc0853"
            },
            {
                "name": "comparator",
                "type": "string",
                "value": ">"
            },
            {
                "name": "value",
                "type": "expression",
                "value": "expressionName"
            }
        ]
    }				
			
See Scenes expression related commands for detail on creating expressions.
Edit

Example 3: compare expression with expression

Compare value of an expression with name “expressionLeft” with a value of an expression with name “expressionRight”. The event will raise when value of “expressionLeft” becoming greater than value of “expressionRight”. Event checked whenever values of “expressionLeft” or “expressionRight” are changed.

				
					"when" : [
    {
        "blockType": "when",
        "blockOptions":{
            "method": {
                "name": "compareNumbers",
                "args": {
                    "expression": "expression",
                    "comparator": "comparator",
                    "value": "value"
                }
            }
        },
        "fields": [
            {
                "name": "expression",
                "type": "expression",
                "value": "expressionLeft"
            },
            {
                "name": "comparator",
                "type": "string",
                "value": ">"
            },
            {
                "name": "value",
                "type": "expression",
                "value": "expressionRight"
            }
        ]
    }
]				
			
Edit

Example 4: compare value of any item that matches the device/item group with numeric type:

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 stateless. It doesn’t have information about previous value of any item in the group.

Comparison type: stateless

				
					{
    "blockType":"when",
    "blockOptions":{
        "method":{
            "name":"compareNumbers",
            "args":{
                "deviceGroup":"deviceGroup",
                "itemGroup":"itemGroup",
                "comparator":"comparator",
                "value":"value"
            }
        }
    },
    "fields":[
        {
            "name":"deviceGroup",
            "type":"device_group",
            "value":"5de64f6a70c7be0541cc0853"
        },
        {
            "name":"itemGroup",
            "type":"item_group",
            "value":"5de64f6a70c7be0541cc0854"
        },
        {
            "name":"comparator",
            "type":"string",
            "value": ">"
        },
        {
            "name":"value",
            "type":"int",
            "value": 51
        }
    ]
}				
			

Available since: Group operations filtering is available since