Conditions entry example

Purpose: to synchronize a real object and its digital copy without losing data.

There is a digital copy of a real object in the monitoring system. The real object can be in one of two states: on or off. Few authorized operators can change the object state. The information about not only the new object state, but also the operator who has done the switch, is recorded in the digital copy.

It is a possible situation when connection with the real object was lost, meanwhile its state was changed. However, the information about the operator, who has done the switch, is not transmitted with the synchronization.

How to:

Step 1: Configure the MQTT-sensor probe in the section Monitoring

The check returns the following metrics:

  • state | whether the object turned on (1) or turned off (0),

  • id | the last operator, who interacted with the object.

The metric msg is a text message, created with data forming rules.

Step 2: Configure object state changes by an operator

If the object obtains information with id, not equal to 0, then all of the parameters will be replaced with the received data. There will be the message, that the state has been changed by the authorized operator.

[
  {
    "conditions": [
      {
        "_field": {
          "name": "new.message.id",
          "value": {
            "_neq": "0"
          }
        }
      }
    ],
    "actions": [
      {
        "type": "set",
        "field": "message.state",
        "value": "{{new.message.state}}"
      },
      {
        "type": "set",
        "field": "message.id",
        "value": "{{new.message.id}}"
      },
      {
        "type": "set",
        "field": "message.msg",
        "value": "The object state has been changed by the operator"
      }
    ]
  },
...
]

Step 3: Configure object turning on after lost and restoring connection

If the object obtains information with id, equal to 0, it is necessary to check the state of the digital copy. If it is different from the state in the data, all of the parameters will be replaced with the received data. There will be the message, that the state has been changed by an unknown operator. This check is executed in two blocks, because it is not possible to compare the current value with the new one in conditions.

To execute the first block of actions the object state must be equal to 0, and the received value must be equal to 1:

[
...
  {
    "conditions": [
      {
            "_field": {
              "name": "new.message.id",
              "value": {
                "_eq": "0"
              }
            }
          },
          {
            "_field": {
              "name": "new.message.state",
              "value": {
                "_eq": "1"
              }
            }
          },
          {
            "_field": {
              "name": "current.message.state",
              "value": {
                "_eq": "0"
              }
            }
          }
    ],
    "actions": [
      {
        "type": "set",
        "field": "message.state",
        "value": "{{new.message.state}}"
      },
      {
        "type": "set",
        "field": "message.id",
        "value": "{{new.message.id}}"
      },
      {
        "type": "set",
        "field": "message.msg",
        "value": "The object has been turned on"
      }
    ]
  },
...
]

Step 4: Configure object turning off after lost and restoring connection

To execute the second block of actions the object state must be equal to 1, and the received value must be equal to 0:

[
...
  {
    "conditions": [
      {
        "_field": {
          "name": "new.message.id",
          "value": {
            "_eq": "0"
          }
        }
      },
      {
        "_field": {
          "name": "new.message.state",
          "value": {
            "_eq": "0"
          }
        }
      },
      {
        "_field": {
          "name": "current.message.state",
          "value": {
            "_eq": "1"
          }
        }
      }
    ],
    "actions": [
      {
        "type": "set",
        "field": "message.state",
        "value": "{{new.message.state}}"
      },
      {
        "type": "set",
        "field": "message.id",
        "value": "{{new.message.id}}"
      },
      {
        "type": "set",
        "field": "message.msg",
        "value": "The object has been turned off"
      }
    ]
  }
]