I set up my first automation within homeassistant and I am having trouble with how to enter the yaml part which includes a template. The problem ist just with the template part with the action, the rest already works.
When I enter the following action with everything hardcoded (no template), that works:
service: vacuum.send_command
data:
entity_id: vacuum.rob
command: start
params:
pmap_id: 12345
regions:
- region_id: "3"
type: rid
user_pmapv_id: 12345
enabled: true
When I look at the trace of that action, I see the following:
params:
domain: vacuum
service: send_command
service_data:
entity_id: vacuum.rob
command: start
params:
pmap_id: 12345
regions:
- region_id: '3'
type: rid
user_pmapv_id: 12345
target: {}
running_script: false
limit: 10
So that is the goal I want to reach, but with a template and the region_id
and type
dependent on trigger.payload
. Using that variable from the trigger already works, but my problem lies in the formating of my yaml/template.
When I enter the following action as yaml, my action is executed, but the region part is not constructed proberly and the command is not understood by the entity:
service: vacuum.send_command
data_template:
entity_id: vacuum.rob
command: start
params:
pmap_id: 12345
regions: >
{% if trigger.payload == 'room_one' %}
- region_id: '3'
{% else %}
- region_id: '999'
{%- endif -%}
type: {{ 'zid' if trigger.payload == 'zone_not_room' else 'rid' }}
user_pmapv_id: 12345
enabled: true
In the trace I see (when trigering with trigger.payload == room_one):
params:
domain: vacuum
service: send_command
service_data:
entity_id: vacuum.rob
command: start
params:
pmap_id: 12345
regions: |-
- region_id: '3'
type: rid
user_pmapv_id: 12345
target: {}
running_script: false
limit: 10
So that >
gets turned into |-
and I am not sure why and why I need the >
at all (saw it in some examples). This is probably just something small but I can’t figure it out. Thanks fort helping.