Solution #2: Thresholds and notifications
Estimated time: 10–15 minutes
You will want to complete the prior sections of this workshop before starting with this one.
Through the combination of historical soil moisture data and observation of your plant, you can begin to determine the point at which your plant will begin to die. Your goal then becomes keeping the soil moisture above that threshold to ensure your plant's health.
In this workshop, you will use this concept of thresholds (or state changes) to explore how nio can use "edge intelligence" (applying logic to data before it reaches a database) to help keep your plant alive.
Talk to me, Seymour
Perhaps your plant starts to wilt when the soil moisture approaches 50%. Between 100% and 51%, however, your plant thrives. Obviously, you should strive to maintain soil moisture greater than 50%. But with rain, temperature, and other changing environmental variables, the time it takes your plant to reach 50% is dynamic.
Instead of relying on the timeline your data model predicts (or, even worse, you just sitting there watching the UI), let nio notify you when your plant's soil moisture reaches 50%.
Within the Threshold_Notification service, you will notice the same PlantStatus Subscriber block already configured to subscribe to the topic
plant.soilmoisture. This is because you can resuse the same block configuration for all solutions within this workshop. If it has the same block name, it always has the same block configuration.
Test that this service notifies you when a threshold is reached:
- Start the Threshold_Notification service.
- Using the UI, water your plant above 50% and let it fall back below 50%.
Open the logger panel by clicking the open logger panel button in the toolbar. You should see a notification letting you know that your soil moisture level has fallen below 50%.
This Threshold_Notification service is subscribing to data from the Plant_Simulator service. The service sends the data through a series of blocks that filter the data at the edge and it only logs a signal when the state of the system changes (i.e., when the soil moisture falls below 50%). This signal, or event, can then be used to trigger another action.
To be notified before the soil moisture percentage reaches 50%, simply replace
50with a higher number in the StateChange block configuration.
If you change the threshold, you must stop and restart the service for the changes to take effect.
With the logic established for notifications, the Logger block can easily be replaced with any other messaging block. Instead of sending the signal to a Logger, you can send yourself a text, email, or Slack message. Just replace the Logger block with whatever notification type you prefer. The TwilioSMS block is a great choice if you want to receive a text message.
Give it a try:
- Create a free Twilio account.
- Drag the TwilioSMS block onto the canvas from the nio System Designer block library.
- Enter your new Twilio credentials into the block config.
- Click accept to save the block config.
- Stop and restart your service.
Find your Twilio SID by clicking "home: phone numbers" from within your Twilio profile.
Now, instead of watching a screen and clicking a button whenever the soil moisture reaches a critical level or relying on an imprecise data model, you are getting notified only when it is necessary for you to take action.
Ugh, though, more notifications? Can't nio take care of all of the watering?
Next, learn how to configure nio to automatically keep your plant alive.