I’m in the process of learning ESPhome and doing my first project.
Can someone explain to me how can I do something as simple as assigning a value to a variable?
I have this:
globals:
- id: zmiana_predkosci_mozliwa
type: bool
restore_value: no
initial_value: 'false'
How can this be done with a global of type string? Any help is much appreciated.
Booleans and numbers are easy. Docs only give this simplest of examples. Sad face.
globals:
- id: bootmsg
type: char[10]
initial_value: "{'b','o','o','t'}" # THIS WORKS.
# I DON'T KNOW A BETTER WAY
on_...:
then:
- globals.set:
id: bootmsg
value: ??? # WHAT GOES THERE?
# NOTHING I TRY WORKS
Thanks for a simpler way to update text messages on my OLED display. The text sensor is easier and smaller to use than a global string for the text message. Using %s and id(displaytext).state.c_str() as below:
BUT, the question was how do I update the value of a global string of type char[10] with global.set
No working solution of any kind, yet.
I did figure out how to do this with a global string of type: std::string
As long as both displaymessage and displaymessage2 are of the same type: std::string I can do this:
I also tried to assign the text sensor state (after publish) to a global string type: std::string using global.set with no luck. The output is just blank. And with char[10] it won’t even compile.
id(displaytext).state.c_str()
id(displaytext).state