So, I’m trying to create an automation that when a certain door sense opens, certain lights turn on (and off). I wanted to make an auto that can handle multiple device pairs for future reusability, to avoid having a half dozen identical automations for each door/light pair.
However, I am struggling with the example I found from someone else, as I am getting errors about the variable at runtime: Error executing script. Error rendering template for variables at pos 1: TypeError: unhashable type: 'dict'
Here is my full automation yaml, I would love any feedback on what I did wrong to make it trip over the variable name (at least, that’s what I presume is happening). (Also I admit in advance I might have my on/offs reversed, I never got this working, so I wasn’t able to test/debug the actual logic of when to turn on or off, lol)
alias: Auto Light Triggers
description: multi-device automation for single-trigger lights
triggers:
- entity_id:
- binary_sensor.pantry_door_is_open
- binary_sensor.closet_door_is_open
variables:
light:
binary_sensor.pantry_door_is_open: light.pantry_light
binary_sensor.closet_door_is_open: light.closet_light
trigger: state
actions:
- variables:
light_state: "{{ states(light) }}"
- choose:
- conditions:
- condition: template
value_template: "{{ light_state == 'off' }}"
sequence:
- metadata: {}
data: {}
target:
entity_id: "{{ light }}"
action: light.turn_on
- conditions:
- condition: template
value_template: "{{ light_state == 'on' }}"
sequence:
- metadata: {}
data: {}
target:
entity_id: "{{ light }}"
action: light.turn_off
mode: parallel