Automation using trigger.from_state

Hi, I am trying to collect charging data as it changes, and I need to get the difference between the old and new values, so I modifies a suggestion by petro
However I cannot get it to work, and after blundering around in Yaml I am pleading for help.
My automation is

alias: Test trigger from
description: ""
trigger:
  - platform: state
    entity_id:
      - input_number.ezri_charge_added_session
variables:
  continue: >
    {{ trigger | default(none) is not none and trigger.to_state is defined and trigger.from_state is defined }}
  before: >
    {{ trigger.from_state.state | float(0) if continue else 0 }}    
  after: >
    {{ trigger.to_state.state | float(0) if continue else 0 }}
  result: >
    {{ input_number.ezri_charge_added_today + after - before }}  
condition:
- condition: template
  value_template: "{{ continue }}"
action:
  - service: input_number.set_value
    data:
      value: result
    target:
      entity_id: input_number.ezri_charge_added_today
mode: single

that fails with
Stopped because of unknown reason “null” at September 28, 2023 at 9:03:20 AM (runtime: 0.00 seconds)
and strangely the automation is modified putting the variables down the bottom as below

alias: Test trigger from
description: ""
trigger:
  - platform: state
    entity_id:
      - input_number.ezri_charge_added_session
condition:
  - condition: template
    value_template: "{{ continue }}"
action:
  - service: input_number.set_value
    data:
      value: result
    target:
      entity_id: input_number.ezri_charge_added_today
variables:
  continue: >
    {{ trigger | default(none) is not none and trigger.to_state is defined and
    trigger.from_state is defined }}
  before: |
    {{ trigger.from_state.state | float(0) if continue else 0 }}    
  after: |
    {{ trigger.to_state.state | float(0) if continue else 0 }}
  result: |
    {{ input_number.ezri_charge_added_today + after - before }}  
mode: single

Any help would be wonderful, thanks in advance

Change this:

  result: >
    {{ input_number.ezri_charge_added_today + after - before }}  

to this:

  result: >
    {{ states('input_number.ezri_charge_added_today') | float(0) + after - before }}  

Change this:

    data:
      value: result

to this:

    data:
      value: '{{ result }}'

It doesn’t matter.

Thank you - obvious when you put it like that!

Thanks again, works perfectly