Decoding binary mqtt payload

Greetings All,

A new HA users here. I’d appreciate some help with decoding a binary
mqtt payload (not a binary sensor in a sense that it only has two states, but the
actual binary payload sent as a stream of bytes). I am throwing into a towel
after searching for a few hours.

The payload looks like this in C:

struct Message {
    struct Header {
       uint16_t id; // 2 bytes
       uint64_t timestamp;  // 8 bytes
       uint64_t sequence; 
    } header;
    uint8_t value1;
    uint8_t value2;
    uint16_t value3;
};

This struct is packed i.e. there are no holes.
A message like the one above is published on a mqtt topic, with the struct above
cast to uint8 and used as a payload.

What I know so far: I managed to configure a few sensors in HA that publish
a single value in json format.

If someone has a simple example on how to read the binary payload and make it
available to HA, I would appreciate it.

Thanks!

I’d like to add that I temporarily worked around this problem by running an executable (outside of HA) that subscribes to these topics, converts binary payload to json, and republishes it on a different topic so that HA could pick them up. It would be great to short-circuit that step.

You may wish to experiment with bitwise_and, bitwise_or, and bitwise_xor.
Numeric Functions and Filters

There’s also pack and unpack.
Functions and Filter to Process Raw Data