I swear, converting from one type to another in ESPHome is like dark magic. You don’t mention which platform you’re using for compilation (arduino versus ESP-IDF), and it matters. String might work on one platform but not the other. I convert a number to a string for one of my devices that uses ESP-IDF and am able to use:
Sorry,
I haven’t been doing this long; I wasn’t aware there were two different platforms.
error: request for member 'c_str' in 'hyst_->esphome::template_::TemplateNumber::<anonymous>.esphome::number::Number::state', which is of non-class type 'float'
113 | state: !lambda "return id(hyst_).state.c_str();"
- text_sensor.template.publish:
id: pool_anzeige
state:
lambda: |-
char buffer[50]; // Allocate sufficient buffer size
sprintf(buffer, "%.1f", id(hyst_).state); // Format to 1 decimal places. Add any other formatting using printf syntax
std::string str(buffer); // Convert char array to string
return str;
Error:
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
- number.increment: minddiff_
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- number.increment: hyst_
- text_sensor.template.publish:
id: pool_anzeige
Must be string, got <class 'NoneType'>. did you forget putting quotes around the value?.
state:
[lambda] is an invalid option for [text_sensor.template.publish]. Please check the indentation.
lambda: |-
char buffer[50]; // Allocate sufficient buffer size
sprintf(buffer, "%.1f", id(hyst_).state); // Format to 1 decimal places. Add any other formatting using printf syntax
Value typing is far too complicated for a system with the goal of making ESP development easy. The reason I use ESPHome is so that I don’t have to learn C.
I still only have a partial understanding of how this enables me to write to my video projector’s UART: