Fill Input select

Thanks, I’ll Try as soon as I can

Sorry everyone, I try my best but I still can’t understand.
The python script from @pnbruckner , it will make input_select display all entites in group.all_lights?
And how shout I edit the input_select?

I’m trying to make a timer for every entites. It look like this

Now I need a input_select to choose what entity to use this timer.
Hope someone can help me.
Thanks a lot, and I’m so sorry for my dumb.

Good day, was looking for this solution and was wondering if you could suggest a variation now that group.all_switches is gone.
Thank you

This:

group_entities = hass.states.get('group.all_lights').attributes['entity_id']
all_lights = []
for e in group_entities:
    all_lights.append(e)

can be replaced by this:

all_lights = hass.states.entity_ids('light')

If you want switches instead of lights then:

all_switches = hass.states.entity_ids('switch')

If you want a list of those entities whose attribute ATTR is equal to VALUE, then in addition to the previous:

sel_switches = []
for e in all_switches:
    if hass.states.get(e).attributes[ATTR] == VALUE:
        sel_switches.append(e)

or just:

sel_switches = []
for e in hass.states.entity_ids('switch'):
    if hass.states.get(e).attributes[ATTR] == VALUE:
        sel_switches.append(e)

Thank you very much for your prompt replay. So I have a custom entity called docker.

would this be correct in this case?

dockers = hass.states.entity_ids('docker')
    
dockers.append(hass.states.get(e).attributes['friendly_name'])
service_data = {'entity_id': 'input_select.docker_control',
                'options': dockers}
hass.services.call('input_select', 'set_options', service_data)

I doubt it.

Is the entity ID docker? It can’t be. Entity IDs must be in the form DOMAIN.OBJECT_ID. What is the entity ID, and what are its attributes? What list are you trying to write to the options attribute of input_select.docker_control?

apologies my mystake. It’s a Domain as you correctly pointed out. The component creates a domain “docker”; so I have for instance docker.homeassistant

I ran your initial suggestion like this

all_lights = hass.states.entity_ids('light')
service_data = {'entity_id': 'input_select.timer_generico7',
                'options': all_lights}
hass.services.call('input_select', 'set_options', service_data)

and got this error.

Traceback (most recent call last):
  File "auto_input_select.py", line 11, in <module>
    all_lights = hass.states.entity_ids('light')
NameError: name 'hass' is not defined
/config/python_scripts #

What exactly do you mean by you “ran” my initial suggestion? The script is only meant to be run as a HA python_script. You can’t run it “stand alone” outside of HA (e.g., from an ssh shell.)

You said there is a docker domain, and there are various entities in that domain. Ok, but again, what are you trying to write to the input select’s options attribute?

Im running HA in docker. so I ssh into the docker and run python auto_input_select.py.

What I would like to do is to automatically populate the input select with all the docker “Domain” entities. i.e. docker.homeassistant, docker.mqtt etc.

Thank you

Edit: uffff…I’m sorry i ran it from the dev services and works fine

Million apologies

Again, you can’t run that script that way. You have to use it as a python_script. If you don’t know how to do that, read the doc page I pointed you to, or read the discussion above.

Thanks for the clarification. I think this is what you want then:

service_data = {
    "entity_id": "input_select.XXX",
    "options": hass.states.entity_ids("docker")
}
hass.services.call("input_select", "set_options", service_data)

Yes, again apologies for the omission.

Thak you for your help and advice.

Of course this is simple enough to do with a simple service call:

service: input_select.set_options
data_template:
  entity_id: input_select.XXX
  options: "{{ states.docker|map(attribute='entity_id')|list }}"

EDIT: OOPS!!! NEVER MIND!!!

lol – I forgot, you can’t do it this way because the list will get turned into a string. Forget I ever said this!!! :smile:

ohh, thank you very much. I assumed it was not possible as in the intial thread you mentioned it may not work. Maybe I missread.

No, you didn’t. I just forgot.

Great, once again many thanks…

1 Like

FWIW, you can make the python_script even simpler:

hass.services.call("input_select", "set_options", {
    "entity_id": "input_select.XXX",
    "options": hass.states.entity_ids("docker")
})

thank you
Saving all the tips for another day :grinning:

1 Like

tried the service call and doesnt work as it’s limited to 255 charachters.

python script works well

thank you

Yeah, because as I said, that won’t work because a template can only output a string, so the list gets converted to a single string, which of course, is not what the service call needs. That’s the main point of this thread, which I had temporarily forgotten. (It’s been a while since this discussion happened – like over a year ago – so I thought there’s was more to what the OP wanted to do.)

Hi, is there is a way to fill input_select options from text file?
and anotehr question, can i set different input_text values ate the same time using for x in …
thanks