I recently switched to a more convenient and consistent method for sending notifications but it would benefit from a code review and any other feature ideas before sharing it in Examples. I’m looking for feedback on both the concept and implementation. Is this useful for you, is there anything else you would like to see, and is the documentation below easy enough to follow?
Overview
Execute the Smart Notify piston with a single argument, message
, to send SMS, push, email, or any other kind of notifications to multiple recipients. Configure the recipients in Smart notify and use that contact info to send the messages in Smart notification sender.
Features
Recipients
After installing the piston, configure it with any number of named recipients. You will message them with standard @Someone notation.
@Hank Bag was left at home
Hank will receive a message with the text “Bag was left at home”
@Divya @Hank Smoke detected in the guest cottage
Both Divya and Hank will receive a message with the text “Smoke detected in the guest cottage”
Urgency
The channel(s) over which a notification is sent is determined by the urgency of the message. For example, while a push notification is fine for a non-essential notification you may want to get an SMS and phone call for critical messages. This is handled with a simple bracket notation:
[low] Open the windows
The washing machine is finished
[critical] Barn may be on fire
The urgencies and notification channels will vary for everyone, so I included a separate piston that is in charge of sending the notifications based on the urgency level and recipient data. It serves as an example but will need to be modified to fit how you want to use notifications. I use the following, though you can use any terminology for the levels and any means of notification for each level:
- low – send an email
- normal – send a push notification to the specified contact
- high – send an SMS to the specified phone
- critical – use IFTTT to call my phone (only one phone number per account), send an SMS by Verizon’s @vtext.com email (different ringtone), send an email
I have SmartThings saved as a contact in my phone so that I can use specific ringtones for SMS sent from SmartThings and sent from the webcore.co email to reinforce the urgency… the SMS for a critical notification is definitely going to get my attention if I somehow miss the also very alarming ringtone for calls from IFTTT.
I’m not keen on naming this “urgency” or “level” – that’s a perfectly valid use case for it but you could set up any number of channels in Smart notification sender and name them any way you want. Any ideas?
Presence logic
Some messages only need to be sent if the recipient is currently present. In some cases messages should be queued until you get back home, delivered only once you’re home and able to act on them.
@Divya:when-present Empty the dishwasher
This message will be sent to Divya either immediately if she is already home, otherwise as soon as she arrives.
@Hank:when-away Check for missing equipment
This message will be sent to Hank either immediately if he is already away, otherwise as soon as he leaves.
@Hank:if-away @Divya:if-away Open the windows at the office
Both will receive the notification if they are away. If both are home, the message is ignored.
A notification can have any number of recipients and any number of notifications can be queued up until the required presence change.
@Divya:if-present @Hank:if-present @Divya @first The door is open!
The use of @first
here will pare the list down to only the first valid recipient. For example, without @first
if both Hank and Divya are home the valid recipients list will be “Divya, Hank, Divya”, if Divya is away the recipients list will be “Hank, Divya”, and if both are away the recipients list will be “Divya” – the @first
command delivers the message only to the first valid recipient so in these examples Divya, Hank, and Divya respectively.
Is the distinction between the words “when” and “if” clear enough to convey the difference in behavior? If not, maybe something more verbose but clearer like @Divya:wait-until-present
?
Repeat until cancelled
I really need to be pestered to remember to switch over a load of laundry; one alert is not enough. The Smart Notify piston allows you to repeat a notification at a predetermined interval. There is one interval running to handle all repeating messages, 5 minutes is a good default for me but you can configure that at the top of the Smart notify piston. Unfortunately the frequency is not configurable on a per-message basis.
Repeating messages require a keyword so that you can cancel the message at a later time. For example, Hank will receive the message “The dishwasher is finished” every 5 minutes if he’s home. If he is away, the message will still be attempted every 5 minutes but the presence logic will cause it to not be sent until he gets back.
@repeat:dishwasher @Hank:if-present The dishwasher is finished
Just be sure to set up a piston to cancel the repeating message. I use a contact sensor on the dishwasher to cancel repeating messages when the door is opened, and power meters on the washer and dryer. Simply send a @cancel message to the Smart notify piston:
@cancel:dishwasher
If you don’t have a way to automatically detect that an action has been completed you could instead use a virtual or physical button that cancels any active repeating messages with:
@cancel:all
Repeating messages can use any features of Smart notify (e.g. multiple recipients and presence logic) with the exception of :when-away
and :when-present
for which you should use :if-away
and :if-present
instead.
Configuration
The Smart notify piston has a few variables to configure as well as a section for recording the contact info for each recipient. After installing the piston you will be asked for two presence devices, these are for the two sample contacts which can be added to or removed later. If each person has multiple presence devices, combine their presence value with Maximum.
Look at the comments for cues on how to format the values and where to stop editing. There are also three Execute Piston calls in the bottom half of the code that need to be updated to point to your Smart notify and Smart notification sender pistons.
The Send smart notification piston may require much more creative configuration based on the number of urgency levels you want and the channels through which you want to receive notifications. The example uses IFTTT to place a phone call for urgent messages but note that IFTTT integrations like voice call and SMS do not work with multiple recipients since you can only verify one number per IFTTT account. I also use an SMS notification via email to Verizon’s @vtext.com service in order to have two different ringtones for SMS to reinforce the urgency.
Feel free to build one from scratch if my Send smart notification is not what you want; I think this initial example is too opinionated and complex to distribute but let me know what you think. The messages, subjects, etc. use sprintf formatting for some flexibility, be sure to look for the list of “placeholders” in the comment instructions.
Usage
To send a notification from one of your pistons, create a string variable called message
. Assign to that variable the contents of your message then pass the variable as an argument to the Smart notify piston using the Execute piston action. No other arguments are needed since all of the functionality described above is controlled by the message.
Installation
- Add a new piston
- Restore a piston using a backup code
- Name the first piston Smart notify and use the backup code
wumg8
- Edit the contact information and Execute piston calls as described in Configuration above
- Add a new piston
- Restore a piston using a backup code
- Name this piston Smart notification sender and use the backup code
b2hx
- Edit the piston or make a copy to notify in ways that make sense to you
Disclaimer Please do not switch all your live notifications to this… it needs more thorough testing and the implementation details may change before it is posted to Examples. Do install it and set up a simple piston to test sending messages with it.
If you decide to switch any live notifications over to Smart notify I highly recommend setting up a third piston that just receives a message
argument and forwards it to Smart notify. Reference that abstraction in your pistons rather than directly executing Smart notify so that if you replace Smart notify with a later version you only need to update the single Execute piston
call in your abstraction.
&