Unknown entity when using a variable entity_id in blueprint

I’m trying to build a blueprint that given an input device will find a specific entity_id under that device and use it in an action. With all the other (hopefully) unrelated stuff the blueprint boils down to:

blueprint:
  name: My Super Awesome Blueprint
  domain: automation

  input:
    fully_kiosk_device:
      name: Fully Kiosk Device
      selector:
        device:
          filter:
            - integration: fully_kiosk

variables:
  fully_kiosk_device: !input fully_kiosk_device
  fully_kiosk_screen_entity_id: "{{ device_entities(fully_kiosk_device) | select('search','^switch\\.(.+)_screen$') | first }}"

trigger:
  - platform: sun
    event: sunrise
    offset: 0

action:
  - type: turn_on
    device_id: !input fully_kiosk_device
    entity_id: "{{ fully_kiosk_screen_entity_id }}"
    domain: switch

However this results in the error:

Message malformed: Unknown entity ‘{{ fully_kiosk_screen_entity_id }}

Replacing the action with a log message it seems to log the correct entity_id so it’s not that it has the wrong id/no id.

Is there any way to get around this other than adding another input for the screen entity?

If nothing else will work I’ll just add the input but that’s mildly annoying and I’m all about wasting hours of time to eleminate mild annoyances (mostly sarcasm…)

Have you tested in developer template what that variable renders as? it it what you are looking for?

I did, using the device ID for my device i get back: switch.name_screen

The output of a template like that is a string. You need to convert that to an entity.
Someone correct me if I’m wrong but I think that is the expand command…

I’ve only used it once so I don’t really remember…

Found this, maybe would help
https://github.com/thejeffreystone/SlackerLabVideoExamples/blob/cc2bf6a96fc933d7bd8975c8eebbbb0674d4cf3a/2023-MasterTemplates_StateBasedEntities/template.yaml#L107.

I quickly tried throwing expand in the template and same thing. In my attempt to Google something else I came across this post where petro mentions that:

You can’t use a template in the entity_id field for a state condition.

Which I thought was conclusive but later in the same there is this link that shows an example that is very similar to what I’m trying.

Maybe you can’t do it in blueprints? I’m a bit confused

Automation blueprints are automations, so no. It’s syntax or something somewhere.

I ended up recreating what I expected the blueprint to generate as an automation and ended up with the same behaviour. After some experimentation it seems like you can’t use variables for entities like that, probably because the validation is trying to validate an actual entity id. In the link I posted previously that is specifically for a service call. I decided to change my blueprint to use a service call with the variables and it works now. A bit unituitive as a blueprint noob but happy it works.
The final working solution:

blueprint:
  name: My Super Awesome Blueprint
  domain: automation

  input:
    fully_kiosk_device:
      name: Fully Kiosk Device
      selector:
        device:
          filter:
            - integration: fully_kiosk

variables:
  fully_kiosk_device: !input fully_kiosk_device
  fully_kiosk_screen_entity_id: "{{ device_entities(fully_kiosk_device) | select('search','^switch\\.(.+)_screen$') | first }}"

trigger:
  - platform: sun
    event: sunrise
    offset: 0

action:
  - service: switch.turn_on
    target:
      entity_id: "{{ fully_kiosk_screen_entity_id }}"