Skip to main content

Twilio Integration (Whatsapp)

In the configuration.yaml these lines are added

twilio:
  account_sid: !secret twilio_SID
  auth_token: !secret twilio_auth_token

the constants !secret twilio_SID and !secret twilio_auth_token are defined in the file secrets.yaml

In Twilio Phone Numbers we need to purchase a number that is able to deliver SMS.

Then in Twilio Console > Messaging > Senders > Whatsapp senders we need to create a new sender which we will link to the Twilio phone number we created and we will need to fill up business information and link our Meta Business account with our Twilio account (that's only for the first sender, later we should in theory be able to add more for the same Twilio + Meta account).

2 integrations are needed: Twilio and Twilio SMS:

https://www.home-assistant.io/integrations/twilio/
https://www.home-assistant.io/integrations/twilio_sms

When the Twilio integration is added from Settings > Integrations, you will get a popup showing what webhooks to add in Twilio Console. Copy that information and head to Twilio Console > Messaging > Senders > Whatsapp senders and click on the sender we are using. There you will find something like below:

image.png

Now in the configuratin.yaml we need to add a notification service that will allow us to send notifications from our whatsapp number:

  - name: twilio_us
    platform: twilio_sms
    from_number: whatsapp:+1123456789

This would be enough to send whatapps on automations, but those whatsapps cannot be just any message, they have to be done using templates. Those templates are defined in Twilio and approved by Whatsapp (Meta).

In Twilio we have to go to Messaging > Whatsapp templates and create a template. It is an easy process. An example of template is:

Ocean Builders informs you about a change in the lights of your Pod. The light {{1}} has been turned {{2}}. If this this is an expected change you do not have to take any actions. Else please use the buttons below.

Then you can create an automation and as long as you send a message with exactly the same content as in the template it will work. I however encountered problems if I have to add new lines to the message.