Create a new sensor from Automation

I have a numeric output from an automation and I want to store this into a sensor.

Do I need to create a new sensor on configuration, and if so what kind should it be?
Also how would I change it’s value from the automation?

I am using a template because I am doing some calculations:

  {% set time=(as_timestamp(trigger.to_state.last_changed) -
  as_timestamp(trigger.from_state.last_changed)) | round(3)  %} {% set
  data=(trigger.to_state.state | float) - (trigger.from_state.state | float) %}
  {% if data > 0 %}
    {{ (((data*8)/time)/1024) | round(2) }}
  {% else %}
  {% endif %}

You could store the value in an input_number

I don’t really like the idea of having an input_number just to store the sensor data.
I would prefer it to be a sensor.

Then you need a python script or AppDaemon or a custom component for variables. You can’t do this with automations.

I thought of python scripts, but I couldn’t find how to get the previous value which is needed for the calculation. Do you know how to get this?

You can continue using your automation to calculate the value and then use the script to set the sensor by passing the sensor name and the valur as a parameter to the script. But I can’t help you there as I don’t use python scripts.

I think that you guided me to the right direction.
Will try checking them the way you proposed.