This Python script for Home Assistant allows you to save and restore entity last_changed status.
last_changed_saver - more info
This Python script allows dynamically setting the state and attributes of an entity in Home Assistant. It can be used to modify existing entities or create new ones if allow_create is set to true.