Target selectors non-deterministic or broken?

I’m about to throw away all my electronics and go live in a cave without lights…
Why on earth are blueprints always broken?

I have one working blueprint using target selectors and actions like this:

input:
  light:
    name: Light(s)
    description: The light(s) to control
    selector:
      target:
        entity:
          domain: light

action:
- service: light.turn_on
  target: !input light
  data:
    transition: 1

But then I have another blueprint with this config

input:
  target_light:
    name: Light (day)
    description: The light to turn on during the day
    selector:
      target:
        entity:
          domain: light
action:
- service: light.turn_on
  target: !input target_light
  data:
    transition: 1

And this one is constantly giving me this when instantiated as automation
Blueprint Z2M - Motion lights generated invalid automation with inputs OrderedDict([('sensor', 'binary_sensor.liiketunnistin_kaytava_occupancy'), ('target_light', OrderedDict([('device_id', 'e01956804983fd3282a532f77b28a8f1')]))]): required key not provided @ data['device_id']. Got None

Any idea what I’m doing wrong here? I have no problems creating automations by copypasting YAML or Duplicating in the UI, but with blueprints I always end up sitting in the dark after hours of debugging.

This is the full blueprint I’m trying to debug after throwing away most of it

blueprint:
  name: Z2M - Motion lights
  description: Motion sensor triggered lights with night mode
  domain: automation
  input:
    sensor:
      name: Motion sensor to use
      description: Something something binary_sensor
      selector:
        entity:
          integration: mqtt
          domain: binary_sensor
          device_class: motion
    target_light:
      name: Light (day)
      description: The light to turn on during the day
      selector:
        target:
          entity:
            domain: light

trigger:
- type: motion
  platform: device
  entity_id: !input sensor
  domain: binary_sensor

action:
- service: light.turn_on
  target: !input target_light

Why have you limited the binary sensor to “integration: mqtt”? (I just would have thought it easier to any device_class: motion).
Anyway I don’t have any experience playing around with mqtt (I want to tho). But maybe this will solve your problem?

blueprint:
  name: Z2M - Motion lights
  description: Motion sensor triggered lights with night mode
  domain: automation

  input:
    sensor:
      name: Motion sensor to use
      description: Something something binary_sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion

    target_light:
      name: Light (day)
      description: The light to turn on during the day
      selector:
        target:
          entity:
            domain: light

trigger:
  - platform: state
    entity_id: !input sensor
    to: "on"

action:
  - service: light.turn_on
    target: !input target_light

Use the Studio Code Server Integration, (if you don’t already) it makes finding bugs easier.