Add text input component
What does this implement/fix?
Adding a input text component (similar to Home Assistant). It allows for setting a string by the user through webserver comp front-end (v1). Implementation for v2 webserver front-end and Home Assistant is not done yet.
Types of changes
- [ ] Bugfix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Other
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#<esphome-docs PR number goes here>
Test Environment
- [ ] ESP32
- [ ] ESP32 IDF
- [x] ESP8266
Example entry for config.yaml:
input_text:
- platform: template
name: "test input text"
id: "it_1"
icon: "mdi:text"
optimistic: true
internal: false
Checklist:
- [x] The code change is tested and works locally.
- [x] Tests have been added to verify that the new code works (under
tests/folder).
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated in esphome-docs.
Hey there @ottowinter, mind taking a look at this pull request as it has been labeled with an integration (api) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
Hey there @ottowinter, mind taking a look at this pull request as it has been labeled with an integration (copy) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
Would it be possible to implement initial_value and restore_value for this?
Would it be possible to implement
initial_valueandrestore_valuefor this?
Yep, that's already on the roll.
I'm waiting for this component. Very lacking...
Me too, and for sure the HA integration part.
This will not work with Home Assistant.
Integrations cannot create "Input helpers". This needs to wait until there is a core entity type that allows text inputs, just like number did for input_number
I hope this can be added soon. I like to use this in my switchplate component.
I have tried to create a new text component for HA, but I can't get it to work yet. Not sure what I'm missing. Maybe someone else could have a try. Here's the code: https://github.com/home-assistant/core/commit/736f01a70e80b79b87ee465d5509b13397f7686c
I have tried to create a new text component for HA, but I can't get it to work yet. Not sure what I'm missing. Maybe someone else could have a try. Here's the code: home-assistant/core@736f01a
Ah, I already see what I'm missing. Will need to add support for this in esphome/aioesphomeapi as well.
Ok, I have tried it but I run into a problem testing as I can't get my aioesphomeapi branch to be used as dependency for the esphome component in HA (https://discord.com/channels/330944238910963714/554842238073700352/1039928836994908203). Maybe someone else could have a look. Below are links to the relevant branches
- https://github.com/mauritskorse/homeassistant-core/tree/input-text
- https://github.com/mauritskorse/aioesphomeapi/tree/text-input-component
Will be ready for the new 2022.12.0 HA release ? :)
Will be ready for the new 2022.12.0 HA release ? :)
I see that in the HA 2022.12 the text component was added. I will have a look whether I can get it to work with ESPHome now.
I just found this PR and wanted to test it out unfortunately something does not work I'm using dev branch and this config:
external_components:
- source: github://pr#3638
components:
- text
text:
- platform: template
name: "My Text Component"
id: "my_text"
optimistic: true
but when I try to run I get some errors:
ERROR Unable to load component text:
Traceback (most recent call last):
File "<my_path>/esphome/lib/python3.9/site-packages/esphome/loader.py", line 162, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<my_config_path>/.esphome/external_components/b41ee16a/esphome/components/text/__init__.py", line 46, in <module>
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTTextComponent),
AttributeError: module 'esphome.components.mqtt' has no attribute 'MQTTTextComponent'
Would be nice if this would be interoperable with the upcoming key_collector component so that text inputs could be also used for entering PIN codes etc. just like matrix or wiegand keypads can be used.
https://github.com/esphome/esphome-docs/pull/2426 https://github.com/ssieb/custom_components/tree/master/components/key_collector
@ssieb
I made some small comments and suggestion on finalizing the code.
Something i'm not clear of when i just see the yaml code; you are using
min:andmax:in it; but what will that tell? is that the value that is only allowed a number betweenmin:andmax:, or does it tell the size of the allowed string?
Thanks @nielsnl68!
Considering the min and max, that is the way the HA text entity addresses these (https://www.home-assistant.io/integrations/input_text/#configuration-variables). I agree that min_length and max_length are actually better.
Considering your suggestions, I have tried to stay close to the way the other template implementations are done. For example in number template component https://github.com/esphome/esphome/blob/6b7b0768755b21cca0e4b67515de93b9ca7b3821/esphome/components/template/number/init.py#L21
https://github.com/esphome/esphome/blob/6b7b0768755b21cca0e4b67515de93b9ca7b3821/esphome/components/template/number/init.py#L58
Of course I don't mind changing according to your suggestions, but my python skill aren't that good that I immediately know what to do...
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.
I still hope this will be added soon :D
This PR looks great, what is the status of this PR? @jesserockz
What is the status of this PR? Has the HA side still not been added?
I think I have everything for restore_value here: https://github.com/EternityForest/esphome/tree/add-text-input-component
But after writing the code, I discovered I can't easily test with what I've got on hand, this branch does not compile for S2 boards anymore it seems, it just tries and fails to fetch an old patch3 toolchain package.
I think I have this synced back up with dev on this branch, with the exception that I'm not able to compile the protobufs using version 3.6.1, haven't had time to set up a VM for that, so this is compiled on 3.12.
Not sure if this work is useful, or if it would just take longer to review than to redo, but I figured I'd give it a go, if nothing else for a chance to learn about protobufs.
https://github.com/EternityForest/aioesphomeapi/tree/text-input-component https://github.com/EternityForest/esphome/tree/sync-add-text-input-component