Main Content

Act on Your Data

This example shows how to send an email when your dew point data exceeds 60°F using a React app.

Prerequisite Steps

Use MATLAB Analysis App to Create Email Alert

This example shows how to send an email each time the dew point level goes over 60°F. The value in the channel is checked every 10 minutes. First create a MATLAB Analysis app which composes the email message, then a React app to monitor the dew point and send that email message when appropriate.

  1. Go to the Apps tab, and click MATLAB Analysis.

  2. Click New. Select the Custom template, and click Create.

  3. In the Name field, enter Dew Point Alert.

  4. In the MATLAB® Code field, enter the following lines of code. Be sure to enter your own alerts API key.

    % === Set up alert mail ===
    alertApiKey = "XXXXXXXXXXXXXXXXXXX";  % Replace with your Alerts API Key, available in your ThingSpeak profile page
    alertUrl = "https://api.thingspeak.com/alerts/send";
    options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key",alertApiKey]);
    mailSubject = "Dew Point Monitor";
    mailBody = " Dew point above 60F. Turn off humidifier. ";
    % === Send mail ===
    webwrite(alertUrl, "body",mailBody, "subject",mailSubject, options);
  5. To test this app, click Save and Run.

You will receive an email message at the address identified with your ThingSpeak account. It should look like the following.

Alert email message

Use React App to Monitor Channel and Send Alert

Use the following steps to create a React app that sends the alert email when specific conditions are met.

  1. Near the bottom of your MATLAB Analysis app page, click React.

  2. In the new React app settings:

    • Set the React Name to Dew Point Email.

    • Set the Condition Type to Numeric.

    • Set the Test Frequency to Every 10 minutes.

  3. Set the condition to trigger when the humidity value in your channel reaches or goes above 60:

    • If channel: select your Dew Point Measurement channel.

    • field: select 3 (Dew Point(F)).

    • For the condition type: select is greater than or equal to.

    • For the condition value: enter 60.

  4. Define the actions for this app to trigger:

    • Set Action to MATLAB Analysis.

    • Set Code to execute to Dew Point Alert:

    • In Options, choose Run action each time the condition is met.

      The settings should now look like the following.

  5. Click Save React.

The React app is now active, and checks your Dew Point Measurement channel every ten minutes. If the latest calculated dew point is 60°F or higher, the React app sends you an email.

Related Examples

More About