Send SMS with USB GSM modem when alarm triggered

My approach is:

1. Variant

  • gsm modem on linux (in my case host of hassio docker)
  • install gammu-smsd
  • configure stored data in sql database (install/configuration of sql server needed)
  • configure gammu-smsd to call script after received sms (curl command to call homeassistant webhook with json data from sms)
#!/bin/sh

from=$SMS_1_NUMBER
message=$SMS_1_TEXT

curl --request POST \
     --url 'https://homeassistanturl/api/webhook/incomingsms' \
     --header 'content-type: application/json' \
     --data "$( jq -nc --arg dela "$from" --arg mesaj "$message" '{"from": $dela, "smsmesaj":  $mesaj }' )"
  • generate ssh key in /homeassistant/config (to be persistent) and copy ssh keys to sistem host.
  • issue rest_command from home assistant

trimitesms: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no user@iphost 'gammu-smsd-inject TEXT {{ numarsms }} -text "{{ textsms }}"'

  • make sql sensor to read recieved and send sms data from gammu
  • make a custom lovelace card to display all data

gsm-lovelace-card

2. Variant (easy one)

esphome:
  name: gsm_esp32
  platform: ESP32
  board: esp-wrover-kit

wifi:
  ssid: ''
  password: ''

logger:
  level: debug
  # baud_rate: 0

ota:

api:
  services:
  - service: send_sms
    variables:
      recipient: string
      message: string
    then:
    - sim800l.send_sms:
        recipient: !lambda 'return recipient;'
        message: !lambda 'return message;'

uart:
  baud_rate: 9600
  tx_pin: 27
  rx_pin: 26

switch:
  - platform: gpio
    id: "key_pin"
    pin: 4
    restore_mode: ALWAYS_OFF
  - platform: gpio
    id: "reset_pin"
    pin: 5
    restore_mode: ALWAYS_ON
  - platform: gpio
    id: "power_pin"
    pin: 23
    restore_mode: ALWAYS_ON

sim800l:
  on_sms_received:
    - lambda: |-
        id(sms_sender).publish_state(sender);
        id(sms_message).publish_state(message);
    - logger.log:
        format: "Received '%s' from %s"
        args: [ 'message.c_str()', 'sender.c_str()' ]

text_sensor:
- platform: template
  id: sms_sender
  name: "Sms Sender"
- platform: template
  id: sms_message
  name: "Sms Message"

I use both variants to send critical alerts about my sistem. (Even if i have no power/internet).

5 Likes