I have this code in esphome yaml that returns the desire value in string rather than number. Kindly help change the code to output number that I can assign unit of measurement to. Thanks in advance.
- text_sensor.template.publish:
id: pv1_voltage
state: !lambda |-
int32_t nIndex = 0, nCur = 0;
std::string::size_type curPos = 0, charPos = 0;
while((charPos = x.find(' ', curPos)) != std::string::npos && nIndex > nCur++) curPos = ++charPos;
return x.substr(curPos, charPos-curPos);