Running a script after serial sensor received binary data?

Hi, I have a microcontroller that writes binary data to a serial port. I’d like to read and extract information from different sensors from this message (it’s a DL message from an UVR heating controller). Using a template sensor is not possible (e.g. depending on the UVR controller type there are different numbers of inputs and outputs). So I want to forward the data to a python script.

Any help?

I think I found a way using pyscript. Assuming the serial sensor is defined like this:

sensor:
  - platform: serial
    serial_port: /dev/ttyACM0
    name: UVR serial

the python script should be declared like follows:

@state_trigger("sensor.uvr_serial")
def uvr_data_received(value=None):
    if value:
        # do something with the data