Trigger a simple Home Assistant Script from a HTTP?

Hi Everyone,
Could someone kindly help me understand how to run a simple script from Home Assistant using an HTTP command?
I am attempting to remap the Netflix button on my Nvidia Shield remote with an Android Remapper application.
I would like the remapper application to execute an HTTP command that would simply run a Home Assistant script.
Considering the advancements in Home Assistant over the years, I was hoping this would be easier to achieve?

Thanks in advance

Webhook triggers should do what you want.

If you open this URL:

http://<homeassistant_ip>:8123/api/webhook/run_my_actions

It will trigger this automation:

- alias: My Actions
  trigger:
  - platform: webhook
    webhook_id: run_my_actions
  action:
  - service: etc...

You can implement this using the automation editor GUI.

See here for more: https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger

Thanks Tom

But for some odd reason, this didn’t work for me, below in what l keyed in however the web browser reported the followng error message

" This site can’t be reached
The webpage at http://192.168.0.60:8123/api/webhook/run_my_actions might be temporarily down or it may have moved permanently to a new web address.
ERR_INVALID_RESPONSE"

alias: My Actions
trigger:
  - platform: webhook
    webhook_id: run_my_actions
    allowed_methods:
      - POST
      - PUT
    local_only: true
action:
  - action: notify.pushover
    metadata: {}
    data:
      message: Testing 1 2 3 4
mode: single

Do you access your local home assistant web page via HTTP or HTTPS?

You need to curl the webpage from a command prompt:

curl -X POST http://192.168.0.60:8123/api/webhook/run_my_actions

Just opening in a browser won’t work :thinking:

I used → HTTP

Thank you!

Thanks works from the Windows command prompt only

1 Like

Having said the above, there must be a workable way to run a script using a HTTP from a web browser?

Yeah, sure, just create a button in HTML, and use POST to call the webhook URL…

Coming from Hubitat, running an automation via an HTTP command was a breeze. Given that Home Assistant is more advanced, I thought this would be easy.

Responses I’ve Received so far (Thanks to those who have tried to help):

  1. Use Webhooks and Run Directly via HTTP
    -Result: Doesn’t work from the browser.
  2. Use the Curl Command
    -Result: Also doesn’t work from the browser.
  3. Create some sort of HTML Button
    -Result: Doesn’t work with 3rd party applications.

Is this all that is available? Surely, I can’t be the only person requesting this.

Recap - I would like to be able to run a script via an HTTP command directly from a web browser.
For example within Google Chrome-> http://192.168.0.1:8123/api/my_script

Should I submit a feature request to the Home Assistant team?

It works if you add ‘GET’ as an allowed method. That is what your browser uses when you go to a page by default. ‘PUT’ and ‘POST’ requests are used when sending a form for example.

Excellent! This works - Thanks hardew

For those who also want to know how to do this, below is my automation that l have tested and with hardew’s help and got it to work.

alias: My Actions
trigger:
  - platform: webhook
    webhook_id: run_my_actions
    allowed_methods:
      - GET
    local_only: true
action:
  - action: notify.pushover
    metadata: {}
    data:
      message: Testing 1 2 3 4
mode: single

To execute this automation from a web browser run the following:
http://<home assistant IP:>:8123/api/webhook/run_my_actions

Can I just confirm. If the URL is known, and you’re HA instance is accessible from the internet, that you could run commands via a webhook that required no authorisation method ?

Only if you leave out this

local_only: true

Is there a way of passing some credentials to authorise the webhook call? Or is it simply local or not ?

Simply local or not.

You could use security by obscurity (not great) if you make the webhook a long random set of characters. e.g. 2x UUIDs 38057a79-42c3-4b3f-aafc-cb551ae39a37-12e3f5a3-e1ae-4fda-93d6-57ddd3be2795

Also ensure you are using a secure (https) URL.

Whilst not ideal, I think thats probably the route I would take.

Or is there a way to detect the ip of the incoming request ?

Nope.