How to Read hex result from UART

Hi all,

I believe this should be an easy question, however I indeed have not found out the answer after several nights digging.

I’m having a Dart WZ-S HCHO sensor here, I would like to use it with ESP8266, and use ESPHome to have an entity showing values in HA, I’m seeing the data from UART debug saying as below (’,’ is the separator I added in log_hex part).

[20:57:40][D][uart_debug:114]: <<< FF,17,04,00,01,04,13,88,45
[20:57:41][D][uart_debug:114]: <<< FF,17,04,00,01,04,13,88,45
[20:57:42][D][uart_debug:114]: <<< FF,17,04,00,01,04,13,88,45
[20:57:43][D][uart_debug:114]: <<< FF,17,04,00,01,04,13,88,45
[20:57:44][D][uart_debug:114]: <<< FF,17,04,00,01,04,13,88,45

My biggest problem here is how could I get the 5th and 6th digits (…01,04…) maybe as string or dec. (Then I should be able to do some math and make it available in HA, which I believe should not be very complicate.)

I’m having some programming background, but unfortunately not familiar with C/C++, for .h file, I could only modify in original frame and not be able to improvise.

I’m so appreciated if you could share some webpages or maybe some codes with me (or just point me a direction or anything), just been crazy for such an obstacle.

Only way I see is through lamba coding in ESPHome (Automations and Templates — ESPHome) which is basically some C++ (be careful code is compiled without checks so even if it compiles lambda code may be wrong :wink:

UART is a bit of a tease I reckon.

You can often see and decode the numbers you want with the debug, and you think you’d be able to do some relatively simple lambdas in your config to parse out the parts you want and publish them into sensors.

But from what I’ve seen you need to go down a custom sensor/component path to actually get the readings into sensors, and then that involves a big jump in knowledge.

So I think you need to Google around for examples and fumble through changing yours to suit.

That’s my thoughts anyway.

I think the custom component linked in this post does something similar (but more). The part that reads UART grabs a few bits and puts them in a sensor.

Here’s a sample that processes hex UART data and returns data in several different sensors.

Combining two bytes into a single value occurs on line 397 of the .h file.