Audio Notifications for Sensor Readings

Estimated reading time: 2 minutes

Flows can assist you in creating dashboards that will notify you when sensor anomalies occur.

Enable Audio Notifications

To set up a Flow that notifies you upon certain temperature readings:

  1. Connect an Inject node, a Function node, and a Serial out node. Connect a Serial in node, a Function node, and an Audio out node separately from the first three nodes.

    The nodes should be connected like the below screenshot:

  2. Double-click either serial node. Click to create a configuration for the connected device. Make sure that the Baud rate and Port name match the device information. Assign this configuration to each serial node in the flow.

  3. Double-click the Inject node. Select String from the drop-down and enter a string message that will request the desired data from it. Here I am using F to request temperature data in Fahrenheit from the sensor. Set an interval to have the node automatically request data after each interval.

  4. Double-click the Audio out node. Select a voice to use. Set up a dashboard if you have not already done so. The default dashboard settings will work for this use case. Make sure to check Play audio when window not in focus to hear the alert when Flows is minimized.

  5. Double-click the upper Function node to ensure that messages to the sensor are properly formatted. In the following code, I add a carriage return to the message to ensure that the device reads it properly.

    msg.payload = msg.payload + "\r"; // Add a carriage return to the output.
    return msg;
  6. Double-click the lower Function node. Enter some lines of code that will check for the sensor reading and output a message when it is above or below a certain threshold.

    var val = parseFloat(msg.payload); // Gets the temperature in degrees Fahrenheit from the string sent by the device.
    if (val > 70.0) { // Checks for if the temperature is higher than 70 deg F
      msg.payload = "high"; // Sets the notification message to say "high" when the temperature is high.
    else {
      msg.payload = "low"; // Sets the notification message to say "low" when the temperature is lower than 70 deg F.
    return msg;
  7. Click Save. Lastly, make sure to open the dashboard with the dashboard tab at the bottom of the screen. Click to open the dashboard to begin hearing the audio notifications.