I’d like to thank @shellian_systems whose post Free SMS notifications via MQTT inspired me to explore IFTTT as a means of sending free SMS messages.
OVERVIEW
- In IFTTT, create an applet that, when triggered by a REST command, sends the received message, via SMS, to a preset telephone number.
- In Home Assistant, use the RESTful_command component to send a message to IFTTT.
INSTRUCTIONS
STEP 1: Create an applet in IFTTT that sends an SMS message when triggered via a URL.
- In IFTTT’s main menu (upper right-hand side), select New Applet.
- Click This in “IfThisThenThat”.
- For “Choose a Service”, enter Webhooks and click it.
- For “Choose Trigger”, click Receive a web request.
- For “Complete Trigger Fields”, enter send_sms for Eventname.
- Click Create Trigger.
- Click That in “IfThisThenThat”.
- For “Choose an Action Service”, enter SMS. Click it.
- You’ll be taken through an SMS setup procedure. Enter your telephone number. You’ll receive a PIN code via SMS. Reply with the PIN to confirm your phone number.
- For “Choose Action”, click Send me an SMS.
- For “Message” replace everything written in the box with {{Value1}}.
- Click Create Action.
- Click Finish.
STEP 2: Record your IFTTT Webhooks authorization code.
- In IFTTT’s main menu (upper right-hand side), select Services.
- Enter Webhooks. Click it.
- Click Settings.
- Copy the authorization code at the end of URL. https://maker.ifttt.com/use/XYZ123ABC
STEP 3: Paste your personal code in secrets.yaml.
# Replace XYZ123ABC with your personal IFTTT Webhooks authorization code
ifttt_send_sms: 'https://maker.ifttt.com/trigger/send_sms/with/key/XYZ123ABC'
NOTE: The word “send_sms” in this URL must match the word used for EventName when you created the applet.
STEP 4: Create a rest_command, called send_sms, in configuration.yaml:
rest_command:
send_sms:
url: !secret ifttt_send_sms
method: POST
headers:
accept: 'application/json'
payload: '{ "value1": "{{ sms_text }}" }'
content_type: 'application/json; charset=utf-8'
Done! Restart Home Assistant and now you have a new service called rest_command.send_sms.
USAGE
Here’s a simple script demonstrating how to use it:
In scripts.yaml:
test_sms:
alias: Send SMS test message
sequence:
- service: rest_command.send_sms
data:
sms_text: "Hello world!"
Restart Home Assistant and “Send SMS test message” will appear in the Frontend UI. Click EXECUTE to send the “Hello world!” message.
IFTTT currently allows for 100 SMS messages per month in the USA and Canada (elsewhere it’s 10 per month).
EDIT
Well, I feel foolish! Effectively, I’ve “discovered” something that already exists! https://www.home-assistant.io/components/ifttt/ Oh well, just another way to accomplish the same thing. My way is a bit more tailored for a specific purpose whereas the IFTTT component is more of a generalist. Nonetheless, it was a good learning experience for me.