esphome icon indicating copy to clipboard operation
esphome copied to clipboard

Add text input component

Open mauritskorse opened this issue 3 years ago • 7 comments

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:

mauritskorse avatar Jul 15 '22 13:07 mauritskorse

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)

probot-esphome[bot] avatar Jul 15 '22 13:07 probot-esphome[bot]

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)

probot-esphome[bot] avatar Jul 15 '22 13:07 probot-esphome[bot]

Would it be possible to implement initial_value and restore_value for this?

nagyrobi avatar Jul 16 '22 20:07 nagyrobi

Would it be possible to implement initial_value and restore_value for this?

Yep, that's already on the roll.

mauritskorse avatar Jul 20 '22 14:07 mauritskorse

I'm waiting for this component. Very lacking...

SCratORS avatar Aug 22 '22 07:08 SCratORS

Me too, and for sure the HA integration part.

nielsnl68 avatar Aug 22 '22 11:08 nielsnl68

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

jesserockz avatar Aug 25 '22 04:08 jesserockz

I hope this can be added soon. I like to use this in my switchplate component.

nielsnl68 avatar Oct 21 '22 01:10 nielsnl68

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

mauritskorse avatar Nov 04 '22 10:11 mauritskorse

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.

mauritskorse avatar Nov 04 '22 10:11 mauritskorse

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

mauritskorse avatar Nov 17 '22 21:11 mauritskorse

Will be ready for the new 2022.12.0 HA release ? :)

SeByDocKy avatar Dec 03 '22 09:12 SeByDocKy

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.

mauritskorse avatar Dec 09 '22 11:12 mauritskorse

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'

foxsam21 avatar Jan 04 '23 22:01 foxsam21

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

nagyrobi avatar Jan 13 '23 09:01 nagyrobi

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: and max: in it; but what will that tell? is that the value that is only allowed a number between min: and max:, 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...

mauritskorse avatar Feb 05 '23 16:02 mauritskorse

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.

github-actions[bot] avatar May 07 '23 00:05 github-actions[bot]

I still hope this will be added soon :D

nielsnl68 avatar May 07 '23 00:05 nielsnl68

This PR looks great, what is the status of this PR? @jesserockz

arthurkomatsu avatar Jun 08 '23 03:06 arthurkomatsu

What is the status of this PR? Has the HA side still not been added?

nielsnl68 avatar Aug 11 '23 14:08 nielsnl68

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.

EternityForest avatar Sep 01 '23 21:09 EternityForest

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

EternityForest avatar Sep 02 '23 03:09 EternityForest