Yes, and then adjust it depending on the incoming new value. I’ve just remembered I do something closer to what you want with my house “maximum power” record:
- alias: Max power recorder
trigger:
- platform: state
entity_id: sensor.power_meter_house
condition:
- condition: template
value_template: "{{ (states('sensor.power_meter_house')|float > states('input_number.max_power')|float) }}"
action:
- service: input_number.set_value
data_template:
entity_id: input_number.max_power
value: "{{ states('sensor.power_meter_house')|float }}"
Again, this is an input_number, and it is storing the maximum house power draw, updated via this automation which triggers whenever the prior maximum is exceeded. I wrote this some while ago: should probably have the template in the trigger instead of the condition, and there’s no need for data_template any more, as data works fine.