Esphome::parse_float Error

I just upgraded esphome from 2021.10 to 2021.12 and now I get an error compiling

Error

Any help on this is much appriciated

Use: esphome::parse_number(x) instead and it works again (parse_float was removed in 2021.11)

The hint of @gungner is not complete but it did put me on the right track.
This replacement worked for me:

# OLD:
optional<float> y = parse_float(x);
# NEW:
optional<float> y = parse_number<float>(x);

Correct, my bad, <float> was written badly so it disappeared from the post.

1 Like

Hi everyone
Can someone please help me to convert my code into the new ESPHome format?
I cannot recompile under the new version and just replacing parse_float with parse_number did not work =(

    - 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);

You must replace parse_float by parse_number<float>. Please read before you ask.

I did =) just did not realise that you have to LITERALLY put =)

1 Like