Serial port HEX values

Hi!!

I’m trying to read the serial port from a 8051 but the 8051 sends the values in HEX, do you know a form of how to display that HEX values in HA?

It’s not exactly clear what you’re asking. Can you provide more context? E.g., are you trying to write python code? Or is this something you’re trying to do in YAML with a sensor of some sort?

If, e.g., you have a sensor entity whose state is a string of hex characters, and you want to convert that to decimal, you could use the int() filter in a template such as:

{{ states('sensor.my_hex_sensor')|int(0,16) }}

int(0,16) takes as input a string of hex characters (i.e., base 16) and converts it to an integer value, which, by default, will be displayed in decimal.

If that’s not what you’re asking for, then more context/description is needed.

Sorry to jump in on this thread but I’ve set up a serial connection (via usb) and can successfully write to it to turn the screen on/off using: echo -e -n ‘\x07\x01\x02\x50\x4F\x57\x01\x08’ >/dev/ttyUSB0

I’m now looking to retrieve the state of the screen (on or off) by sending a read hex string to the serial port (\x07\x01\x01\x50\x4F\x57\x08) where a return value of 07 01 00 50 4F 57 XX 08 should be received where XX = 00 for off and XX = 01 for on. Any suggestions how to set up a HA sensor to send the request, read the result and parse it?