[No Longer Supported] Twilio Notifications Driver - Supports SMS and Voice Calls

Update 12-20-2023: Due to change in US regulations and mobile carrier requirements I am no longer using Twilio and can no longer provide support for this driver.

This driver was originally created in May 2018 which ultimately became a stock driver. Since then I have made several additions, so here are the differences from the stock Twilio driver:

  1. Have parent container driver that creates children notification devices so you only have to enter the Twilio API once in the parent container.
  2. In certain regions of the world (not USA), Twilio supports Alphanumeric Senders which are a little cheaper than purchasing a phone number. Added support for Alpha Sender.
  3. Support voice calls via text to voice. Added SpeechSynthesis capability to the child driver and when you invoke the speak command, the driver will instruct Twilio to call your phone number instead and speak the text.

If you haven't heard of Twilio, you have most likely been a recipient of one of their notifications. They are the communications vehicle behind many of the SMS messages you receive from financial institutions and other companies and they offer voice and push type services as well.

I have experience integrating with them at work so setting up a driver was pretty straight forward. They offer a pay as you go cost model which is very cheap. At the time of this posting it will cost you around $1 per month for your own dedicated phone number and $0.075 per SMS message. So for around $2 per month you can receive over 1300 SMS messages. They have global support too!

To utilize this driver:

  1. Sign up for a Twilio account
  2. Fund the account via credit card or PayPal - $20 minimum unfortunately
  3. Purchase a phone number (or setup Alphanumeric sender if supported in your region). They have agreements with carriers throughout the world so you can likely get a phone number in your country and area code.
  4. Capture your account's SID and Auth Token:
  5. Add the container and device drivers code to your HE hub or use HPM to install the code - search for Twilio SMS and Voice Notifications.
  6. Create a new virtual device and set the type to Twilio Container and Save Device.
  7. Enter the Twilio API Credentials into the Hubitat driver:
  8. Designate whether you are using an Alpha Sender, default no.
  9. Select your Twilio Phone Number or Alpha Sender and Save Preferences.
  10. Enter a child Device Label and phone number and click Create Device. The phone number needs to be entered in E.164 format for example in the US and Canada +18005551212. Multiple child notification devices can be setup and they will all leverage the same Twilio API Credentials, unlike the stock driver that requires you to enter them for each device.

Once this is setup, you can select this new device in Rule Machine for notifications. The messages are logged as events too!

To setup voice calls, additional setup is required within your Twilio Account. The Twilio Voice API requires a URL to query for the text to speak which complicates the setup because most people don't have a web server available. Fortunately they have a feature called TwiML Bins that you can setup within your Twilio Account and leverage it as this URL while sending it the text to speak.

  1. Login to your Twilio Account.
  2. On the very left side, click the circle with the 3 dots, just below the Home and # icons.
  3. Scroll to the Runtime section, and click TwiML Bins
  4. Click Create new TwiML Bin
  5. Enter a Friendly Name such as "Hubitat"
  6. In the TwiML text area, paste in the following code:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Pause length="2"></Pause>
    <Say>{{VoiceMessage}}</Say>
</Response>
  1. Click Create
  2. At the top of the record, you will find the URL for this TwiML Bin, click the bottom to the right of the URL to copy it to the clipboard
  3. Back in your Hubitat Twilio Container driver, find the TwiML Bin URL preference and paste the URL into that field and click Save Preferences
  4. To utilize this feature, in Rule Machine or other apps, use the Speak command and the text you wish to speak via phone call. This driver will call the phone number and speak the text entered.

The driver can be found here or in HPM:

Special thanks to @ogiewon for his original Pushover driver as inspiration for this driver.

6 Likes

If there was a way to send an email notification, it would be easy and free to send SMS via email gateways - at least here in the US (cant speak globally) carriers all support this AFAIK

I can email myphonenumber@vtext.com on Verizon and it is sent as SMS ...

Twilio doesn't provide email notifications. I don't know of a web service to send email notifications. Maybe Google has one but that would require a different driver.

The reason companies like Twilio exist is because email to SMS gateways aren't supported globally and I have had hit or miss success on delivery of those. Twilio guarantees delivery since the messages are delivered directly to the carriers.

What I was thinking is if the hub had an MTA it could send the email directly to an email address and therefore SMS via the gateway... dont need a webservice for that ... simple postfix/sendmail/whatever

I know why the exist, but was just thinking of an alternative (free and if done on the hub via MTA LOCAL) way of achieving the same result

Email MTA driver could work, just have to work out the details for sending to various SMTP providers. Usually your ISP provides one, or if you have a gmail account it would be possible.

I don't know of any technical limits we have that prevent a driver from working. Just time and priority. I've wanted an email send method for awhile but haven't heard of the demand from users until now.

Ahh, free time. Where are you... :slight_smile:

1 Like

Oh and BTW nice job on the twilio driver. I will have to check it out.

1 Like

Excellent work on this! We also use Twilio at work for customized notifications for users on an Enterprise level. They are rock solid with this.

On another note, I've integrated with Sfax to receive all my notifications via fax machine. If anyone wants this, I'm happy to share!

1 Like

Wouldn't IFTTT satisfy this requirement? I've used Gmail with applets in the past and it was reasonably fast.

Could do -- so could MQTT and a host of other things ... but for something as base as email, I would not want to use IFTTT (I dont use it at all) or other services ... using a hammer to kill a gnat :slight_smile:

If all you have is a hammer everything does look like a nail... or at least you have to treat it as such

Not sure I concur. IFTTT definitely is not a precision tool, but then neither is email. For me, once I'm forced to use any kind of cloud service, I personally don't care how many servers it has to hop to, as long as all of them are reasonably fast and reliable. IFTTT doesn't hold that track record for everything, but some connections have certainly never failed me or slowed significantly.

I consider services like IFTTT, Stringify, Yonomi and Gideon to be more like a multi-tool. You don't hammer away at a screw, you flip up the screwdriver and use it for what it was built to do. :wink:

I think we can agree to disagree with IFTTT ... its caused me too many issues, or in your example, stripped too many screwheads for me to revisit any time soon

2 Likes

Fair enough. Look forward to another great app/driver for Hubitat.

1 Like

Would it possible to use Twilio to send a text to Hubitat that would trigger a rule in rule machine?

Rules don’t have endpoints, an app does/can though. An app could create an event that a rule listens to. So very clunky.

Adding @chuck.schwer for thoughts since he had asked about this driver.

Use IFTTT as the trigger to turn on a virtual switch and create a rule truth.

IFTTT could
Probably be cobbled together but I’ve had less than stellar results using that.

The holly grail for me would be to have a chatbot that surfaces all my notifications and that I can chat back to trigger things. Hopefully in the future the bot would gain some intelligence and surface patterns, suggesting rules for them. That’s a ways off though.

You’re describing IFTTT with other platforms or Hubitat? I’ve had incredibly slow IFTTT performance with some manufacturers integrations, but the triggers and actions with Hubitat all seem to be around 8 sec, which isn’t fast, but fast for IFTTT.

Other platforms, I haven’t tried it with Hubitat.

Works better than expected!

Yeah, I'm thinking this would be the way to do it. write an App that would provide an endpoint and then point twilio to that endpoint. From there you could trigger an event or control a device. I'm not sure you would want to write a rule to be triggered, But since you are already writing an App you would just do what you need to do outside of Rule Machine.