I have just combined several automations into one:
- alias: "Handle Color Cards"
id: handle_colorcards
mode: single
max_exceeded: silent
variables:
# Map tag ID to content
tags:
f36a212d-5d8a-4d0e-8f96-xxxxxxxxxxx:
alias: red
service: light.turn_on
data:
hs_color:
- 0
- 100
transition: 1
2841c96f-aff7-4905-8ec0-xxxxxxxxxxx:
alias: orange
service: light.turn_on
data:
hs_color:
- 30
- 100
transition: 1
3c92bafa-205f-461c-a45e-xxxxxxxxxxx:
alias: yellow
service: light.turn_on
data:
hs_color:
- 60
- 100
transition: 1
[... more variables...]
trigger:
platform: event
event_type: tag_scanned
condition:
- "{{ trigger.event.data.tag_id in tags }}"
action:
- variables:
tag_service: "{{tags[trigger.event.data.tag_id].service }}"
tag_data: "{{tags[trigger.event.data.tag_id].data }}"
- service: "{{ tag_service }}"
target:
entity_id: light.hue_2_light
data: "{{ tag_data }}" <------ THIS IS THE ISSUE
I wonder how to further reduce the code by setting the transition centrally in the service data of the action block.
I have tried several approaches:
data: >
"{{ tag_data }}"
transition: 1
...
data: "{{ tag_data }}"
transition: 1
...
but they all give one of these errors:
Error rendering data template: Result is not a Dictionary
OR
expected a dictionary for dictionary value @ data['action'][0]['variables']. Got None extra keys not allowed @ data['action'][0]['tag_data']. Got None extra keys not allowed @ data['action'][0]['tag_service']. Got None.
How do I combine / merge / join / mix a template with a mapping?
All help appreciated in advance