Help with my first blueprint and variables

Hi all,

I have the next simple blueprint:

blueprint:
  name: Configure ZBMINIR2 detached relay mode
  description: Configure ZBMINIR2 detached relay mode.
  domain: automation
  author: 
  homeassistant:
    min_version: 2022.4.0

  input:
    zbminir2_device:
      name: ZBMINIR2 device
      selector:
        device:
          filter:
            manufacturer: SONOFF
            model: Zigbee smart switch (ZBMINIR2)
          multiple: false

    controlled_light:
      name: Toggle target lights
      description: The switch will toggle these lights.
      selector:
        entity:
          filter:
            domain: light
          multiple: false

triggers:
  - domain: mqtt
    device_id: !input 'zbminir2_device'
    type: action
    subtype: toggle
    trigger: device

variables:
  zbminir2_device: !input 'zbminir2_device'
  zbminir2_switch: "switch.{{ device_attr(zbminir2_device, 'name') | slugify }}"

actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: '{{ zbminir2_switch }}'
            state: "off"
        sequence:
          - type: turn_on
            device_id: '{{ zbminir2_device }}'
            domain: switch
      - conditions:
          - condition: state
            entity_id: '{{ zbminir2_switch }}'
            state: "on"
        sequence:
          - action: light.toggle
            metadata: {}
            data: {}
            target:
              entity_id: !input 'controlled_light'

mode: single

But I am not able to use the variables and I get the following error:

Message malformed: Entity {{ zbminir2_switch }} is neither a valid entity ID nor a valid UUID for dictionary value @ data['actions'][0]['choose'][0]['conditions'][0]['entity_id']

Surely it is a problem of not understanding how variables work, do you know of any specific documentation on where and how to use variables?

thanks for everything

You can’t use templates in every field. Most fields do not allow templates. So if you want to use those variables, you need to use template conditions.

thanks @petro this is the working blueprint:

blueprint:
  name: Configure ZBMINIR2 detached relay mode
  description: Configure ZBMINIR2 detached relay mode.
  domain: automation
  author: [email protected]
  homeassistant:
    min_version: 2022.4.0

  input:
    zbminir2_device:
      name: ZBMINIR2 device
      selector:
        device:
          filter:
            manufacturer: SONOFF
            model: Zigbee smart switch (ZBMINIR2)
          multiple: false

    controlled_light:
      name: Toggle target lights
      description: The switch will toggle these lights.
      selector:
        entity:
          filter:
            domain: light
          multiple: false

triggers:
  - domain: mqtt
    device_id: !input 'zbminir2_device'
    type: action
    subtype: toggle
    trigger: device

variables:
  zbminir2_device: !input 'zbminir2_device'
  zbminir2_switch: "{{ device_entities(zbminir2_device)[0] }}"

actions:
  - choose:
      - conditions:
          - alias: "ZBMINIR2 switch is OFF"
            condition: template
            value_template: "{{ states(zbminir2_switch) == 'off' }}"
        sequence:
          - service: switch.turn_on
            data:
              entity_id: '{{ zbminir2_switch }}'
      - conditions:
          - alias: "ZBMINIR2 switch is ON"
            condition: template
            value_template: "{{ states(zbminir2_switch) == 'on' }}"
        sequence:
          - action: light.toggle
            metadata: {}
            data: {}
            target:
              entity_id: !input 'controlled_light'

mode: single