No announcement yet.

Any way to make phone calls with Twilio and this plugin?

  • Filter
  • Time
  • Show
Clear All
new posts

    Any way to make phone calls with Twilio and this plugin?

    I was steered this way on another thread about trying to have alert/alarm events trigger a phone call with text to speech announcement. At first was looking to get HS3 VoIP/SIP connectivity, to use with my current VoIP service, but seems there isn't any current SIP HS3 plugin. Then someone suggested Twilio. So far I've set up a trial Twilio account, installed this plugin and configured it with Twilio account. So far all I am able to get working to send SMS messages on events, but not really needing that as I can already send SMS messages through email to mobile phones.

    Can anyone confirm whether or not there's any option for phone calls with voice announcements (text to speech) using this plugin and Twilio, or any other ideas other than a circa 1990s POTS dialer? Maybe I'm limited because I'm only on Twilio trial right now, though plugin device options only seems to support SMS messaging, unless there's something on Twilio side to convert this to a phonecall? Haven't found anything indicating that's an option.

    Using HS3 Pro running on Win10 Pro

    I am interested in this as well. I have been using Twilio for SMS alerts from HomeSeer for about 2 years now an it has been rock solid. Although I do not use the plugin, I use a script. I currently use a Twilio plugin for Home Assistant and it supports Text To Speech, so it is possible. I will spend some time on this over the next few weeks.


      For a programmed voice call using Twilio you can use an HTTP POST call
      see here -


        Originally posted by JB-dallas View Post
        For a programmed voice call using Twilio you can use an HTTP POST call
        see here -
        good find, that works great. Thanks


          Hi will40, were you able to get the HTTP post call for the Twilio phone call to work? I modified my SMS script (that uses a HTTP post request) to perform a call. I am able to get it somewhat working, but I am having an issue with the string encoding. The SMS message body could be a normal string, but in order to use the TTS service, it needs to be URL or UTF8 encoded. I do not know how to convert the ASCII string to a UTF8 encoded string in my C# script.



            Hey Adam

            I ran it as an HS3 event to "run another program" using the curl command line on their website and worked. I looked further on the site how to call an audio file instead of the demo @ ( or maybe even text to speech for individual announcements, but it went over my head.

            I will pick away at improving this with more time unless you understand how to generate a TwiML and can help me? My immediate event is below if it helps you. It does dial out and ring my phone and gives me the demo welcome audio when I answer it.

            Click image for larger version  Name:	twilio.JPG Views:	0 Size:	35.6 KB ID:	1351633


              It just took some more reading

              Rather than starting up your own webserver to host the scripts, TwilioBin can host the scripts you create on the Twilio console. I have it setup as HS3 events now for home emergency notification outbound phone calls using text to speech messages and it works.

              Now if I was only smart enough to figure out how to build a plug in to attach HS3 device value and status to the TTS messages it would be close to a complete VOIP notification solution similar to Smartercontrol's SCSIP PI that dropped out years ago.


                Hi Will,

                I had some time to play this evening. I took my Twilio SMS script and I modified it for a phone call. I cannot take credit for this script; it was taken from this forum a while ago. I tried for a few hours to get the UrlEncode function to work, but my C# skills are basic and I did a dirty workaround of replacing spaces with %20. I might post a request someplace else to help me do it the proper way; It is probably a simple mistake.

                Anyway, it seems to work quite well for me. I fill in the parameter field with what I want the TTS say. It will even work to resolve the device values. Be careful with special characters; it might not work with the URL.

                Also, play around with the voices in Twilio. The included default voice is not real sounding. I found enabling the Amazon Polly voices were much better and easier to understand.

                // Simple phone call script using https api via curl
                using System;
                using System.Diagnostics;
                public Object Main(Object[] parm)
                  string arg;
                  // HS3 always seems to pass 1 parameter - but check for existence
                  // reflect the error in the txt message
                  if ( parm.Length < 1 ) {
                    arg = "ERROR - No argument(s) passed";
                  else {
                    // The single parameter is a string so so convert it from object
                    arg = parm[0].ToString();
                    // Need to provide at least 1 character parameter message string
                    if ( arg.Length < 1 ) {
                      arg = "--No message text parameters provided--";
                  // Parameter string can contain HS3 replacement variables:
                 // e.g. "$date $time Mode $$DSA:V1: Motion"
                  arg = hs.ReplaceVariables( arg );
                  // Edit the following string constants to reflect your account
                  // information and to and from phone numbers.
                  const string accountSid = "#######################";
                  const string authToken = "#######################";
                  const string fromPhone = "+1##########";  // Twillow sending phone number
                  const string toPhone = "+1##########";    // Mobile phone to call to
                  //Replace spaces with %20 for allow for URL encode
                  string messageText = arg.Replace(" ", "%20");
                  // Build the curl argument string
                  string curlArgs = "-X POST \"" +
                                    accountSid + "/Calls.json\" " +
                                    "--data-urlencode \"To=" + toPhone + "\" " +
                                    "--data-urlencode \"From=" + fromPhone + "\" " +
                                    "--data-urlencode \"Url=" + messageText + "\" " +
                                    "-u " + accountSid + ":" + authToken;
                  // Log the message to be sent
                  hs.WriteLog( "CALL-CURL", curlArgs );
                  // Launch curl process to send message
                  System.Diagnostics.Process proc = new System.Diagnostics.Process();
                  proc.StartInfo.FileName = "curl";
                  proc.StartInfo.Arguments = curlArgs;
                  return 0;
                Click image for larger version

Name:	CaptureTwilio.PNG
Views:	420
Size:	43.2 KB
ID:	1351993


                  Looks good Adam! The script ran right out of the box and with different arguments I am trying with no errors.

                  I will continue to kick this around but looks like you nailed it.



                    Great. I’m happy it worked ok. I’m still not a fan of the way I encoded the URL, so I will likely poke at it.


                      Hi Adam

                      i read your post about your modified script with interest
                      I am a complete beginner with twillo and I just set up test account and it works with the plugin to send SMS

                      If I would like to try your script would I have to configure something in twillo itself or is it all fully confined to the script.




                        You will need a Twilio account and a purchase a phone number. I think I pay $1/month per number and you pay for each call/sms (very cheap though).

                        This scrip is for auto dialing a TTS (Text To Speech) message to a phone number. I use a different script for sending SMS messages. If sending SMS messages is all you need, I would recommend using the Twilio HomeSeer plugin instead of scripting.

                        The only config required in Twilio is enable the number to support phone calls and optionally you can enable Amazon Polly voice profiles for better sounding messages.


                          Adam I have been using Twilio since you got me started the beginning of the year with the scripts and all is well.

                          I just noticed on a current dashboard login that Twilio is going to two-factor authentication in Oct. I assume that is going to through a wrench into the scripts?