Having trouble POSTing input_select options with RESTapi

I am using the RESTapi to POST data into an input_select entity, but am having difficulty, not sure if it is a bug or something I’m doing wrong…

In my configuration.yaml, I have an input_select setup

input_select:
  pc_modes:
    options:
      - none
    name: PC Video Modes
    initial: none

which gives me this in lovelace
image

I am using Python on an separate (from HASS.IO) computer to send a POST request to home assistant.

{'User-Agent': 'python-requests/2.20.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'Authorization': 'Bearer REDACTED', 'Content-Length': '70'}
b'{"state": "2k.xml", "attributes": {"options": ["2k.xml", "4k.xml"]}}'

Home assistant accepts the request and returns a status 200

Everything looks good with the input_select on lovelace - it shows the options and current state correctly. Using the states inspector, again everything looks good.
image

But when I try to use the input_select in lovelace to change to one of the different options, I get the error,
Invalid option: 4k.xml (possible options: none)

It seems like the input_select will only accept the original “none” option, even though “none” is no longer an option for the entity.

Hoping someone can see something I’ve missed,
Thanks!

Ok after doing some more reading…
https://community.home-assistant.io/t/using-templates-for-input-select-set-options-populating-options-within-an-input-selector/55025/16
The conversation was about templating rest commands, but it still applies, I found out my mistake, but it still seems like more of an error.

I was using

curl -X POST -H "Authorization: Bearer REDACTED" -H "Content-Type: application/json" -d "{\"state\": \"4k.xml\",\"attributes\":{\"files\":[\"2k.xml\",\"4k.xml\" ]} }" http://192.168.10.144:8123/api/states/input_select.pc_modes

which for some reason ended up creating a new input_select with the same name, the lovelace was showing the new version, while the select validation still used the original.

when I try with

curl -X POST -H "Authorization: Bearer REDACTED" -H "Content-Type: application/json" -d "{\"entity_id\": \"input_select.pc_modes\",\"options\":[\"2k.xml\",\"4k.xml\" ]}" http://192.168.10.144:8123/api/services/input_select/set_options

it works as expected.

update: in addition the input_select options, even the state cannot be correctly applied via a POST to the /api/states endpoint, not sure why it’s even there, maybe just to generate new entities. (Got the state update working via /api/services/input_select/select_option)

Hope this can help anyone else .

You’re just changing the representation of the input_select entity in HA’s State Machine. You’re not actually changing the entity itself. You need to use services to do what you want. See call a service. Also, see the input_select services.

Thank you Phil, that makes sense now!

1 Like