REST command as "notify" service

Hi !
I’m using “JPI” ( Get JPI ) to use an old Android phones as an SMS gateway.
From Home Assistant, I have this :

rest_command:
  sendsms_jpi:
    url: 'http://androidPhoneIPaddress:8080/?action=sendSms&number={{numtel}}&message={{message}}'

So, I can use this “sendsms_jpi” rest command from Home Assistant to send SMS through the android phone.

Now, I want to use it aas a “notify service”, to be able to use it with Alarmo.
Is it possible ?

Use a rest notify component instead of the rest_command component:

I use the rest notify component for sending notifications to a googletv device, it took me a little while to work out how to add parameters. In my case, it’s a POST with JSON data, not a GET, but I think this should work for your needs:

notify:
  - name: sendsms_jpi
    platform: rest
    resource: http://androidPhoneIPaddress:8080/action?sendSms
    data:
      "number": "{{ data.numtel if (data.numtel is defined) else 'set_a_default_number_here' }}"
      "message": "{{ message }}"

Then call it from an automation with an action like so:

  - service: notify.sendsms_jpi
    data:
      message: "Whatever text you want to send"
      data:
        "numtel": "212-555-2368"

The only ‘clever’ thing I’ve done here is to set a default number in the component, so that the inner data section(beneath the message in my example) of the automation action could be omitted if you mainly only ever send to one number (but want to retain the ability to send to arbitrary numbers). Both message and numtel in the action could also be templates rather than just plain strings.

Thanks @gonzotek it works perfectly :slight_smile:

1 Like