How to correctly timestamp MQTT state updates?

I wish to timestamp incoming mqtt state updates (using the MQTT integration). The timestamp may be in the past as my mqtt states may be updated some time after the sensor changed, but currently the timestamp given to the sensor update is the same as the time the MQTT message was recieved. In the incoming state update from my broker the time the state changed is in the incoming packet, I just need to “insert” it somehow.

How can I apply a timestamp so that the state is registered correctly in the database, and history plots show correctly?

There are several posts in this community that ask about timestamps but I cannot find anything that answers exactly this.

You can’t. HA doesn’t work this way. There’s no way to override the time on state objects.

There are some integrations that allow you to add historical LTS data, however a change like this would require changes to the integration.

That’s a shame. There’s quite a few queries along the same lines in the community forums.