Can't trigger an automation using a URL

Scenario:
I have guests staying and I want to create an automation that they can trigger either via a URL or embed that URL into a QR code.

The automation YAML is as follows:

alias: Guest Lights
description: ""
trigger:
  - platform: webhook
    allowed_methods:
      - POST
    local_only: true
    webhook_id: TurnOnGuestLights
condition: []
action:
  - type: turn_on
    device_id: 6ac5dadef429dc75045bfd7963e11605
    entity_id: 9e6563130317c6f8f358bd45c2223812
    domain: light
    brightness_pct: 100
mode: single

The URL for this webhook is:
https://192.168.13.6:8123/api/webhook/TurnOnGuestLights

When I enter that URL into a browser I get this error message:
“ERR_INVALID_RESPONSE”

Looking at the HA logs, it shows:

  • Webhook TurnOnGuestLights only supports POST methods but GET was received from 192.168.13.69

How is this possible when the YAML clearly shows that the allowed_method IS POST?

As per the documentation, I tried the same thing but changed the allow_method to PUT and the error logs show:

  • Webhook TurnOnGuestLights only supports PUT methods but GET was received from 192.168.13.69

How can I fix this please?
Thanks in advance

That URL alone performs a GET operation.

That’s why both of your tests produced an error message indicating “but GET was received from 192.168.13.69”.

If you look at the Webhook Trigger’s documentation, it shows using the curl command to perform a POST request.

Unless you really need to use POST or PUT, I suggest you configure the Webhook Trigger to accept a GET request. Once you confirmed it works, you can optionally switch it back to PUT or POST but then you will need to use curl or some other means of producing a POST/PUT request.

Hi,
Thanks for your reply.

I saw the ‘curl’ bit but I don’t understand how that can be used or embedded into a URL.
If it was a QR Code, how would a mobile device scan that and process it accordingly?

If you just access a URL with a browser, that’s a GET request.

From the docs:

Webhooks support HTTP POST, PUT, HEAD, and GET requests; PUT requests are recommended. HTTP GET and HEAD requests are not enabled by default but can be enabled by adding them to the allowed_methods option.

I know that, that’s what it says in the documentation.

So, how do I get this working?

    allowed_methods:
      - GET

Brilliant.

That ‘kind of’ works, the automation gets triggered but also initiates a file download, while I appreciate this is likely to be part of the ‘GET’ process as it’s asking to get/retrieve information and the browser interprets this as a download or something, I can see this being a bit concerning to guests if they don’t know what it is.

Anyone know of how to get around this or a better way of achieving this?
Thanks very much

How are you presenting this to guests?

The docs say you should use POST:

If you’re using a local HTML page, just use a form submit button to do the POSTing. See this page and the method section on the following page:

The idea is that a guest scans a QR Code to trigger the automation but I DON’T want people to have to install the companion app or login to anything just to trigger an automation.

If I could setup a dashboard with various things (turn heating on, change lights brightness etc) on it which could be interacted with without having to login, that might be another option.
If this was possible, I’d want to limit the max temperature that the heating could be set to.

This automation for the heating I want specifically as I don’t want the heating left on when guests leave so the automation will turn it off after X hours

Did you ever figure out how to get this done? I’m wanting to do the exact same thing.

thanks.