Device Notification with Microsoft Flow

For a couple of IoT projects I’ve been working on, I wanted to allow scripts to trigger a notification on my phone. I evaluated a number of solutions, but many of them were paid services that only served that particular purpose. Additionally, many of them did not include the ability to customise the notifications.

A solution presented itself when I began to look at creating workflows with Microsoft Flow, which is included in an Office 365 for business subscription. Microsoft Flow basically allows for a trigger event to cause a number of actions. In this case there was a trigger that could be activated when a web request was made to a specific URL and one of the actions was to trigger a notification on a phone. Additionally, by including a JSON POST in the request, it was possible to modify the content of the notification. As a point of interest you could also send an email with almost the same setup if it would better suit the application.

Procedure

  1. Login to your Office 365 portal (portal.office.com)
  2. Click on the Flow link
  3. Click the button for “Create from blank”
  4. Search for the “When a HTTP request is received” trigger and add it to the flow
  5. Create the JSON Schema
    1. This is probably the most complicated part of the whole procedure as you need to define the JSON structure that will be used to provide parameters for your notification
    2. For my notification system, I only wanted to provide two parameters:
      1. A source field for the device or application sending me a message
      2. A message field for the contents of the actual message
    3. The JSON structure for these two fields looked likes the following:
      {
      
      "type": "object",
      
      "properties": {
      
      "Source": {
      
      "type": "string"
      
      },
      
      "Message": {
      
      "type": "string"
      
      }
      
      }
      
      }
    4. Note: You could create a far more advanced structure if you wanted more information in your notifications
  6. Now the trigger is fully configured you will need to add an action
    1. In this case, we will add the “send me a mobile notification” action
    2. It’s important to note that this requires you have the Microsoft Flow app installed on your mobile phone.
  7. Next we need to configure the notification action
    1. The only field we need to populate is the Text field which will be displayed as the body of the notification
    2. We could add an arbitrary text string into the field if we only ever want one message to be displayed, however we can reference the variables we created earlier in the JSON Schema to make the message more meaningful.
    3. For example with regard to my JSON schema, I created the message “Source has said Message”
      1. You will notice that the variables outlined in the JSON schema will appear as different symbols in the text, confirming that flow has recognised them as the variables above.
      2. It should look something like the following:Capture
      3. When the notification is generated the source and message placeholders will be replaced by the information you provide in the web request.
  8. Finally save the workflow
    1. This will generate a unique URL that you will make a web request to and will then trigger the notification.
    2. The whole flow should look something like this one:Capture

You will now have a working notification system. Simply install the flow app on your phone, sign into it using the same Microsoft account and make a request to the specified URL. A future blog post will go into detail about how to make a web request and provide the necessary JSON parameters using a number of scripting languages.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s