Changing states of text_input from a script

make a template binary_sensor

template:
- binary_sensor:
  - name: some_text empty
    state: "{{ is_state('input_text.some_text', '') }}"

Then use that in the conditional card using on or off.

I didn’t realize that.

thanks petro, it works perfect.

Hi, i got this also working with the white space. Any idea how i can make this as empty value?

Setting the input text to blank has recently stopped working for me. The below script was working fine for me for many months.

script:
  clear_fields:
    alias: Clear Input Text Fields
    mode: single
    sequence:
      - service: input_text.set_value
        target:
          entity_id: input_text.user_id
        data:
          value: ""
      - service: input_text.set_value
        target:
          entity_id: input_text.user_pin
        data:
          value: ""
1 Like

Working perfectly fine here. Are you sure the entity isn’t changing the value to nothing? Don’t look at the entity on your overview page as that can be affected by caching. Look at it in the developer tools → states page.

I’m seeing this too - I reported it on the release blog, but no-one seemed to pick up on it, or be seeing it.

As I said there, nothing in the logs, no change in the state in the Developer Tools → States page. Can still set the empty value via the frontend, just not via a service call.

As a workaround, to empty an input text, I now set the value to a single space " ", and return the value in scripts and automations with the jinja trim filter, which makes it at an empty string if it is only a single space.

Are you testing this in the service caller?

Yep, and via a script too. Believe me, I spent quite some time testing it from all angles, but haven’t posted a GitHub issue, as it seemed I was the only one.

And you see nothing in the logs, yet you get a “this worked” check when you press the call service button?

Yes, the new green check mark comes up, but with no change in the input text.

It also produces the red cross error (and reports an error in the log) when I try ‘null’ ‘none’ or ‘[]’, I guess because these are not string values.

EDIT: To be very precise, I only tested this on 2022.4.0, as I’ve been happy enough with the workaround to not investigate it any further.

Do you have a min value set on the input_text?

I tried it on input texts with min value set, and one’s without min value set, but with no difference that I could observe.

The documentation suggests that min_value defaults to 0 if you don’t set it, but I did try setting it explciitly to 0 anyway.

Nothing has changed in the code here at all. The last change to this service occurred 11 months ago.

EDIT: The last change to the entity itself was 5 months ago.

the code implies that the length of the string has to be greater than your minimum. I.e. if it’s set to 0, it must be length 1.

I admit it looks very strange, and is obviously not widely experienced. Something must be weird in my setup.

I half-wondered if changes to the database might be affecting how the entity history is stored, but then of course that would not explain how I can still empty the input_text from the frontend.

set state in the frontend is not the same as a service call to set the value.

Interesting - I don’t expect it would accept a min_value of -1 though?!?

There are no restrictions for that

FWIW, my minimum is 0 and I can set it to an empty string via the service.

Sounds like a bug go me, as the definition of minimum is the smallest number possible.

we still haven’t identified why it’s not working for him. No bug identified yet. :wink:

regardless, if you were lower than the minimum, you’d have a warning in your logs.