Exercise - Creating an IoT alert

Completed

Exercise 1: Register a device

Note

As of the writing of these exercises Microsoft Flow has been renamed Power Automate. Power Automate is the name of the collection of automations that include flow. Expect some of the screen images here to transition to the new naming over time. Functionality should still be as expected.

Task 1: Create a flow

In this task, you will create a flow that will register a device.

  1. Navigate to Power Apps and make sure you are in the correct environment.

  2. Select Apps and click to open the Connected Field Service application.

  3. Select Customer Assets.

  4. Click Flow and select Create a flow.

  5. Click Sign in.

  6. Provide your credentials if required.

  7. Select My Flows, click New, and select + Instant - from blank.

  8. Click Skip.

  9. Search for When a Record is Selected and select When a Record is Selected (Microsoft Dataverse).

  10. Select Default for Environment, Customer Assets for Entity Name, and click + New Step.

  11. Search for Create a Device and select Create a Device Azure IoT Central action.

  12. Click Sign in.

  13. Sign in with the credentials that you used to create the Azure IoT Central application and Accept the required permission.

  14. Select smart-trashcan (Name of the IoT Central Application created by you) for Application, select the template you created, click the Device Name enter Azure IoT and select Name from the Dynamic Content window.

    Screenshot of Create a device window with Device Name highlighted.

  15. Select Yes for Device Simulated.

  16. Click + New Step.

  17. Search for Create a New Record and select Create a New Record (Dataverse).

  18. Select Current for Environment, select IoT Devices for Entity Name, click on the Name field, and select Device Name from the Create a Device action in the Dynamic Content pane.

  19. Click on the ... Menu button and select Rename.

  20. Rename the step Create Device and click Show Advanced Options.

  21. Click on the Device ID field, type Azure IoT and select Device ID from the Create a Device action in the Dynamic Content pane.

  22. Set Registration Status Value to Registered, set Simulation Value to Yes, and set Status Reason Value to Active.

    Screenshot of Registration Status Value, Simulated Value, and Status Reason Value details.

  23. Click on the Account field, select Account from the When a record is created action in the Dynamic Content pane, and click Hide Advanced Options.

  24. Click + New Step.

  25. Search for List Records and select List Records (Dataverse).

  26. Select Current for Environment, select Connection Roles for Entity Name, and click Show Advanced Options.

  27. Enter name eq 'Connected IoT Device' for Filter Query and click Hide Advanced Options.

    Screenshot of the Filter Query set as name eq 'Connected IoT Device'.

  28. Click + New Step.

  29. Search for Create a new record and select Create a New Record (Dataverse).

  30. Select Current for Environment and select Connections for Entity Name.

  31. Rename the step Create Connection and click Show Advanced Options.

  32. Click on the Connected From field and select Customer Asset from the When a record is selected action in the Dynamic Content pane.

  33. Select msdyn_customerassets for Connected From Type.

    Screenshot of Connected From set to Customer Asset and Connected From Type set to msdyn_customerassets.

  34. Click on the Connected To field and select IoT Device from the Create Device action in the Dynamic Content pane.

  35. Select msdyn_iotdevices for Connected To Type.

    Screenshot of Connected To set as IoT Device and Connected To Type set as msdyn_iotdevices.

  36. Click on the Role To field and select Connection Role from the List Records action in the Dynamic Content pane.

  37. Your step will get wrapped in Apply to Each. Click Add an Action.

  38. Search for Update a Record and select Update a Record (Dataverse).

  39. Select Current for Environment, select Customer Assets for Entity Name, click on the Record Identifier field and select Customer Asset from the When a record is selected action in the Dynamic Content pane.

  40. Click Show Advanced Options.

  41. Click on the Account field and select Account from the When a record is selected action in the Dynamic Content pane.

    Screenshot of Account set to Account and When a record is selected set to Account.

  42. Click Hide Advanced Options.

  43. Rename the step Update Customer Asset.

  44. Scroll up and rename the flow Register Device.

    Screenshot of flow renamed to Register Device.

  45. Save the flow.

Task 2: Test registering device

  1. Go back to your Connected Field Service application and navigate to Customer Assets.

  2. Click New.

  3. Enter Test Device for Name and click Save.

  4. Click Flow and select the flow you created.

  5. Click Continue.

  6. Click Sign in if prompted and Continue.

  7. Sign in with your Azure credentials.

  8. Click Run Flow.

  9. Click Done.

  10. Refresh the page.

  11. The flow should populate the Connect Device Attributes.

    Screenshot of the flow with the Connect Device Attributes.

Exercise 2: Create IoT alerts

In this exercise, you will create IoT alert for the trash container pickup request.

Prerequisite: Make sure that you have CDS provisioned in the Default Environment.

Task 1: Create pickup request alert

  1. Go to your Azure IoT Central and open the left navigation.

  2. Select Devices.

  3. Open the device created by the flow.

  4. Select the Rules tab, you can't directly add new rule to a device. Click Device Templates.

  5. Open the Device Template you created.

  6. Select the Rules tab, click + New, and select Event.

  7. Enter Pickup Requested for Name and click + to Add Condition.

  8. Select Ready for Pickup for Measurement and click Save.

  9. Click + to add an Action.

  10. Select Microsoft Flow.

  11. Click New and select Automated - from blank.

  12. Enter Create Alerts for Name, search for IoT Central, select When a rule is fired, and click Create.

    Screenshot of the Build an automated flow details.

  13. Click Sign in.

  14. Provide your credentials.

  15. Select smart-trashcan (Name of the IoT Central Application created by you) for Application, Pickup Requested for Rule and click New Step.

  16. Search for Microsoft Dataverse and select List records.

  17. Select the correct environment, select Customer Assets for Entity Name, and click Show Advanced Options.

  18. Type msdyn_deviceid eq 'Azure IoT ' and place your curser inside after the IoT.

  19. Select Device ID.

  20. Click + New Step.

  21. Select Apply to Each.

  22. Select Value.

  23. Click Add an Action.

  24. Search for Microsoft Dataverse and select Create a New Record.

  25. Select the correct environment, select IoT Alerts for Entity Name, and click on the Description field.

  26. Select Device Name from the "When a rule is fired" action in the Dynamic Content and type - to the end of it.

  27. Select Rule Name from the "When a rule is fired" action in the Dynamic Content and click Show Advanced Options.

  28. Select the Alert Data field and click the Expression tab.

  29. Type utcNow() and click OK.

  30. Select the Alert Time field and select Timestamp.

  31. Locate the Device ID field and select Device ID from the When a rule is fired action in the Dynamic Content pane.

  32. Locate the Customer Asset field and select Customer Asset.

  33. Click Hide Advanced Options.

  34. Click Save.

  35. Click Done.

Task 2: Test alerts

  1. Select Devices and open the Test Device created by the Flow.

  2. Select the Rules tab and select the Pickup Requested rule.

  3. The simulator should generate new Pickup Request every few minutes.

    Screenshot of the simulator generated new pickup request.

  4. Go to your Connected Field Service application.

  5. Select IoT Alerts.

  6. You should see the alerts generated by the simulator. The alert Description will be a concatenation of Device Name and Rule Name.

    Screenshot of the alerts generated by the simulator.