Need help to fix code for an updated ESPHome version

My old compiled codes works fine, apart from its not updating HA. But it gets proper values for the template sensor. Now, I am trying to “updated” it, after updating ESPHome version.
It started with just “parse_float” issue that is suppose to be “parse_number” now, but if I just change that, I get a lot more errors =( Why life cannot be simple?
This is my old code:

    - mac_address: E9:F5:D3:BB:1C:30
      service_uuid: 2A03
      then:
        - lambda: |-
            std::string b(x.begin(), x.end());
            std::string myStr = &b[0];
            float num_float = parse_float(myStr).value();
            ESP_LOGD("PowerMeter_sensor_instant_power:", "%s", &b[0] );
            id(PowerMeter_sensor_instant_power).publish_state(num_float);
            
    - mac_address: E9:F5:D3:BB:1C:30
      service_uuid: 2A04
      then:
        - lambda: |-
            std::string b(x.begin(), x.end());
            std::string myStr = &b[0];
            float num_float = parse_float(myStr).value();
            ESP_LOGD("PowerMeter_sensor_pulse_hour:", "%s", &b[0] );
            id(PowerMeter_sensor_pulse_hour).publish_state(num_float);      

    - mac_address: E9:F5:D3:BB:1C:30
      service_uuid: 2A05
      then:
        - lambda: |-
            std::string b(x.begin(), x.end());
            std::string myStr = &b[0];
            float num_float = parse_float(myStr).value();    
            ESP_LOGD("PowerMeter_sensor_pulse_day:", "%s", &b[0] );
            id(PowerMeter_sensor_pulse_day).publish_state(num_float);      

If I change from parse_float to parse_number, I get these errors:

config/esphome/m5atom-lite.yaml: In lambda function:
/config/esphome/m5atom-lite.yaml:45:43: error: no matching function for call to 'parse_number(std::__cxx11::string&)'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:375:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_unsigned<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:375:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:45:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:384:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_unsigned<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:384:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:45:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:389:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_signed<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:389:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:45:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:398:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_signed<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:398:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:45:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:403:13: note: candidate: template<class T, typename std::enable_if<std::is_same<T, float>::value, int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:403:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:45:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:412:13: note: candidate: template<class T, typename std::enable_if<std::is_same<T, float>::value, int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:412:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:45:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();
                                           ^
/config/esphome/m5atom-lite.yaml: In lambda function:
/config/esphome/m5atom-lite.yaml:55:43: error: no matching function for call to 'parse_number(std::__cxx11::string&)'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:375:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_unsigned<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:375:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:55:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:384:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_unsigned<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:384:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:55:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:389:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_signed<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:389:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:55:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:398:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_signed<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:398:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:55:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:403:13: note: candidate: template<class T, typename std::enable_if<std::is_same<T, float>::value, int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:403:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:55:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:412:13: note: candidate: template<class T, typename std::enable_if<std::is_same<T, float>::value, int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:412:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:55:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();
                                           ^
/config/esphome/m5atom-lite.yaml: In lambda function:
/config/esphome/m5atom-lite.yaml:65:43: error: no matching function for call to 'parse_number(std::__cxx11::string&)'
             float num_float = parse_number(myStr).value();    
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:375:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_unsigned<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:375:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:65:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();    
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:384:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_unsigned<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:384:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:65:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();    
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:389:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_signed<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:389:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:65:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();    
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:398:13: note: candidate: template<class T, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_signed<_Tp>::value), int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:398:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:65:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();    
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:403:13: note: candidate: template<class T, typename std::enable_if<std::is_same<T, float>::value, int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const char*, size_t)
 optional<T> parse_number(const char *str, size_t len) {
             ^
src/esphome/core/helpers.h:403:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:65:43: note:   cannot convert 'myStr' (type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') to type 'const char*'
             float num_float = parse_number(myStr).value();    
                                           ^
In file included from src/esphome/core/application.h:9:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:412:13: note: candidate: template<class T, typename std::enable_if<std::is_same<T, float>::value, int>::type <anonymous> > esphome::optional<T> esphome::parse_number(const string&)
 optional<T> parse_number(const std::string &str) {
             ^
src/esphome/core/helpers.h:412:13: note:   template argument deduction/substitution failed:
/config/esphome/m5atom-lite.yaml:65:43: note:   couldn't deduce template parameter 'T'
             float num_float = parse_number(myStr).value();    

Have you tried with

parse_number<float>

Instead of just parse_number.

/Mattias

Thank you! It’s fixed! But what a strange notation.

Hi
Glad I could help.
The parse_number is a template function so you need to define the type. My c++ knowledge is very rusty so I glad I got it right.

/Mattias