Generate alerts from IoT devices

Completed

After you have registered your IoT-enabled customer assets with Azure IoT Hub, readings from the devices will be captured based on the configuration. Within IoT Hub, you can define how and when you want to trigger an alert that can be returned to Dynamics 365. For example, consider a scenario where you have an IoT-enabled thermostat. The device constantly sends temperature readings back to IoT Hub. When a temperature reading that is outside of your specified threshold is discovered, it generates an IoT alert record in Dynamics 365.

If you use the Connected Customer Service for IoT Hub deployment option, device data is available in Dynamics 365. You can capture this data in multiple ways:

  • IoT Alert - When an alert is generated, details about the alert are included as JSON with the alert.

  • Pull Device Data - Initiates a device data pull directly from the IoT device record in Microsoft Dynamics 365 Field Service.

  • Scheduled Data Pull - Similar to a direct device data pull, except that it's done on a defined schedule.

If you use the Connected Customer Service deployment option, the ability to pull device data and display inside Dynamics 365 isn't available.

Work with the Alert Data feature

After an IoT alert has been generated, you need to identify what your next action should be. The IoT Alert record contains several pieces of information, including the type of alert, time, device ID, and alert data.

The Alert Data field consists of JSON data that contains specific detail about the event. The included data can vary depending on the device. Information in the Alert Data field will generally dictate the specific next step that you should take. When starting to build automations around next steps, you need to understand what tools and information are available and how those tools allow you to achieve your goal.

Several actions are available out of the box that you can use to automate items. For example, you can create and register devices and interact with IoT alert records. When an alert is received, the specific data that is related to the alert is in the Alert Data field. The data in this field is in JSON format. The following code sample represents what would pass to the Alert Data field when an IoT alert is raised.

{"deviceid":"smt-1298","readingtype":"Temperature","reading":113,"eventtoken":"c802338d-60f2-4a79-b45c-e164e2191ce0","threshold":70,"ruleoutput":"AlarmTemp","time":"2018-09-06T15:58:08.964Z"}

Generally, you can't directly use the contents of the Alert Data field because you might be attempting to query based on one of the properties, not all of them. First, parse the relevant parameters that you want to work with so that you can use those parameters to drive query on and drive next steps.

If you parse the previous JSON string, you discover that it's communicating the following information.

Parameter Value
Deviceid Smt-1298
Readingtype Temperature
Reading 113
Eventtoken c802338d-60f2-4a79-b45c-e164e2191ce0
Threshold 70
Ruleoutput AlarmTemp
Time 09/06/2018 06:58:08 AM

Use Power Automate to parse data

Power Automate includes an action called Parse JSON. When you trigger the Parse JSON action, the JSON from the Alert Data field is parsed into individual properties. Make sure that you define the schema so that the command knows how to parse the data. You can use sample payloads from the IoT alert to generate the schema.

The following image shows that the same JSON string is being used that was included in an IoT alert to create the schema.

{"deviceid":"nest1234","readingtype":"Temperature","reading":80,"eventtoken":"cfd5e690-ee88-4ca8-a75d-3b86ac61295c","threshold":70,"ruleoutput":"AlarmTemp","time":"2019-10-19T16:42:26.457Z"}

The string created multiple properties that represent each item that is parsed in the JSON, such as deviceid, readingtype, reading, and so on.

Screenshot of the Parse JSON window showing parsed data.

After the data has been parsed, you can use it to populate other fields in the IoT alert, as you did with the workflow. Now, you can use each property as dynamic content in any future step in the flow.

Screenshot showing how to use Parse JSON in dynamic content.

If you use this approach to parse the previous JSON string, you could create a flow in Power Automate that performs the following actions:

  1. The flow initiates when a new IoT alert record is created.

  2. The Parse JSON action is run to parse the JSON into individual properties.

  3. The flow updates the IoT alert record with the output value of one of the returned properties. For example, the Reading property is used to update the Device Reading field.

  4. Another flow could be triggered on the update of the Device Reading field, which performs the following actions:

    • If the Device Reading field is between 70 and 85, it creates a command that is related to the IoT alert that sends a reset command to the device.

    • If the Device Reading field is greater than 85 degrees, the workflow completes with a status of Succeeded.

Create cases from IoT alerts

When you receive an alert from a device, your service team can manually monitor the alerts and troubleshoot the issue remotely. If the issue isn't resolved by sending a remote command, the service representative can create a case to work on the issue further. The provided business process flow guides you through the process of manually responding to IoT alerts.

The initial stage in the business process flow is on the IoT alert record, and the following stages are for the case. If you select the first stage and then select Next Stage, you can create a case. Then, the Quick Create pane appears, as shown in the following screenshot.

Create a case in an IoT alert business process flow.

After you have created the case, the Alert status on the IoT alert record will change to In Progress - Case Created and the record will be read-only. When the case is resolved, the status of the IoT alert is automatically changed to Closed.

Required security roles for Connected Customer Service

Security roles for Connected Customer Service allow administrators to give appropriate access to Internet of Things (IoT) entities, including alerts, assets, devices, and commands.

The following security roles are included with Connected Customer Service:

  • IoT - Administrator - All privileges for all records on customer assets, IoT devices, IoT alerts, and associated tables.

  • IoT - Endpoint User - A special role that is used by Microsoft to connect Dynamics 365 to IoT Hub systems.

Note

Any user who needs to work with device registration and device data pulls (IoT Hub) is required to have both IoT Administrator and IoT Endpoint User security roles.

You might need to create your own security roles to provide the privileges that are required for your users.

Important

These built-in roles are designed to supplement other roles, such as customer service representative or CSR manager; they only contain the privileges for Connected Customer Service and don't contain the privileges that users require, such as accounts, contacts, cases, and activities.