Trying to have an input_select also read the input_text, to create further flexibility next to the preset options, Im having trouble finding the correct syntax.
So I think what youâre trying to do is to change one of the options in input_select.travel_destination to be the value of input_text.travel_destination. Is that correct?
If so, I believe this is possible. There may be a better way, but I would think that would involve an automation that would use the input_select.set_options service. I.e., whenever input_text.travel_destination changes (and probably when HA starts), the automation would trigger and the action would be to set the options of input_select.travel_destination. But I donât think you can change just one of the options - you have to set all the options. So the automation might look something like this:
I havenât actually tried this, so not sure if it will work exactly as is, but hopefully you get the idea.
Now, having said that, if it were me, Iâd just leave the last option as something like âas specified in text inputâ, and then have whatever uses input_select.travel_destination use input_text.travel_destination when the former is set to this last option. Does that make sense?
yes indeed. i follow your thinking in the automation (which i will try soon) but donât understand why I wouldnât just have it like that in the definition of the input_select in the first place. If you can set the options through the automation, that must be a possibility from starters too?
Wonât a template work in the options directly?
about your suggestion making sense: i do think that might be so Not sure exactly how this would be implemented though.
Another thing about the input_text: can you help me formatting the patternâŚ
the options from an input select are set in 2 ways: 1) in the config 2) through a service
and you cant use templates there.
in an automation you can use templates, thats why that would work.
edit: and pattern needs to be a string, so use quotes.
Yep, sorry, meant to comment about that, too. So the pattern, as I understand it, needs to be a âregular expression.â If youâre not familiar with regular expressions you can specify a pattern like âlower and upper case letters or numbers, followed by a comma and an optional space, followed by more lower or upper case letters or numbersâ. That would look like this:
pattern: '[a-zA-Z0-9]+, ?[a-zA-Z0-9]+'
Again, if youâre not familiar with regular expressions, just Google!
BTW, I havenât tested that regular expression on HA. There are a zillion definitions for how regular expressions work and Iâm not that familiar yet with how HA implements them.
about the automation: If the options are set in the automation, how do i declare the input_select.travel_destination itself. Right now i have the options in that declaration, but since the automation would set them that would not be correct any longer?
The options array is required when you define it in your configuration. But since it will (almost immediately) get overwritten by the automation, you can just include enough to make it happy, e.g.:
Just so you understand, initial and pattern do two different things. initial controls what the value will be when HA starts. pattern, on the other hand, determines whether what is typed in will be accepted.
E.g., you could just use initial as a hint for what should be typed in. Or you could just use pattern to make sure what is typed in meets some particular format (but that has to be defined in terms of a regular expression.) Or you could even do both.
Also note, if you donât use initial, then if HA restarts it will retain whatever is in the input_text across the restart, whereas if you do use initial it will overwrite that after the restart.
since the original travel time sensors work with zone.home and device_tracker.iphone as origin and destinations, and the input_select doesnât, could I add these to the automation to maybe?
Hmm, yes, templates can be tricky, and sometimes down right difficult. Try putting single quotes around {{ ... }}. So:
- Paris, France
- '{{ states("input_text.travel_destination") }}'
When I tried it on the Templates page I thought the single quotes would become part of the resulting string. But I think they might actually be necessary here.
BTW, donât claim to understand this all, by any means, but Iâm not sure how what you have for pattern works. Anyway, glad youâre making progress!
using the 2 techniques you both suggested, and Yamllint checked, seems to be fine both ways. The initial state is there as an example, and âpatternâ checks if one fills it put correctly
Yes, theyâre syntactically correct, but I donât think theyâre semantically correct. Are you sure youâre not getting any warnings or errors in the HA log regarding these?
As long as itâs working for you I guess thatâs the main thing. I just donât understand how it is. Besides the pattern for the input_text items, I also see other things in your configuration that I donât understand. E.g., under customize, you have âtemplatesâ under sensor.travel_destination, and the actual templates under âiconâ do not appear to be jinja. So either the documentation is woefully inadequate, or Iâm completely missing something.