Is it possible to create an input box within ESPHome?
For example, I want to store the MQTT within the UI and be able to update whenever I like, not hardcoded.
Is it possible to create an input box within ESPHome?
For example, I want to store the MQTT within the UI and be able to update whenever I like, not hardcoded.
Do you mean in a display attached to the esphome device, or do you mean in the web page produced by the web_server
component?
Web page.
Is like to be able to change it without re flashing the code
Yes.
But please don’t think too much into MQTT.
Just an input box where the data can be saved, not even sure if the data can be stored to flash so it doesn’t loose the data when rebooted.
Don’t think this is possible with ESPHOME?
Just coming back to this.
Is it possible for a text box to store the data to flash?
So i could input “hello world”
Reboot and it still be there…
But able to edit via the Web UI?
There is no control that allows user to enter some text. It is requested and I believe someone is working on it.
Thanks!
I think I also saw in some documentation that the data can’t be saved after a reboot either
Have a look at global variables:
Thanks!
I think this is where I saw global values can’t be saved on reboot?
This is where it says global values can be saved on reboot. The following will be restored on boot:
globals:
- id: a_global_value
type: int
restore_value: yes
initial_value: '1'
restore_value:
means save this to flash and restore on boot. Other commands are required on esp8266, these are in the linked docs.
Thanks!
But can this be a string, that’s edited and saved?
The only way you can currently edit and save an arbitrary string on ESPHome is to link a Home Assistant text sensor to an input_text:
helper in HA, and edit the text on HA.
You would use a lambda to write the value to the global when it changes (using on_value:
).
Can we do it now?
Just input on esphome webui, value would be saved and kept event after restart, so that way no home assistant is needed to update value.
Try it out and see what you come up with. Post your results and let the group know.
I’m working on a similar goal, to take a string from user-input, ideally from the web UI, and store the string in a persistent esphome global. I though I’d seen someone do that with the sprinkler component. They were storing schedule data like “Mon,Wed,Fri”, but I can’t find the example.
One thing to note: When setting a default value for esphome global (in the yaml), you always pass a string, regardless of the data type.
globals:
- id: my_int
type: int
restore_value: yes
initial_value: '0'
And if your data type is std::string, you have to double-enclose your value like this:
globals:
- id: days
type: std::string
restore_value: yes
initial_value: '"Mon,Wed,Fri"'
I’ll update, if I find a way to pass user input to a text_sensor. Note that we do have the ability to create API methods in esphome. I haven’t used that yet, but it might be part of a solution.
Update: Found it. Use the text
component. It’s like text_sensor
, but it’s intended for user input. You might have to use v2 or v3 of the web component.