Help with my first own BP: Missing input definition error

Hi,
now that I’m finally rolling out home assistant in my flat, i wanted to create a BP on my own for my room lighting to learn how to use BPs properly.

But HA throws this error:

BP automation failed to set up.
Error:Invalid blueprint: Missing input definition for .

Below is what I currently have. What am I doing wrong here? AI models are not much of a help.

#####################################################################
# Blueprint: Motion-based lighting with sun, time and lux
# Author: HrHauptfeld
# Version: 2025.10.18
# Description: Motion-based automation for lights with customizable
# colors, brightness and illuminance control
#####################################################################

blueprint:
  name: "Motion-based Lighting Automation with sun, time and lux"
  description: |
    # ⭐ Motion-based Lighting Automation ⭐
    Turn lights on/off based on motion, time, sun position, and illuminance.  
    Fully customizable colors and brightness for different periods of the day.

    **Version:** 2025.10.18  
    **Help:** [Home Assistant Community](https://community.home-assistant.io/)  

    <details>
    <summary><strong>Features Overview</strong></summary>

    ✅ Motion sensor triggers for automatic lighting  
    ✅ Day, Late Day, and Night color and brightness customization  
    ✅ Optional illuminance-based control  
    ✅ Structured UI with collapsible feature sections  
    ✅ Flexible timing: choose fixed times or sun state  

    </details>

  domain: automation
  input:
    motion_sensor:
      name: "Motion sensor"
      description: "Select the motion sensor that triggers the lights."
      selector:
        entity:
          domain: binary_sensor

    light_target:
      name: "Target light"
      selector:
        target:
          entity:
            domain: light

    #########################################################
    # Motion & Light Control (Feature Section)
    #########################################################
    feature_section:
      name: "⚙️ Motion & Light Control"
      icon: mdi:motion-sensor
      collapsed: true
      description: |
        <details>
        <summary><strong>How Motion & Light Control Works</strong></summary>

        - When motion is detected, the lights turn on immediately.  
        - After motion stops, lights turn off after the specified delay.  
        - Use high-quality motion sensors to prevent false triggers.  
        - Combine multiple sensors with groups if needed.  
        - Ensure the lights you select support brightness and color if you plan to customize them.

        </details>
      input:
        motion_off_delay:
          name: "Motion off delay"
          description: "Delay before turning off lights after no motion."
          default:
            minutes: 2
            seconds: 2
          selector:
            duration: {}

    #########################################################
    # Sun & Time Settings (Feature Section)
    #########################################################
    sunTime_section:
      name: "☀️ Sun & Time Settings"
      icon: mdi:weather-sunset
      collapsed: true
      description: |
        <details>
        <summary><strong>Sun & Time Settings Guidance</strong></summary>

        - The day period defines when your "Daytime" color/brightness applies.   
        - Night is applied after sunset.  
        - Adjust these times to match your lifestyle or geographic location.  

        </details>
      input:
        time_mode:
          name: "Time mode"
          description: "Choose whether to use fixed times or sun entity for day/night separation."
          default: sun
          selector:
            select:
              options:
                - label: "Fixed times"
                  value: fixed
                - label: "Sun entity"
                  value: sun

        day_start:
          name: "Day start time"
          description: "ONLY works when 'Fixed times' are selected"
          default: "08:42:21"
          selector:
            time: {}

        day_end:
          name: "Day end time"
          description: "Always works (for evening lights)"
          default: "16:21:16"
          selector:
            time: {}

    #########################################################
    # Illuminance Control (Feature Section)
    #########################################################
    illuminance_section:
      name: "💡 Illuminance Control (optional)"
      icon: mdi:brightness-6
      collapsed: true
      description: |
        <details>
        <summary><strong>Illuminance Control Guidance</strong></summary>

        - Lights will only turn on if the measured illuminance is below this threshold. 
        - Leave the sensor empty if you want lights to always respond to motion.  

        </details>
      input:
        illuminance_sensor:
          name: "Illuminance sensor (optional)"
          description: "Optional sensor to prevent unnecessary lighting."
          default: []
          selector:
            entity:
              domain: sensor
              device_class: illuminance

        illuminance_threshold:
          name: "Illuminance threshold"
          description: "ONLY works with a light sensor selected (duh!)"
          default: 1221
          selector:
            number:
              min: 0
              max: 5000
              unit_of_measurement: lx
              mode: box

    #########################################################
    # Color & Brightness Customization (Feature Section)
    #########################################################
    color_section:
      name: "🎨 Light Colors & Brightness"
      icon: mdi:lightbulb
      collapsed: true
      description: |
        <details>
        <summary><strong>Color & Brightness Guidance</strong></summary>

        - Day, Late Day, and Night periods each have configurable colors and brightness.  
        - Use soft colors at night to reduce glare and preserve circadian rhythm.  
        - Bright whites are ideal for daytime work areas.  
        - Adjust sliders to suit your preference or room type.  

        </details>
      input:
        day_color:
          name: "Daytime color"
          description: "RGB color for daytime lighting."
          default: [255, 244, 229]
          selector:
            color_rgb: {}

        day_brightness:
          name: "Daytime brightness"
          description: "Brightness percentage for daytime lighting."
          default: 77
          selector:
            number:
              min: 1
              max: 100
              unit_of_measurement: "%"
              mode: slider

        late_color:
          name: "Evening color"
          description: "RGB color for evening lighting."
          default: [8, 169, 232]
          selector:
            color_rgb: {}

        late_brightness:
          name: "Evening brightness"
          description: "Brightness percentage for evening lighting."
          default: 88
          selector:
            number:
              min: 1
              max: 100
              unit_of_measurement: "%"
              mode: slider

        night_color:
          name: "Nighttime color"
          description: "RGB color for night lighting."
          default: [255, 0, 0]
          selector:
            color_rgb: {}

        night_brightness:
          name: "Nighttime brightness"
          description: "Brightness percentage for night lighting."
          default: 42
          selector:
            number:
              min: 1
              max: 100
              unit_of_measurement: "%"
              mode: slider

mode: restart
max_exceeded: silent

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

  - platform: state
    entity_id: !input motion_sensor
    to: "off"
    for: !input motion_off_delay

condition: []

action:
  - choose:
      # --- Motion detected ---
      - conditions:
          - condition: state
            entity_id: !input motion_sensor
            state: "on"
        sequence:
          - choose:
              # --- Daytime (fixed times) ---
              - conditions:
                  - condition: template
                    value_template: >
                      {{ input('time_mode') == 'fixed' }}
                  - condition: time
                    after: !input day_start
                    before: !input day_end
                sequence:
                  - choose:
                      - conditions:
                          - condition: template
                            value_template: >
                              {{ (input('illuminance_sensor') != none)
                                and (states(input('illuminance_sensor'))|int(99999) <= input('illuminance_threshold')|int)
                                or (input('illuminance_sensor') == none) }}
                        sequence:
                          - service: light.turn_on
                            target: !input light_target
                          - delay: "00:00:01"
                          - service: light.turn_on
                            target: !input light_target
                            data:
                              transition: 1
                              rgb_color: !input day_color
                              brightness_pct: !input day_brightness
                          - service: logbook.log
                            data:
                              name: "Motion Lighting"
                              message: "Day branch triggered"

              # --- Daytime (sun above horizon) ---
              - conditions:
                  - condition: template
                    value_template: >
                      {{ input('time_mode') == 'sun' }}
                  - condition: state
                    entity_id: sun.sun
                    state: "above_horizon"
                sequence:
                  - choose:
                      - conditions:
                          - condition: template
                            value_template: >
                              {{ (input('illuminance_sensor') != none)
                                and (states(input('illuminance_sensor'))|int(99999) <= input('illuminance_threshold')|int)
                                or (input('illuminance_sensor') == none) }}
                        sequence:
                          - service: light.turn_on
                            target: !input light_target
                          - delay: "00:00:01"
                          - service: light.turn_on
                            target: !input light_target
                            data:
                              transition: 1
                              rgb_color: !input day_color
                              brightness_pct: !input day_brightness
                          - service: logbook.log
                            data:
                              name: "Motion Lighting"
                              message: "Day branch triggered"

              # --- Evening (after day_end until sunset) ---
              - conditions:
                  - condition: template
                    value_template: >
                      {{ input('time_mode') == 'fixed' }}
                  - condition: time
                    after: !input day_end
                  - condition: state
                    entity_id: sun.sun
                    state: "above_horizon"
                sequence:
                  - service: light.turn_on
                    target: !input light_target
                  - delay: "00:00:01"
                  - service: light.turn_on
                    target: !input light_target
                    data:
                      transition: 1
                      rgb_color: !input late_color
                      brightness_pct: !input late_brightness
                  - service: logbook.log
                    data:
                      name: "Motion Lighting"
                      message: "Late Day branch triggered"

              # --- Nighttime (sun below horizon) ---
              - conditions:
                  - condition: state
                    entity_id: sun.sun
                    state: "below_horizon"
                sequence:
                  - service: light.turn_on
                    target: !input light_target
                  - delay: "00:00:01"
                  - service: light.turn_on
                    target: !input light_target
                    data:
                      transition: 1
                      rgb_color: !input night_color
                      brightness_pct: !input night_brightness
                  - service: logbook.log
                    data:
                      name: "Motion Lighting"
                      message: "Night branch triggered"

      # --- Motion cleared (turn lights off after delay) ---
      - conditions:
          - condition: state
            entity_id: !input motion_sensor
            state: "off"
        sequence:
          - service: light.turn_off
            target: !input

It just ends with this, was there supposed to be more? !input by itself is invalid.

1 Like

whoops! yeah it should be: target: !input light_target
nothing beats another another set of human eyes.

now HA stopped throwing an error for it. Thanks m8! would have been so much easier if HA would have provided a line number like for other errors :slight_smile:

now the conditions just have to work. in the traces section im getting an undefined error for the first three conditions.

I have never seen input() existing as a template function before. Did you just make that up or is it referenced somewhere?

1 Like

ok got it. Making blueprints is so much more complicated than making automations via the UI.

I added variables to the BP, adjusted the jinja code and now all works as expected. Thanks for the help guys!

variables:
  time_mode: !input time_mode
  day_start: !input day_start
  day_end: !input day_end
  illuminance_sensor: !input illuminance_sensor
  illuminance_threshold: !input illuminance_threshold
  light_target: !input light_target
  day_color: !input day_color
  day_brightness: !input day_brightness
  late_color: !input late_color
  late_brightness: !input late_brightness
  night_color: !input night_color
  night_brightness: !input night_brightness

I’m not sure what you are doing there, but you copied 4 input: sections out of your LLM into that and the indentation is all over the place.
I’m shocked that it compiles all.

Friends don’t let friends use LLM to write code…
So the right way to write a Blueprint, (well let’s call it best practice and the method suggested in the docs), is to write an automation or script that does a simplified version of that you want first, then add the blueprint magic sauce. Getting the logic working is not always easy, and becomes obfuscated in all that variable substitution stuff, making everything frustrating.
Get what you want working with sample entities instead of !inputs, then make the blueprint out of that by adding the !inputs and variables and such. Try to avoid device triggers and selectors. You can make them work, but people tend to struggle with those when dealing with them outside of the GUI editor context.