Service call error input_text

Hi,
I have created an input_text helper using GUI which is configured like in the screenhot below:


Now when i try to change its value via service call i get this in my log and it won’t change:

[548150746752] sequence item 0: expected str instance, Optional found
[548014179280] sequence item 0: expected str instance, Optional found
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.9/site-packages/voluptuous/validators.py", line 215, in _run
    return self._exec(self._compiled, value, path)
  File "/usr/local/lib/python3.9/site-packages/voluptuous/validators.py", line 339, in _exec
    v = func(path, v)
  File "/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 134, in validate
    raise vol.Invalid("must contain at least one of {}.".format(", ".join(keys)))
TypeError: sequence item 0: expected str instance, Optional found

How do i solve this?

Obviously, please show the service call

@koying
Oh, i forgot to include this.
It’s a button card whose code is:

type: button
tap_action:
  action: call-service
  service: input_text.set_value
  service_data:
    value: '000000'
  target:
    entity_id: input_text.pin_eingabe
name: Test
1 Like

Works for me.
I’m not convinced the error is linked to the service call…

1 Like

@koying: I tried to click on the button, and
this little error box is showing after clicking on the Button card:

No clue. It’s in service_data but cannot see the issue.
Do you have the same problem when calling the service through the Developer tools?

1 Like

I cannot replicate the problem either. :man_shrugging:

  1. I created input_text.junk.
    Screenshot from 2021-08-03 11-13-51

  2. I created the following Button Card.

type: button
tap_action:
  action: call-service
  service: input_text.set_value
  service_data:
    value: '000000'
  target:
    entity_id: input_text.junk
name: Test
  1. Tapping the resulting Button Card sets the state value of input_text.junk to 000000.

  1. No error messages are reported in the Log.
1 Like

No, it then works as expected and sets the state to 000000

Maybe a gizmo in the button definition, then. Definitely where the issue lies, anyway.
Try to recreate it.

After trying several times, i ended up using an input_boolean and:

  • a new button card code:
type: button
tap_action:
  action: toggle
name: Test
entity: input_boolean.test
show_name: true
show_icon: true
show_state: true
  • and an automation for the service call:
alias: Test button
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.test
    from: 'off'
    to: 'on'
condition: []
action:
  - service: input_text.set_value
    target:
      entity_id: input_text.pin_eingabe
    data:
      value: '000000'
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.test
mode: single

Doesn’t make any sense.
Using directly a button works both for Taras and me…

Is your button directly under a lovelace view, or under another layout or something?

I have already found another solution (post edited) a workaround , deleted the button and replaced it with an automation, a helper entity, and a button card with toggle action on the helper entity
This does the job of setting the state but avoiding the service call

Wow, ok, fair enough. …

I would say you have found a workaround.

A true Solution would solve the original problem you experienced with the Button Card. What you have proposed avoids using a Button Card and employs a slightly more complex arrangement depending on an additional entity and automation. Effectively, your solution is “don’t use a Button card”.

The fact two other people were unable to duplicate the failure you experienced, implies something else is (was) responsible for the problem. Unless you investigate and resolve it, you may not be able to ever use a Button Card on your system (or the Button card you had created was uniquely corrupted and maybe now other Button cards you create will work properly).

1 Like

Yes, that’s right, I have only found a workaround, but the ‘workaround’ also uses a button card, just without the service call that is the problem, but with the toggle action
However, if I create another button card with another (different) service call (alarm disarm),
That works, but not if I create a new card using the code from the my first post

Except it’s not a problem for two other people who tested it using the same code. That implies there is something your instance is doing that is different.

That’s a useful clue.

One simple experiment is to create a script that sets input_text.pin_eingabe to 000000.

alias: pin_eingabe
sequence:
  - service: input_text.set_value
    target:
      entity_id: input_text.pin_eingabe
    data:
      value: '000000'

Then modify the Button Card to call the script.

type: button
tap_action:
  action: call-service
  service: script.pin_eingabe
name: Test

I have tried it, and it works :smiley:

That’s good news!

I would still consider my suggestion to be a workaround because it doesn’t explain why your Button Card doesn’t like calling the input_text.set_value command directly but is happy to call a script containing the same command.

Just to satisfy my curiosity, which version of Home Assistant are you using? I performed my test using 2021.7.4.

System Health

version: core-2021.7.4
installation_type: Home Assistant OS
dev: false
hassio: true
docker: true
virtualenv: false
python_version: 3.9.5
os_name: Linux
os_version: 5.10.17-v8
arch: aarch64
timezone: Europe/Berlin

GitHub API: ok
Github API Calls Remaining: 5000
Installed Version: 1.13.2
Stage: running
Available Repositories: 908
Installed Repositories: 40

logged_in: false
can_reach_cert_server: ok
can_reach_cloud_auth: ok
can_reach_cloud: ok

host_os: Home Assistant OS 6.2
update_channel: stable
supervisor_version: supervisor-2021.06.8
docker_version: 20.10.6
disk_total: 58.0 GB
disk_used: 45.0 GB
healthy: true
supported: true
board: rpi4-64
supervisor_api: ok
version_api: ok
installed_addons: Samba share (9.5.1), Terminal & SSH (9.1.3), motionEye (0.15.0), ZeroTier One (0.11.1), File editor (5.3.3)

can_reach_server: ok

dashboards: 6
resources: 30
views: 15
mode: storage

Interesting. That’s the same version of Home Assistant yet it produces a problem that others cannot reproduce. :thinking: