Blueprint : optional Input

Hello Everybody,

I try to create my first blueprint for control my radiators.

One in with climate and other with light (qubino)

I put in input this :

input:
    climate_target:
      name: xxxxxxxxxxxxxx
      description: xxxxxxxxxxxxxxxxxxxxx
      selector:
        entity:
          domain: climate
    is_fil_pilote:
      name: xxxxxxxxxxxxxxxxxxxxxxxx
      description: xxxxxxxxxxxxxxxxxxxxxxx
      default: false
      selector:
        boolean:
    
   # heater qubino
    heater_wire:
      name: xxxxxxxxxxxxxxxxxxx
      description: xxxxxxxxxxxxxxxxxxxxx 
      selector:
        entity:
          domain: light

Then for me the input climate_target is optional if i toggle is_fil_pilote and choose the input heater_wire.

But when i want to save my automation depending of this blueprint, i have this error :

Missing imput climate_target

But i dont need it in the case i choose a qubino heater.

Is anybody has an idea to workaround please?
I found with an input like this

input:
  climate_target:
   name: climate
   default: climate.default

But i m not sure that the great solution.

The default can be an empty dict:
default: {}

I used this for a light. The choose ensure you only call the service if it’s not empty/None

blueprint:
  input:
    light_target:
      name: Light
      default: {}
      selector:
        target:
          entity:
            domain: light

variables:
  light_target: !input light_target

action:
  - choose:
      - conditions: "{{ light_target }}"
        sequence:
          - service: homeassistant.turn_off
            target: !input light_target
2 Likes

That didn’t work for me!
Do you guys know what’s wrong with my blueprint?

Are you sure you need the wait_for_trigger? It might already be off by the time the script runs? (It all async and NOT guaranteed to run immediately)

The light will turn off just after the wait_for_trigger. That’s part is okey. The problem are the conditions

- conditions: "{{ switch_target }}"
Doesn’t work.

Ok. Just found the solution.

Doesn’t work because condititions is wating for true or false. the template "{{ light_target }}" renders a dictionary (empty if the entity is not selected).

- conditions: "{{ light_target|length > 0 }}" does the trick in this case.

That’s a working blueprint that turns the light(s) ON whenever motion is detected.

blueprint:
  name: Motion Light ON (revisado)
  description: Turn light(s) ON when motion is detected and OFF when there is no motion.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    switch_target:
      name: (Optional) Switch
      default: {}
      selector:
        target:
          entity:
            domain: switch
    light_target:
      name: (Optional) Light
      default: {}
      selector:
        target:
          entity:
            domain: light
    no_motion_wait:
      name: Wait time
      description: "Time to leave the light on after motion sensor changes to 'clear' (off)."
      default: 30
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

# If motion is detected while automation is running, script will restart.
mode: restart

trigger:
  platform: state
  entity_id: !input motion_entity
  to: "on"

variables:
  light_target: !input light_target
  switch_target: !input switch_target

action:
  - choose:
      - conditions: "{{ light_target|length > 0 and switch_target|length > 0 }}"
        sequence:
          - service: switch.turn_on
            target: !input switch_target
          - service: light.turn_on
            target: !input light_target
          - wait_for_trigger:
              - platform: state
                entity_id: !input motion_entity
                to: 'off'
          - delay: !input no_motion_wait
          - service: switch.turn_off
            target: !input switch_target
          - service: light.turn_off
            target: !input light_target
      - conditions: "{{ switch_target|length > 0 }}"
        sequence:
          - service: switch.turn_on
            target: !input switch_target
          - wait_for_trigger:
              - platform: state
                entity_id: !input motion_entity
                to: 'off'
          - delay: !input no_motion_wait
          - service: switch.turn_off
            target: !input switch_target
      - conditions: "{{ light_target|length > 0 }}"
        sequence:
          - service: light.turn_on
            target: !input light_target
          - wait_for_trigger:
              - platform: state
                entity_id: !input motion_entity
                to: 'off'
          - delay: !input no_motion_wait
          - service: light.turn_off
            target: !input light_target
    default: []
1 Like

Indeed, seems like it did not like the falsy value and what I did in the end seems to be a double not

  - choose:
    - conditions:
      - "{{ not not light_target }}"

For reference this was mine that backed off due to repeat movements:

blueprint:
  name: Alarm Zone Automations
  description: Translate a binary_sensor alarm zone to an input number value. Optionally switch lights
  domain: automation
  # source_url: https://github.com/home-assistant/core/blob/40c727df6663f6c6a9e6509e1771b3fe19acb079/homeassistant/components/automation/blueprints/motion_light.yaml
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    input_number_entity:
      name: Input Number
      selector:
        entity:
          domain: input_number
    light_target:
      name: Light
      default: {}
      selector:
        target:
          entity:
            domain: light
    no_motion_t1:
      name: Wait time
      description: Initial time.
      default: 60
      selector:
        number:
          min: 10
          max: 300
          unit_of_measurement: seconds
    no_motion_t2:
      name: Wait time
      description: Second wait time.
      default: 240
      selector:
        number:
          min: 10
          max: 300
          unit_of_measurement: seconds
    boost_n:
      name: Boost
      description: "Boost to second interval if n moves in the first"
      default: 2
      selector:
        number:
          min: 0
          max: 9
    all_day:
      name: Switch all day long
      description: "Always switch on lights, even during the day"
      default: 0
      selector:
        number:
          min: 0
          max: 1

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

variables:
  light_target: !input light_target
  no_motion_t1: !input no_motion_t1
  no_motion_t2: !input no_motion_t2
  input_number_entity: !input input_number_entity
  boost_n:  !input boost_n
  all_day:  !input all_day

trigger:
  platform: state
  entity_id: !input motion_entity
  to: "on"

action:

  - choose:
      - conditions: "{{ states(input_number_entity)|float < 0.1 }}"
        sequence:
          - service: input_number.set_value
            data:
              entity_id: !input input_number_entity
              value: 0.1


  - choose:
      - conditions:
        # Switch on if night or if all_day=1
        - "{{ not is_state('sun.sun', 'above_horizon') or all_day|int==1 }}"
        # Only switch if we have a light
        - "{{ not not light_target }}"
        sequence:
          - service: light.turn_on
            target: !input light_target

    # >3.n - n=1-9, n=count in last 60 seconds
  - choose:
      # Ensure we dont go past 3.9 when incrementing 0.1
      - conditions: "{{ states(input_number_entity)|float > 3.8 }}"
        sequence:
          - service: input_number.set_value
            data:
              entity_id: !input input_number_entity
              value: 3.9
      # Add .1 increments to count the amount of triggers
      - conditions: "{{ states(input_number_entity)|float > 2.95 }}"
        sequence:
          - service: input_number.set_value
            data:
              entity_id: !input input_number_entity
              value: "{{ (states(input_number_entity)|float+0.1)|round(1) }}"
      # increase from 2-->3, but keep the minor...
      - conditions:  "{{ states(input_number_entity)|float > 1.95 }}"
        sequence:
          - service: input_number.set_value
            data:
              entity_id: !input input_number_entity
              value: "{{ (states(input_number_entity)|float+1)|round(1) }}"
            # - repeat:
            #   count: 10
            #   sequence:
            #     - service: input_number.increment
            #       data:
            #         entity_id: !input input_number_entity
    # ELSE set to 3 - starting here...
    default:
      - service: input_number.set_value
        data:
          entity_id: !input input_number_entity
          value: 3

  - delay:
      seconds: "{{ no_motion_t1 }}"

  # decrement by 1 (10xstep)
  # 2..2.9 = no_motion_t1 < t < no_motion_t2
  # - repeat:
  #     count: 10
  #     sequence:
  #       - service: input_number.decrement
  #         data:
  #           entity_id: !input input_number_entity
  - service: input_number.set_value
    data:
      entity_id: !input input_number_entity
      value: "{{ (states(input_number_entity)|float-1)|round(1)|float }}"

  # if more than boost_n times, activate the boost "on" time
  - variables:
      boost_active: "{{ states(input_number_entity)|float > (2.05+(boost_n|int)/10) }}"

  # Switch light off if boost_NOT_active
  - choose:
    - conditions:
      - "{{ not boost_active }}"
      - "{{ not not light_target }}"
      sequence:
      - service: light.turn_off
        target: !input light_target

  - delay:
      seconds: "{{ no_motion_t2 }}"

  # Switch light off after delay if boost_active
  - choose:
    - conditions:
      - "{{ boost_active }}"
      - "{{ not not light_target }}"
      sequence:
      - service: light.turn_off
        target: !input light_target

  # 5min < 15min
  - service: input_number.set_value
    data:
      entity_id: !input input_number_entity
      value: 1
  - delay:
      minutes: "10"

  # 15min < t < 30min
  - service: input_number.set_value
    data:
      entity_id: !input input_number_entity
      value: 0.5
  - delay:
      minutes: "15"

  # 30min < t < 45min
  - service: input_number.set_value
    data:
      entity_id: !input input_number_entity
      value: 0.2
  - delay:
      minutes: "15"

  # 45min < t < 60min
  - service: input_number.set_value
    data:
      entity_id: !input input_number_entity
      value: 0.1
  - delay:
      minutes: "15"

  # >60 min
  - service: input_number.set_value
    data:
      entity_id: !input input_number_entity
      value: 0

It’s the middle of the day, so lots of movement :wink: but this is the result of the input_numbers for each zone.

image