Send sms via MQTT

Python script watching a MQTT topic and send msg to SMS

Could be used for sending notifications to sms from a home automation platform such as Home Asssitant etc.
Listens to topic /sms/

pip3 install python-gsmmodem-new
pip3 install paho-mqtt

Set config parameters to tty for the modems serial interface as well as parameters needed for mqtt

To send a sms to a phonebook number:

  1. Edit the phonebook dictionary and add names and numbers to all persons
  2. Send a MQTT message to topic /sms/name

To send a sms to all numbers in phonebook

  1. Send a MQTT message to topic /sms/all

To send a sms to any number

  1. Send a MQTT message to topic /sms/xxxxxxxxxxx The number will be translated to +xxxxxxxxxxx, no plus sign in the topic

Hi thanks for this share. Quick question does this require a specific modem to work or?

The main pre-req for the modem is that it sets up a serial port, and I think that most or all do.

I have personally only tested with four different Huawei modems and those all work. There may or may not be problems with the usb port set up as for powersave which can cause the port to die. Only solution for that so far is to unplug the modem and re-plug, but that really has nothing to do with the script itself.


Works perfect, got use of my old Maestro 100 GSM modem. I’m using it together with Supervisor daemon to keep it running on my ubuntu machine.

why not just use mailgun to send an email to your sms number ([email protected]) and skip the antequated serial gms modem step all together?

Because it will work only for Google FI subscribers

what are the hardwares used for this setup?

I assume the python script is installed in a computer such as Raspberry Pi and then a USB modem such as HUAWEI E3372 is plugged into the the same computer?

Sorry for the late response. The setup you mention is about what I use, a computer with a USB modem.

I think the point of sms is to communicate even when the is no internet connection.

I like to have an as Internet free HomeAssistant setup as possible. The GSM modem i something I just happened to have laying around so it was easy to use and configure. I can also receive commands to HA that way even though I haven’t implemented that part yet.