I’m trying to define static maps in my trigger_variables that I can use to look things up in my automation actions. Here’s a broken minimal example of the kind of thing I’m trying to do:
When I try to save this, unfortunately, I get an error about “extra keys not allowed @ data['trigger_variables']”. I know I can do things with choose, but I have automations with multiple parameters, some derived from the triggering entity, some derived from, say, the trigger ID or the trigger ID mod the number of actions per device.
Is there any way to define automation-wide maps that can then be consulted in multiple actions?
Thanks. It looks like I just indented trigger_variables too much. It works with either variables or trigger_variables. I assume the latter is preferable when I don’t ever expect the value to change. In fact, this seems to be legal syntax as well:
Based on the results of my tests, the value of trigger.idx is a string. So if you want to use it to match a dictionary key, ideally the key should be a string.
alias: Trigger Variables 1
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.test
to: "on"
condition: []
action:
- service: notify.persistent_notification
data:
message: "{{ door.get(trigger.idx, 'none') }}"
title: TV 1
mode: single
trigger_variables:
door:
"0": switch.front_door
"1": switch.back_door
It effectively changed the type of the keys from integer to string. It’s just one of Automation Editor’s quirks that can interfere with one’s ability to create more advanced automations (and a reason why I don’t use it).