ZTE 3G/4G dongle SMS notification

Sharing configuration for sending notifications via SMS using ZTE dongle. I have a ZTE MF710 modem, the configuration might work with other dongles that appear as virtual ethernet adapters on the host (hassio in my case on raspberry pi).
The dongle has a web interface that can be accessed with a browser at http://192.168.0.1/

configuration.yaml

notify:
  - platform: rest
    name: sms
    resource: http://192.168.0.1/goform/goform_set_cmd_process
    method: POST
    headers:
      host: 192.168.0.1
      referer: http://192.168.0.1/index.html
    target_param_name: Number
    message_param_name: MessageBody
    title_param_name: encode_type
    data_template:
      goformId: 'SEND_SMS'
      isTest: 'false'
      notCallback: 'true'
      ID: '-1'
      sms_time: '{{now().year%100}}%3B{{now().month}}%3B{{now().day}}%3B{{now().hour}}%3B{{now().minute}}%3B{{now().second}}%3B%2B0'
      encode_type: GSM7_default

At this point I can only send notification with GSM 7-bit encoding (https://www.developershome.com/sms/gsmAlphabet.asp) so it is restricted to predefined notifications. If somebody knows how to encode strings (with jinja?) or what other formats the dongle supports, please share here so that we can also send templated messages.

automations.yaml

action:
  service: notify.sms
  data:
    target: '0123456789'
    message: '00680061006C006C006F'

This sends an SMS to phone number 0123456789 with text hallo .

2 Likes

And here it is: the templatable version. Works with the most basic characters only, though the table can be extended with a few more.

configuration.yaml

notify:
  - platform: rest
    name: sms
    resource: 'http://192.168.0.1/goform/goform_set_cmd_process'
    method: POST
    headers:
      host: '192.168.0.1'
      referer: 'http://192.168.0.1/index.html'
    data_template:
      goformId: 'SEND_SMS'
      isTest: 'false'
      notCallback: 'true'
      Number: '{{target[0]}}'
      sms_time: '{{now().year%100}}%3B{{now().month}}%3B{{now().day}}%3B{{now().hour}}%3B{{now().minute}}%3B{{now().second}}%3B%2B2'
      MessageBody: >
        {%- set table = {
          ' ':'20','!':'21','"':'22','#':'23','¤':'24','%':'25','&':'26','\'':'27','(':'28',')':'29','*':'2A',
          '+':'2B',',':'2C','-':'2D','.':'2E','/':'2F',
          '0':'30','1':'31','2':'32','3':'33','4':'34','5':'35','6':'36','7':'37','8':'38','9':'39',
          ':':'3A',';':'3B','<':'3C','=':'3D','>':'3E','?':'3F','¡':'40',
          'A':'41','B':'42','C':'43','D':'44','E':'45','F':'46','G':'47','H':'48','I':'49','J':'4A','K':'4B','L':'4C','M':'4D','N':'4E','O':'4F','P':'50','Q':'51','R':'52','S':'53','T':'54','U':'55','V':'56','W':'57','X':'58','Y':'59','Z':'5A',
          'a':'61','b':'62','c':'63','d':'64','e':'65','f':'66','g':'67','h':'68','i':'69','j':'6A','k':'6B','l':'6C','m':'6D','n':'6E','o':'6F','p':'70','q':'71','r':'72','s':'73','t':'74','u':'75','v':'76','w':'77','x':'78','y':'79','z':'7A',
        } -%}{%- for chr in message|string -%}00{{table[chr]|default('32')|string}}{%- endfor -%}
      ID: '-1'
      encode_type: GSM7_default

automations.yaml

action:
  service: notify.sms
  data:
    target: '001234567890'
    message: 'Hello World!'
2 Likes

You just plugged the modem into USB and it was able to connect via http:192.168.0.1? Or, did the modem require some SSH commands or similar in order to be recognized by your Pi/HASSIO?

No setup required, this modem acts like a usb network card and on linux worked out of the box.

@rp3tya thanks a lot for providing your notify configuration

I have had some trouble getting it to work. I receive an error in home assistant whenever i try to call the notify.sms service - “str’ object has no attribute ‘hass’”

I have been able to get it to work by playing around, but i don’t really know what I’m doing. This is my solution:

configuration.yaml

notify:
  - platform: rest
    name: sms
    resource: 'http://192.168.0.1/goform/goform_set_cmd_process'
    method: POST
    headers:
      host: '192.168.0.1'
      referer: 'http://192.168.0.1/index.html'
    data_template:
      goformId: '{{target[1]}}'
      isTest: '{{target[2]}}'
      notCallback: '{{target[3]}}'
      Number: '{{target[0]}}'
      sms_time: '{{now().year%100}}%3B{{now().month}}%3B{{now().day}}%3B{{now().hour}}%3B{{now().minute}}%3B{{now().second}}%3B%2B2'
      MessageBody: >
        {%- set table = {
          ' ':'20','!':'21','"':'22','#':'23','¤':'24','%':'25','&':'26','\'':'27','(':'28',')':'29','*':'2A',
          '+':'2B',',':'2C','-':'2D','.':'2E','/':'2F',
          '0':'30','1':'31','2':'32','3':'33','4':'34','5':'35','6':'36','7':'37','8':'38','9':'39',
          ':':'3A',';':'3B','<':'3C','=':'3D','>':'3E','?':'3F','¡':'40',
          'A':'41','B':'42','C':'43','D':'44','E':'45','F':'46','G':'47','H':'48','I':'49','J':'4A','K':'4B','L':'4C','M':'4D','N':'4E','O':'4F','P':'50','Q':'51','R':'52','S':'53','T':'54','U':'55','V':'56','W':'57','X':'58','Y':'59','Z':'5A',
          'a':'61','b':'62','c':'63','d':'64','e':'65','f':'66','g':'67','h':'68','i':'69','j':'6A','k':'6B','l':'6C','m':'6D','n':'6E','o':'6F','p':'70','q':'71','r':'72','s':'73','t':'74','u':'75','v':'76','w':'77','x':'78','y':'79','z':'7A',
        } -%}{%- for chr in message|string -%}00{{table[chr]|default('32')|string}}{%- endfor -%}
      ID: '{{target[4]}}'
      encode_type:  '{{target[5]}}'

automations.yaml

action:
  service: notify.sms
  data:
    target: ['001234567890','SEND_SMS', 'false', 'true', '-1', 'GSM7_default']
    message: 'Hello World!'

Perhaps somebody that knows what they’re doing can kindly provide a better solution.

Thanks

Why do you pass all fields as parameters? They should not change as far as I know.
I suspect that the corresponding data fields are not templatable, hence the error message.

Yes, if there are any regular data fields in data_template, an error is returned.

how did this endeavor work out in the long run?