It’s possible to add custom attributes to an existing entity. You can do it via Configuration > Customizations or by adding the new attribute to the customize.yaml file (explained here).
However, the custom attribute’s value cannot be defined by a template. The value must be a constant like a string or integer.
It is possible to change the value of an entity’s state or attribute. It can be done with a python_script like this one. However, that change is not permanent and is lost when Home Assistant is restarted.
As you can see, although it is easy to create a new attribute, assigning it a dynamic value isn’t straightforward. You might be better off creating a Template Sensor.