Skip to Content
Technical Articles

How to integrate SAP Leonardo IoT Actions with SAP Leonardo IoT User-defined Event Types and Events

With recent enhancements to SAP Leonardo IoT actions, now it is possible to invoke actions via SAP Leonardo IoT events based on user-defined event types along with their attributes.

This enhancement creates another trigger point to SAP Leonardo IoT actions in addition to already existing SAP Leonardo IoT rules framework.

In this blog, I would like to share how to integrate SAP Leonardo IoT actions with SAP Leonardo IoT user-defined event types and events.

Scenario:

Consider following scenario where external rule source exists (e.g. a custom-built device diagnosis application) to check for certain error codes from IoT enabled machines. Based on those error codes we want to define an Action in SAP Leonardo IoT that creates a service ticket in SAP S/4 HANA.

In this case we can utilize SAP Leonardo IoT’s User-defined Event Types and its Events (see User-defined Events based on OData Event Type) to run SAP Leonardo IoT Actions

 

User-defined Event Type and Events:

User-defined event types, Events property set types and create events for those through following APIs:

User-defined Event Type: Create Event Type

Event Property Set Type: Create Event Property Set Type

Events based on user-defined event type: Create Events

 

Event Type Sample Payload

Following is a sample payload to represent error code use case scenario where section “Codes” represents various error codes that an IoT enabled machine may send out via user-defined events in case of any issues.

{
      "Name": "iotae.custom.events:error_codes",
      "Descriptions": [
        {
          "LanguageCode": "en",
          "Description": "Event type for Error Codes"
        }
      ],
      "PackageName": "iotae.custom.events",
      "PropertySetId": "CoffeeTemp",
      "PropertySetType": "iotae.custom.events:machine_reading",
      "PropertySetDescriptions": [
        {
          "LanguageCode": "en",
          "Description": "Error Code Property Set"
        }
      ],
      "Statuses": [
        {
          "EventStatus": "Open",
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "Open"
            }
          ]
        },
        {
          "EventStatus": "InProcess",
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "In process"
            }
          ]
        },
        {
          "EventStatus": "Completed",
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "Completed"
            }
          ]
        }
      ],
      "Severities": [
        {
          "EventSeverity": 1,
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "High"
            }
          ]
        },
        {
          "EventSeverity": 2,
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "Medium"
            }
          ]
        },
        {
          "EventSeverity": 3,
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "Low"
            }
          ]
        }
      ],
      "Codes": [
        {
          "EventCode": "1000",
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "Error Code 1000"
            }
          ]
        },
            {
          "EventCode": "2000",
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "Error Code 2000"
            }
          ]
        },
                {
          "EventCode": "3000",
          "Descriptions": [
            {
              "LanguageCode": "en",
              "Description": "Error Code 3000"
            }
          ]
        }
      ]
    }

 

Actions

Once User-defined Event-Type has been created, SAP Leonardo IoT Action can be created in the Action Service by choosing “Custom Event” for “Triggered by” column:

 

For this scenario, a user-defined event type “error_codes” with “machine reading” as the property set was created and selected as you can see from above screen shot.

Please note that when choosing “Custom Event” as triggered by, Thing Type must be selected manually.

Also notice that for “Custom Event” two new columns are exposed “Condition Source” and “Condition Regular Expression”.

These two columns allow regular expression to be applied on standard content fields for events and things such as event.id, event.status, event.code, thing.id, thing.name etc…

E.g. By defining event.code as condition source and 1000 as expression, this sample action will only trigger when custom event with even code 1000 is raised.   This functionality gives additional flexibility to filter out events at action level.

You can find several good introductions to Regular Expressions on the Web, e.g. oreilly’s introduction to regular expressions. Also, there are pages where you can test your regular expressions. Just Google for “regular expression tester”.

For the Action message payload, all tokens are available including Properties from both ThingType Property Sets and Event Property Set Types.

For example, our sample User-defined Event Type (custom event) “error_codes” contains a Property Set Type called “machine_reading” which in turn has the following properties:

  • reading_a
  • reading_b
  • error_detail

Therefore, all three fields are available to be used as tokens:

Note: All available tokes you can find by typing “${“ + another letter (like “r” for finding reading_a).

 

Values for these properties will be captured via event payload:

In this example, action will capture values 11 for reading_a, 21 for reading_b and “Fuse B needs to be replaced for error_detail tokens.

Summary:

As you can see with introduction of the integration between SAP Leonardo IoT’s User-defined Event Types and SAP Leonardo IoT’s Actions, SAP Leonardo IoT provides an additional layer of flexibility of triggering actions.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.