Can't get two automations triggered by the same webhook (only one gets triggered)

Hi, everyone! Thought I’d ask community for help on this one :slight_smile:

I’ve been working on a project recently that would check on a Front Gate/Garage door status to decide if to proceed with an open/close command. The logic is as follows:

I would call respective webhooks “entrance_open” and “entrance_close” using iOS Siri Shortcuts that perform a “Get contents of URL” with POST method in JSON format (this works for all of my other automations). The webhooks would then trigger two automations each:

“entrance_open” webhook triggers “Front Gate Conditional Open” automation and “Garage Door Conditional Open” automation.

“entrance_close” webhook triggers “Front Gate Conditional Close” automation and “Garage Door Conditional Close” automation.

The automations are as follows:

  1. Front Gate Conditional Open
- id: '1595439065549'
  alias: Front Gate Conditional Open
  description: ''
  trigger:
  - platform: webhook
    webhook_id: entrance_open
  condition:
  - condition: state
    entity_id: cover.front_gate
    state: closed
  action:
  - data: {}
    entity_id: switch.sonoff_100097deca
    service: switch.toggle
  1. Garage Door Conditional Open
- id: '1595439708923'
  alias: Garage Door Conditional Open
  description: ''
  trigger:
  - platform: webhook
    webhook_id: entrance_open
  condition:
  - condition: state
    entity_id: cover.garage_door
    state: closed
  action:
  - data: {}
    entity_id: switch.sonoff_100097dbf9
    service: switch.toggle
  1. Front Gate Conditional Close
- id: '1595439971816'
  alias: Front Gate Conditional Close
  description: ''
  trigger:
  - platform: webhook
    webhook_id: entrance_close
  condition:
  - condition: state
    entity_id: cover.front_gate
    state: open
  action:
  - data: {}
    entity_id: switch.sonoff_100097deca
    service: switch.toggle
  1. Garage Door Conditional Close
- id: '1595440049391'
  alias: Garage Door Conditional Close
  description: ''
  trigger:
  - platform: webhook
    webhook_id: entrance_close
  condition:
  - condition: state
    entity_id: cover.garage_door
    state: open
  action:
  - data: {}
    entity_id: switch.sonoff_100097dbf9
    service: switch.toggle

These 4 automations check the status of Garage Door/Front Gate before toggling an open/close/stop switches (essentially dumb switches that perform the next logical command for the Garage Door/Front Gate). If the Front Gate or Garage Door is already open, it won’t open it anymore, and vice-versa for closing.

The intended effect of this is to avoid situations when I’m coming home by car but garage door is already open, leading to my Siri Shortcut closing it instead.

However, I’ve run into an issue with triggering multiple automations with a single webhook. The problem is that calling the webhook would trigger only one of the two automations, but not the other (somehow it always works for Front Gate, but not for the Garage Door).

I’ve checked the following:

  • Syntax appears to be correct and identical (minus variables) for Front Gate and Garage Door automations.
  • States of both “cover.garage_door” and “cover.front_gate” are reported as “open” or “closed” correctly and aren’t “unavailable” (MQTT binary switches).
  • Automations work when triggered manually one-by-one without an issue (ignoring the condition of course).

Is there a limit on the number of automations a webhook can trigger, am I doing something wrong, or is there a more elegant solution to this (e.g. scripts, which I haven’t gotten around to figuring out yet)? I’d like to stick to webhook as a trigger (avoids weird “I have toggled…” Siri responses), and to maintain a single-URL on the iOS Siri Shortcut side (multiple “get contents of URL” actions tend to fail with Siri Shortcuts).

Thanks in advance for your advise on this!

Same problem here.
I used the gui to create an automation.

I create an automation with a webhook id. No problem.

I create a second automation with the same webhook id.
As a save the automation it’s gone. I created a second automation with another webhook id. No problem.

As soon as i re-open the automation and change the webhook id to the already used one the automation is gone.

webhooks have an odd restriction for events. They only fire 1 automation. If you want to have a webhook fire multiple automations, you have to create an automation that fires a custom event. Then make your other automations work off the custom event. There is a feature request to make webhooks fire more than one automation. Go vote for it!

Until then, you’ll have to stick with the work around.

- alias: Webhook Handler
  trigger:
  - platform: webhook
    webhook_id: entrance_close
  action:
  - event: handled_webhook
    event_data_template:
      id: "{{ <USE TRIGGER OBJECT HERE> }}"

I currently don’t have the means to help you create the template. If you subscribe to the webhook event in the devtools -> event page and paste the result here, I can help you create the template.

1 Like

The only possible cause of my problem was the installation of browser-mod. It also broke my auto-entities setup.
Romoved it and all the lost automations reapeared. :slight_smile:

What’s the need for templated event data? Why not just fire a custom, hard-coded event for open in the one automation, and another custom, hard-coded event for close?

Or…

You can use the choose action (new in 0.113) to solve this problem:

- id: '1595439065549'
  alias: Front Gate / Garage Door Conditional Open
  description: ''
  trigger:
  - platform: webhook
    webhook_id: entrance_open
  action:
  # If front gate is closed, open it.
  - choose:
    - conditions:
      - condition: state
        entity_id: cover.front_gate
        state: closed
      sequence:
      - data: {}
        entity_id: switch.sonoff_100097deca
        service: switch.toggle
  # If garage door is closed, open it
  - choose
    - conditions:
      - condition: state
        entity_id: cover.garage_door
        state: closed
      sequence:
      - data: {}
        entity_id: switch.sonoff_100097dbf9
        service: switch.toggle

And do the same thing for close.

Also, even before 0.113, you could have used @petro’s suggestion, or even a template to determine entity_id to one switch.toggle call.

1 Like

I was trying to keep it dynamic, where he could add more webhook triggers and essentially just pass the events along.

2 Likes

Thanks @petro, @pnbruckner for your suggestions. I’ll play around with both! My temp solution before that was to move Conditional Open/Close logic into scripts instead of automations, and have a webhook trigger one automation with two scripts.

@petro also voted for the feature request, thanks for sharing!