I am trying to parse this UART stream of data in order to extract the value for the “FlowTempSetpoint” but have drawn a blank. Can anybody give me a nudge in the correct direction please?
Thanks @tim.plas yes from what I have researched I like the route of parsing the dummy receiver. My challenge at the moment is generating suitable lambda script that filters the stream text data. Still getting my head around the syntax, will try and find something close to my use case as a starting point.
If that’s all you receive, you could verify that the length is 25 bytes (“FlowTempSetpoint: 10.00\r\n”).
Then extract bytes 19-23. That would be dirty simple approach if the value is always double-digit decimal xx.xx
I have only ever parsed HEX and my skills with strings are disaster, but it could be something like this:
sequence:
- lambda: |-
if (bytes.size() == 25) {
// Extract bytes 19..23
char buf[6]; // 5 chars + null terminator
for (int i = 0; i < 5; i++) {
buf[i] = bytes[19 + i];
}
buf[5] = '\0';
float value = atof(buf);
ESP_LOGD("uart", "Extracted value %.2f", value);
}
Thanks @Karosm; it compiled (which is a great start for me ) and whilst it is dirty it does extract the value I was looking for…would have to stress test it to see how resilient it is to fault conditions on the TX device. How would I pass this value to a HA entity? I am on baby steps but bit by bit I am managing to walk. I can see it is something to do with sensor.template.publish but can’t quite get the syntax correct to link up with the value parsed in the UART… thanks in advance
Amazing thankyou. So simple and worked a treat. Can be like playing with lego when you find the right blocks to build with but so infuriating when you are not sure were to look. Any good points of reference for building up some good foundation knowledge on ESPhome / yaml apart from trial and error!? Thanks again
Esphome documentation of course. It’s the only place where you find updated and valid information. This forum is good source as well, but esphome is evolving so fast, that lot of info gets outdated quickly.
And when you need help, open new topic instead of posting to some (years) old one.