Use of input_boolean in the Blueprint Template Variable

I struggle with the input_boolean when used in template variable.

blueprint:
  ...
  input:
	overwrite_boolean:
      name: Overwrite Boolean (Optional)
      description: ...
      selector:
        entity:
          filter:
            domain: input_boolean
      default: []
variables:
  overwrite_boolean: !input overwrite_boolean
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: door_opened
          - condition: template
            value_template: "{{ states(overwrite_boolean) in ('unavailable', 'unknown', 'off') }}"
        sequence:
          - service: input_number.set_value
            data:
              value: 2
            target:
              entity_id: !input room_state

When I replace the variable with the specific entity, the automation works as expected:

"{{ states('input_boolean.entrance_overwrite') in ('unavailable', 'unknown', 'off') }}"

However, when used with the variable, either:

  • “{{ states(overwrite_boolean) in (‘unavailable’, ‘unknown’, ‘off’) }}”
    Automation works except case when the entity is not defined in the blueprint.
  • “{{ states(‘overwrite_boolean’) in (‘unavailable’, ‘unknown’, ‘off’) }}”
    Automation works only when variable not defined.

I tried creating the condition several different ways aslo with the use of has_value(), but can’t make it work. Perhaps someone knows what I’am doing wrong.

I don’t use blueprints often, but you likely need to add Or conditions to cover that case:

action:
  - choose:
      - conditions:
          - condition: trigger
            id: door_opened
          - or:
              - condition: template
                value_template: "{{ overwrite_boolean == none }}"
              - condition: template
                value_template: "{{ states(overwrite_boolean) in ('unavailable', 'unknown', 'off') }}"
        sequence:
1 Like

I had wrong expectation of the state ‘unknown’, where I thought it covers the case when the device is not stated (“{{ overwrite_boolean == none }}”).

I have end up doing the following:

blueprint:
  ...
  input:
	overwrite_boolean:
      name: Overwrite Boolean (Optional)
      description: ...
      selector:
        entity:
          filter:
            domain: input_boolean
      default:
variables:
  overwrite_boolean: !input overwrite_boolean
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: door_opened
          - condition: template
            value_template: "{{ overwrite_boolean == none or is_state(overwrite_boolean, 'off') }}"
        sequence:
          - service: input_number.set_value
            data:
              value: 2
            target:
              entity_id: !input room_state

This worked only after I have removed the incorrect statement: default:[] to default:

Thank you for the help Drew! :))

Or alternative to check for availability of an anything…

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

1 Like