Struggling with variables for a mixed device automation

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

As configured, the function states() is being given a dictionary,

{"binary_sensor.pantry_door_is_open": "light.pantry_light",
 "binary_sensor.closet_door_is_open": "light.closet_light"}

… instead of what it expects, an entity ID like "light.closet_light".

You need to use the trigger variable to get the desired value from light

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_ent: "{{ light.get(trigger.entity_id) }}"
  - metadata: {}
    data: {}
    target:
      entity_id: "{{ light_ent }}"
    action: light.turn_{{ 'on' if is_state(light_ent, 'off') else 'off' }}
mode: parallel

Interesting, thanks!

I wonder if what I was sourcing from was just so old that recent changes to things maybe broke what I was referencing… it was from jan 2024 but maybe that was still too old.

In any case, many, many thanks for the guidance! This worked perfectly!