From 72062aa3dec48e2f0c9c83fbb49bbb29c84c9942 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Mon, 4 Sep 2023 09:35:57 -0700 Subject: [PATCH] Add template entity script action documentation (#28768) * Add template entity script action documentation * Update source/_integrations/template.markdown Co-authored-by: Erik Montnemery * Focus action explanation on variables avaiable in templates * Remove whitespace * tiny tweak --------- Co-authored-by: Erik Montnemery Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com> --- source/_integrations/template.markdown | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/source/_integrations/template.markdown b/source/_integrations/template.markdown index caab7a606b2..153eee1a261 100644 --- a/source/_integrations/template.markdown +++ b/source/_integrations/template.markdown @@ -112,6 +112,10 @@ unique_id: description: The unique ID for this config block. This will be prefixed to all unique IDs of all entities in this block. required: false type: string +action: + description: Define actions to be executed when the trigger fires. Optional. Variables set by the action script are available when evaluating entity templates. This can be used to interact with anything via services, in particular services with [response data](/docs/scripts/service-calls#use-templates-to-handle-response-data). [See action documentation](/docs/automation/action). + required: false + type: list sensor: description: List of sensors required: true @@ -660,6 +664,36 @@ template: {% endraw %} +### Trigger based handling of service response data + +This example demonstrates how to use an `action` to call a [service with response data](/docs/scripts/service-calls/#use-templates-to-handle-response-data) +and use the response in a template. + +{% raw %} + +```yaml +template: + - trigger: + - platform: time_pattern + hours: /1 + action: + - service: weather.get_forecast + data: + type: hourly + target: + entity_id: weather.home + response_variable: hourly + sensor: + - name: Weather Forecast Hourly + unique_id: weather_forecast_hourly + state: "{{ now().isoformat() }}" + attributes: + forecast: "{{ hourly.forecast }}" +``` + +{% endraw %} + + ## Legacy binary sensor configuration format _This format still works but is no longer recommended. [Use modern configuration](#configuration-variables)._