← All integrations

Send SMS from Home Assistant

Get a text when the alarm goes off, the freezer warms up or the front door opens at night, even when the phone that receives it has no internet. Home Assistant calls the NS SMS API with rest_command, and your Android phone sends the SMS from its own SIM card.

Who this is for

  • Home Assistant users who want SMS alerts for family members without the companion app.
  • Holiday homes, garages and workshops where push notifications are not enough.
  • Anyone who prefers to keep the setup in YAML, with no custom integration to install.

Before you start

  • An Android phone (8.0 or newer) with a SIM card that can send SMS.
  • The NS SMS app from Google Play, set as the default SMS app, with "Accept API requests" turned on in the API tab.
  • Your phone ID (device_id) and API key (nss_...) from the API tab. Below they appear as YOUR_DEVICE_ID and nss_YOUR_API_KEY.
  • Access to your Home Assistant config folder (File editor or Studio Code Server add-on, Samba or SSH).

No account, email or password. Install the app, turn on the API and copy your phone ID and API key.

Setup, step by step

  1. Step 1.Store the API key as a secret

    Open secrets.yaml (next to configuration.yaml) and add the value of the Authorization header: the word Bearer, a space and your key.

    secrets.yaml
    ns_sms_auth: "Bearer nss_YOUR_API_KEY"
  2. Step 2.Add a rest_command

    Add this to configuration.yaml and replace YOUR_DEVICE_ID. The to_json filter turns the number and the message into valid JSON strings, so quotes and new lines in the message cannot break the request.

    configuration.yaml
    rest_command:
      send_sms:
        url: "https://sms-api.n-soft.pl/v1/sms/send"
        method: post
        headers:
          Authorization: !secret ns_sms_auth
        content_type: "application/json"
        payload: >-
          {"device_id": "YOUR_DEVICE_ID",
          "to": {{ to | to_json }},
          "text": {{ message | to_json }}}

    If configuration.yaml already has a rest_command: section, put send_sms under it instead of adding a second rest_command: key.

  3. Step 3.Restart and send a test SMS

    Check the configuration (Developer tools > YAML), restart Home Assistant, then run the action from Developer tools > Actions in YAML mode. The phone sends the SMS within a few seconds.

    Developer tools > Actions (YAML mode)
    action: rest_command.send_sms
    data:
      to: "+14155550123"
      message: "Hello from Home Assistant"
  4. Step 4.Use it in an automation

    Create a new automation, open the three-dot menu, choose Edit in YAML and paste the example. Replace binary_sensor.front_door with your own entity. Templates such as now() work in the message.

    Automation editor > Edit in YAML
    alias: SMS when the front door opens at night
    triggers:
      - trigger: state
        entity_id: binary_sensor.front_door
        to: "on"
    conditions:
      - condition: time
        after: "23:00:00"
        before: "06:00:00"
    actions:
      - action: rest_command.send_sms
        data:
          to: "+14155550123"
          message: "Front door opened at {{ now().strftime('%H:%M') }}"
    mode: single
  5. Step 5.Optional: an SMS notify service

    Some blueprints and scripts expect a notify action. The RESTful notify platform can send the same request: it puts the message in text, the target in to and adds device_id. Restart again after adding it, then call notify.sms.

    configuration.yaml
    notify:
      - name: sms
        platform: rest
        resource: "https://sms-api.n-soft.pl/v1/sms/send"
        method: POST_JSON
        headers:
          Authorization: !secret ns_sms_auth
        message_param_name: text
        target_param_name: to
        data:
          device_id: "YOUR_DEVICE_ID"
    automation action
    action: notify.sms
    data:
      message: "The washing machine has finished."
      target: "+14155550123"

Check the status and receive webhooks

The send request answers 202 with a message ID right away. The status then moves through received (the phone has it), sent and delivered, or failed with an error code. You can ask for it with GET /v1/sms/{id}, or let the server POST every change to a webhook address that you set in the app (API tab). Webhooks work on every plan and also report usage.warning, usage.limit_reached, device.offline and device.online.

To see the result inside an automation, add response_variable: sms to the rest_command action. sms.status is the HTTP status (202 when accepted) and sms.content.id is the message ID.

To react to webhook events, create an automation with a webhook trigger and set the webhook address in the NS SMS app to https://YOUR-HOME-ASSISTANT/api/webhook/<webhook_id>. Home Assistant must be reachable from the internet over HTTPS (for example through Home Assistant Cloud or your own reverse proxy). This example warns you when the SMS phone stops reporting:

Automation editor > Edit in YAML
alias: NS SMS phone went offline
triggers:
  - trigger: webhook
    webhook_id: ns-sms-REPLACE-WITH-A-LONG-RANDOM-STRING
    allowed_methods:
      - POST
    local_only: false
conditions:
  - condition: template
    value_template: "{{ trigger.json.event == 'device.offline' }}"
actions:
  - action: persistent_notification.create
    data:
      title: NS SMS
      message: "The SMS phone stopped reporting at {{ trigger.json.sent_at }}."
mode: queued

A webhook trigger cannot check the X-NS-Signature header, so treat the webhook ID as a password: make it long and random, and keep it out of screenshots.

Troubleshooting

  • Action rest_command.send_sms not found: the YAML was not loaded. Check the configuration, read Settings > System > Logs and restart.
  • Versions older than late 2024 use service: instead of action:, and trigger:/platform: instead of triggers:/trigger:. Building the automation in the visual editor writes the right syntax for your version.
  • An automation that fires on every sensor change can use up the daily cap quickly. Add a condition, a for: duration or mode: single.
  • 401 unauthorized: the Authorization header must be "Bearer " followed by the key, and device_id must belong to that key.
  • 403 api_disabled: open the app and turn on "Accept API requests" in the API tab.
  • 422 validation_failed: the number must be in international E.164 format, with + and the country code (for example +14155550123), and the text at most 1,600 characters.
  • 429: more than 30 requests a minute, or the daily or monthly cap of your plan (Free 50 a day, Pro 500, Business 1,000). The response says which one.

SMS API reference → SMS error codes → Plans and daily limits →

Use cases for Home Assistant

Other integrations