Automation - condition how to check if input_text is empty?

how to check if input_text is empty in automation - condition ?


{{ states('input_text.your_entity') == ' ' }}

return true if the text field is empty.

Thx.

Can you show me how tu use this in automation?


  trigger:
    …

  condition:
    - condition: template
      value_template: "{{ states('input_text.your_entity') == ' ' }}"

  action:
    …

That’s not empty that’s a space. Does it actually work?

You could also do:

value_template: "{{ states('input_text.your_entity')|length == 0 }}"

This solution working, thx @pedolsky and @tom_l for help.

Now I have another question:)

How to empty input_text in automation?

I tryed like this:

service: input_text.set_value
data:
  value: ' '
target:
  entity_id: input_text.mami_google_calendar_description

but input_text not empty I have space in it.

Flawlessly. But I think your solution is more elegant.

Did you set an initial value in your input_text config?

service: input_text.set_value
data:
  value: '' # that's two single quotes with no space. 
target:
  entity_id: input_text.mami_google_calendar_description
1 Like

Another question:

How to deselect (clear selection) in input_select in automation?

I don’t think you can clear it. You can only change it to one of the options. Maybe add an extra option “Nothing Selected”, or “Off”?

1 Like

I am usingentity_select like you say. I just wondering if there’s a way to deselect selection:)

Not that I know of.

I have a strange problem with automation and input_text.

In both cases automation goes trough option 2 with or without text in input_text.mami_google_calendar_description

here is automation:

alias: mimi_google_calendar
description: vpis v google koledar mami počutje
trigger:
  - platform: state
    entity_id: input_boolean.mami_google_calendar_confirm
    from: 'off'
    to: 'on'
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              "{{ states('input_text.mami_google_calendar_description')|length
              == 0 }}"
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 5
              milliseconds: 0
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.mami_google_calendar_confirm
      - conditions:
          - condition: not
            conditions:
              - condition: template
                value_template: >-
                  "{{
                  states('input_text.mami_google_calendar_description')|length
                  == 0 }}"
        sequence:
          - service: google.add_event
            data:
              calendar_id: [email protected]
              summary: '{{ states(''input_select.mami_google_calendar_select'') }}'
              description: '{{ states(''input_text.mami_google_calendar_description'') }}'
              end_date_time: >-
                {{ states('input_datetime.mami_google_calendar_date') }}T{{
                states('input_datetime.mami_google_calendar_time') }}Z
              start_date_time: >-
                {{ states('input_datetime.mami_google_calendar_date') }}T{{
                states('input_datetime.mami_google_calendar_time') }}Z
          - delay:
              hours: 0
              minutes: 0
              seconds: 5
              milliseconds: 0
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.mami_google_calendar_confirm
          - service: input_select.select_option
            data:
              option: izberi
            target:
              entity_id: input_select.mami_google_calendar_select
          - service: input_text.set_value
            data:
              value: ''
            target:
              entity_id: input_text.mami_google_calendar_description
    default: []
mode: single

This is not correct. Do not quote multi-line templates

      - conditions:
          - condition: not
            conditions:
              - condition: template
                value_template: >-
                  "{{
                  states('input_text.mami_google_calendar_description')|length
                  == 0 }}"

I can also be simplified to:

      - conditions:
          - condition: template
             value_template: >
                  {{
                  states('input_text.mami_google_calendar_description')|length
                  != 0 }}

Only quote single line templates:

      - conditions:
          - condition: template
             value_template: "{{ states('input_text.mami_google_calendar_description')|length != 0 }}"

You have done this in two places.

1 Like

Now is working. thx

1 Like