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.
871
+
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:
875
+
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`.
878
+
879
+
-``trigger_type``isset to "mqtt"
880
+
-``webhook_id``isset to the webhook_id that was called.
881
+
-``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
+
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.
886
+
887
+
An simple example looks like
888
+
889
+
.. code:: python
890
+
891
+
@webhook_trigger("myid", kwargs={"extra": 10})
892
+
def webhook_test(webhook_data, extra):
893
+
log.info(f"It ran! {webhook_data}, {extra}")
894
+
895
+
which if called using the curl command `curl -X POST-d 'key1=xyz&key2=abc' hass_url/api/webhook/myid
0 commit comments