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:
- Have parent container driver that creates children notification devices so you only have to enter the Twilio API once in the parent container.
- 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.
- 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:
- Sign up for a Twilio account
- Fund the account via credit card or PayPal - $20 minimum unfortunately
- 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.
- Capture your account's SID and Auth Token:
- 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.
- Create a new virtual device and set the type to Twilio Container and Save Device.
- Enter the Twilio API Credentials into the Hubitat driver:
- Designate whether you are using an Alpha Sender, default no.
- Select your Twilio Phone Number or Alpha Sender and Save Preferences.
- 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.
- Login to your Twilio Account.
- On the very left side, click the circle with the 3 dots, just below the Home and # icons.
- Scroll to the Runtime section, and click TwiML Bins
- Click Create new TwiML Bin
- Enter a Friendly Name such as "Hubitat"
- In the TwiML text area, paste in the following code:
<?xml version="1.0" encoding="UTF-8"?>
- Click Create
- 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
- Back in your Hubitat Twilio Container driver, find the TwiML Bin URL preference and paste the URL into that field and click Save Preferences
- 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.