Notify service using a web form

I have a garmin inreach satellite communicator i would like to use as a notify service.

It uses a random phone number for sms and i dont want to use an sms gateway to send replies. But there is a web form that can be used to submit an email, name and message.

Is there a way to create a notify service that will submit a message to this html form so i can get select high priority alerts sent to my sat communicator?

I could easily handle two way communication by monitoring the email address for replies.

The use case is i run homeassistant on a 10w computer in my overlanding truck, and i want to get alerts if the camper alarm is triggered or the batteries are below a threshold while im off back packing. However the messages cost .50$ so i just have to be careful how and when it’s used.

I see this is likely a use for notify.command_line using a script that does the form submit

It seems that homeassistant doesn’t include the necessary library to submit forms. However I was able to inspect the web-page after sending a test message and extracted the uri and headers sent.

Here’s an example that can be used with the command_line integration by placing in /config/scripts/inreach_notify.py

note your reply-to email should replace example%40domain.com with @ encoded as %40
the Guid TEST should be replaced with the GUID in the addressbar when you visit the send-message web interface for your inreach account

import subprocess
import sys
import json

MAX_MESSAGE_LENGTH = 160

def send_message(message):
    # Check the length of the message
    if len(message) > MAX_MESSAGE_LENGTH:
        return "Error: Message too long (maximum 160 characters)"

    # Encode the message
    encoded_message = subprocess.check_output(["bash", "-c", f"echo '{message}' | jq -s -R -r @uri"]).decode('utf-8')

    # Construct the payload
    payload = f"ReplyAddress=example%40domain.com&ReplyMessage={encoded_message}&Guid=TEST"

    try:
        # Use subprocess to execute the curl command
        result = subprocess.check_output(["curl", "-s", "-H", "authority: us0.explore.garmin.com", "-H", "origin: https://us0.explore.garmin.com", "-H", "referer: https://us0.explore.garmin.com/textmessage/txtmsg?extId=TEST", "-H", "x-requested-with: XMLHttpRequest", "--data-raw", payload, "--compressed", "https://us0.explore.garmin.com/TextMessage/TxtMsg"])

        # Parse the JSON response
        response = json.loads(result)

        # Check the success status and return the appropriate message
        if "Success" in response and response["Success"]:
            return "Message sent successfully"
        else:
            return "Failed to send message"
    except subprocess.CalledProcessError as e:
        return f"Error: {e}"

if __name__ == "__main__":
    message = sys.argv[1] if len(sys.argv) > 1 else ""
    result = send_message(message)
    print(result)

command_line:
  - notify:
      name: inreach
      command: "python3 /config/scripts/inreach_notify.py {{ message }}"

Once I pair this with an imap/pop integration and the starlink satellite on my truck, I can now control homeassistant from literally anywhere on the planet, even if there’s no cell service. I just would need to configure pre-defined commands to respond to, like “pre-heat” or “conserve power”

1 Like

You could just use this: RESTful Command - Home Assistant.

1 Like

Thanks i converted to this,

Heres what i did if anyone wants this

inreach_notify:
  url: 'https://us0.explore.garmin.com/TextMessage/TxtMsg'
  method: 'POST'
  payload: 'ReplyAddress={{ fromaddress }}&ReplyMessage={{ message }}&Guid={{ guid }}'
  content_type: 'application/x-www-form-urlencoded'
  headers:
    authority: 'us0.explore.garmin.com'
    origin: 'https://us0.explore.garmin.com'
    referer: 'https://us0.explore.garmin.com/textmessage/txtmsg?extId={{ guid }}'
    x-requested-with: 'XMLHttpRequest'

Just be careful, the messages are $0.50 a pop