Automation Help: Stop/Start incoming HA Mobile App webhooks from mobile phones

My Home Assistant instance is behind an NGINX reverse proxy. as: https://hassio.mydomain.com

I have 4 Mobile Companion apps that sends lots of incoming data to HA via webhooks. When I do a full shutdown of Home Assistant Host or Restart Home Assistant Host, I noticed that NGINX gets bombarded with incoming failed attempts from these webhooks until I start up HA again.

The problem is that when I shutdown/restart Home Assistant Host, my NGINX reverse proxy gets bombarded with incoming mobile app webhooks. So, when Home Assistant starts up again, this queued-up traffic seems to interfere with Amazon Alexa cloud from connecting to Home Assistant via Nabu Casa on startup. The only way I can fix this is to re-login back into Nabu Casa or try to restart HA again (which sometimes works).

Below is my best attempt at mitigating this by creating an automation to stop incoming mobile app webhooks on shutdown/restart and turn them back on with another automation when HA starts back up. Unfortunately, it doesn’t seem like I’m doing it correctly.

Can someone please let me know what I’m doing wrong; and, suggest a solution that would work correctly. PS: And, no, I don’t want to reduce the polling rate or disable any sensors as a solution.

configuration.yaml

rest_command:
  disable_webhook_sm_g781v:
    url: "https://hooks.nabu.casa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb="
    method: POST
    headers: {Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxMjEzMzM3NzJkZjQ0Zjg0OWJiNmZkMGQyNDFlOTJjOCIsImlhdCI6MTU4NzgzNzIwMiwiZXhwIjoxOTAzMTk3MjAyfQ.iWy1Hbws1K8d7NPZdSTiqGe73QA2ojclFx-I1wppsWM", content_type: "application/json"}
    payload: '{"state": "off"}'
  disable_webhook_sm_g781v_2:
    url: "https://hooks.nabu.casa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb="
    method: POST
    headers: {Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxMjEzMzM3NzJkZjQ0Zjg0OWJiNmZkMGQyNDFlOTJjOCIsImlhdCI6MTU4NzgzNzIwMiwiZXhwIjoxOTAzMTk3MjAyfQ.iWy1Hbws1K8d7NPZdSTiqGe73QA2ojclFx-I1wppsWM", content_type: "application/json"}
    payload: '{"state": "off"}'
  disable_webhook_sm_t500:
    url: "https://hooks.nabu.casa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb="
    method: POST
    headers: {Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", content_type: "application/json"}
    payload: '{"state": "off"}'
  disable_webhook_sm_n960u:
    url: "https://hooks.nabu.casa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb="
    method: POST
    headers: {Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", content_type: "application/json"}
    payload: '{"state": "off"}'
  enable_webhook_sm_g781v:
    url: "https://hooks.nabu.casa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb="
    method: POST
    headers: {Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", content_type: "application/json"}
    payload: '{"state": "on"}'
  enable_webhook_sm_g781v_2:
    url: "https://hooks.nabu.casa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb="
    method: POST
    headers: {Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", content_type: "application/json"}
    payload: '{"state": "on"}'
  enable_webhook_sm_t500:
    url: "https://hooks.nabu.casa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb="
    method: POST
    headers: {Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", content_type: "application/json"}
    payload: '{"state": "on"}'
  enable_webhook_sm_n960u:
    url: "https://hooks.nabu.casa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb="
    method: POST
    headers: {Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", content_type: "application/json"}
    payload: '{"state": "on"}'

automations.yaml

- id: '1701248970838'
  alias: Disable Webhooks on Shutdown
  trigger:
  - platform: homeassistant
    event: shutdown
  action:
  - service: rest_command.disable_webhook_sm_g781v
  - service: rest_command.disable_webhook_sm_g781v_2
  - service: rest_command.disable_webhook_sm_t500
  - service: rest_command.disable_webhook_sm_n960u
- id: '1745248970851'
  alias: Enable Webhooks on Startup
  trigger:
  - platform: homeassistant
    event: start
  action:
  - service: rest_command.enable_webhook_sm_g781v
  - service: rest_command.enable_webhook_sm_g781v_2
  - service: rest_command.enable_webhook_sm_t500
  - service: rest_command.enable_webhook_sm_n960u