Once I set the value of a substitution, can I change it later? If so, how? If not, how can I use a variable where the value can be changed as needed?
Yes, but for it to take effect you have to recompile and upload the firmware.
Set up one of the Home Assistant components which can be modified from HA. You will likely need to include an automation in your firmware to update the desired endpoint when a change is made to the HA component.
What are you trying to do? What yaml do you have at the moment?
A lot of ESPHome inputs like numbers and text can have initial values and can then also be changed at runtime.
Have a a look at select:
and then the template it is used in:
(see the whole yaml [here])(Midea branded AC’s with ESPhome (no cloud))
You can also change this in the web interface
A general response for those helping me, since I have an appointment and can study this more later.
I’m trying to do this independently of HA. I’ve had many times where I upgrade HA and that breaks it and takes me, sometimes, a week or more, to fix it. So I’m working hard to make sure what I do will work with two (or more) ESPHome devices working with each other as well as being able to work through HA.
I want to be able to use the web interface to be able to change text components as needed and use them in sections other than the component itself. If I was writing a program, it would be like being able to get user input and use the user’s new input value throughout the program.
So something that only changes at compile time is not going to do what I need. I need to be able to change the values while ESPHome is running.
In general, I’m going to use a display hooked up to the ESPHome device. The user will be able to pick what devices to check for various states and pick what messages it displays according to those states. For instance, if the switch to my etching laser goes on, it’d see that through a REST API and display, “Warning: Laser in use. Wear safety goggles.” But I want to be able to use the web interface to change the values of the text that is displayed.
The section that displays text will be completely separate from the Text Template where it is changed from the web interface. But, overall, as I’m learning ESPHome, I’m finding it frustrating I can’t use real variables that I can update and change.
@Mahko_Mahko might have a point that works for me, if I can change the inputs and reference their value from elsewhere in the YAML file.
@aceindy, you might have it and I have to study what you provided more carefully.
So if I use a lambda call, then I could use them pretty much like I use variables in most languages?
One thing I want to do that I can’t quite figure out how to do in the YAML setup ESPHome uses is a delay I want to set up. I want to have a flag go off a set time after a device is turned off. For instance, one of them is a vent fan. For now, let’s say it turns off 2 minutes after the etching laser is turned off. I know I can use a delay for that, but what if it gets turned on again? If that happens, I want to reset the delay.
Turn the laser on, then off. Vent fan should stay on 2 more minutes. But then, if you find you have one more thing that you can etch, and it takes 30 seconds to etch, you run the program, it turns the laser on, then off. You still have time on that original delay, maybe 15 seconds. But I want that delay to be reset so it stays on for 2 minutes after the last time it was turned off.
I haven’t explored time components that much yet, so maybe it’s possible that whenever the switch is turned off, it can add 2 minutes to the current time, store that, and the delay will be in a loop that, each second, checks to see if it’s after that 2 minute delay. (Maybe that’d be the best way - if I can do it that way?)
You can call a script that has a delay until an action happens and have the script in restart mode.
You’d use a on_turn_off:
trigger or similar.