You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
``@webhook_trigger`` listens for calls to a `Home Assistant webhook <https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger>`__
868
-
at `your_hass_url/api/webhook/webhook_id`and triggers whenever a request is made at that endpoint.
869
-
Multiple ``@webhook_trigger`` decorators can be applied to a single function if you want
870
-
to trigger off different mqtt topics.
867
+
``@webhook_trigger`` listens for calls to a `Home Assistant webhook <https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger>`__ at ``your_hass_url/api/webhook/webhook_id`` and triggers whenever a request is made at that endpoint. Multiple ``@webhook_trigger`` decorators can be applied to a single function if you want to trigger off different webhook ids.
871
868
872
-
An optional ``str_expr`` can be used to match against payload message data, and the trigger will only occur
873
-
if that expression evaluates to ``True``or non-zero. This expression has available these four
874
-
variables:
869
+
Setting ``local_only`` option to ``False`` will allow request made from anywhere on the internet (as opposed to just on local network).
870
+
The methods option needs to be an listorsetwith elements ``GET``, ``HEAD``, ``POST``, or``PUT``.
875
871
876
-
Setting `local_only` option to `False` will allow request made from anywhere on the internet (as opposed to just locally).
877
-
The methods option needs to be an listorsetwith elements `GET`, `HEAD`, `POST`, or`PUT`.
872
+
An optional ``str_expr`` can be used to match against payload message data, and the trigger will only occur if that expression evaluates to ``True``or non-zero. This expression has available these three
873
+
variables:
878
874
879
-
-``trigger_type``isset to "mqtt"
875
+
-``trigger_type``isset to "webhook"
880
876
-``webhook_id``isset to the webhook_id that was called.
881
877
-``webhook_data``is the data/json that was sent in the request returned as a `MultiDictProxy <https://aiohttp-kxepal-test.readthedocs.io/en/latest/multidict.html#aiohttp.MultiDictProxy>`__ (ie a python dictionary that allows multiple of the same keys).
882
878
883
-
When the ``@webhook_trigger`` occurs, those same variables are passed as keyword arguments to the
884
-
function in case it needs them. Additional keyword parameters can be specified by setting the
885
-
optional ``kwargs`` argument to a ``dict``with the keywords and values.
879
+
When the ``@webhook_trigger`` occurs, those same variables are passed as keyword arguments to the function in case it needs them. Additional keyword parameters can be specified by setting the optional ``kwargs`` argument to a ``dict``with the keywords and values.
886
880
887
881
An simple example looks like
888
882
@@ -892,9 +886,7 @@ An simple example looks like
892
886
def webhook_test(webhook_data, extra):
893
887
log.info(f"It ran! {webhook_data}, {extra}")
894
888
895
-
which if called using the curl command `curl -X POST-d 'key1=xyz&key2=abc' hass_url/api/webhook/myid
which if called using the curl command ``curl -X POST-d 'key1=xyz&key2=abc' hass_url/api/webhook/myid`` outputs ``It ran! <MultiDictProxy('key1': 'xyz', 'key2': 'abc')>, 10``
898
890
899
891
Other Function Decorators
900
892
-------------------------
@@ -1352,9 +1344,7 @@ It takes the following keyword arguments (all are optional):
1352
1344
-``mqtt_trigger=None`` can be set to a string orlist of two strings, just like
1353
1345
``@mqtt_trigger``. The first string is the MQTT topic, and the second string
1354
1346
(when the setting is a two-element list) is an expression based on the message variables.
1355
-
-``webhook_trigger=None`` can be set to a string orlist of two strings, just like
1356
-
``@webhook_trigger``. The first string is the webhook id, and the second string
1357
-
(when the setting is a two-element list) is an expression based on the message variables.
1347
+
-``webhook_trigger=None`` can be set to a string orlist of two strings, just like ``@webhook_trigger``. The first string is the webhook id, and the second string (when the setting is a two-element list) is an expression based on the message variables.
1358
1348
-``webhook_local_only=True``is used with``webhook_trigger`` to specify whether to only allow
1359
1349
local webhooks.
1360
1350
-``webhook_methods={"POST", "PUT"}``is used with``webhook_trigger`` to specify allowed webhook
0 commit comments