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.