Set input_number to zero before next number is generated

I’m really struggling here, My brain is cooked.
I’m trying to set an input_number to zero before the new number is generated. Ive tried various ideas and Ive googled but Ive not got anywhere, I’m just not very good at this yaml lark.
So I thought another action or something would go between actions and data template to set the number to zero, I just don’t know what needs to go there. Can anyone help me out please?
I couple of people have suggested this but it didn’t work

actions:
  - data:
      entity_id: input_number.last_gate_lock_user_code
      value: 0
    action: input_number.set_value
  - data_template:
      entity_id: input_number.last_gate_lock_user_code
      value: "{{trigger.event.data.parameters.userId | int}}"
    action: input_number.set_value
mode: single

Thanks

Generally, the configuration looks fine (though data_template was soft-deprecated more than 3 years ago, so you should just use data), but you should share the entire automation. Sharing information piecemeal often results in prolonging this whole process of debugging.

When you say “it didn’t work”, how were you testing?

I’m unlocking the lock which triggers the automation, This uses a helper to generate the user number. If user 1 unlocks the lock once, number 1 is generated, But if the same user unlocks the lock, no number is generated because its already set. I think that’s correct
This is the full automation

alias: Gate Lock - Lock User
description: ""
triggers:
  - event_type: zwave_js_notification
    trigger: event
conditions:
  - condition: template
    value_template: "{{ trigger.event.data.device_id == '6021505e924ec4f3b039455440f2****' }}"
  - condition: template
    value_template: "{{ trigger.event.data.event == 6 }}"
actions:
   - data_template:
      entity_id: input_number.gate_lock_user_code
      value: "{{trigger.event.data.parameters.userId | int}}"
    action: input_number.set_value
  - data_template:
      entity_id: input_text.gate_lock_last_user
      value: |
        {% if states('input_number.gate_lock_user_code') | int == 1 %}
        Keiley Used Her Code
        {% elif states('input_number.gate_lock_user_code') | int == 2 %}
        Maddy Used Her Code
        {% elif states('input_number.gate_lock_user_code') | int == 3 %}
        Tag 1
        {% elif states('input_number.gate_lock_user_code') | int == 4 %}
        Card
        {% elif states('input_number.gate_lock_user_code') | int == 5 %}
        Code5
        {% elif states('input_number.last_front_door_code') | int == 6 %}
        Code6
        {% elif states('input_number.last_front_door_code') | int == 7 %}
        Code7
        {% elif states('input_number.last_front_door_code') | int == 8 %}
        Code8
        {% elif states('input_number.last_front_door_code') | int == 9 %}
        Code9
        {% else %}
        Error
        {% endif %}
    action: input_text.set_value
mode: single

It could be something as simple as you need a small delay between them.
Try with 1 second delay. It shouldn’t matter too much in this case anyway

This is how I would change the automation.

alias: Gate Lock - Lock User
description: ""
triggers:
  - event_type: zwave_js_notification
    trigger: event
conditions:
  - condition: template
    value_template: "{{ trigger.event.data.device_id == '6021505e924ec4f3b039455440f2****' }}"
  - condition: template
    value_template: "{{ trigger.event.data.event == 6 }}"
actions:
  - alias:  Reset value of last user code number to 0
    action: input_number.set_value
    data:
      value: 0
    target:
      entity_id: input_number.last_gate_lock_user_code
  - variables:
      codes:
        "1": Keiley Used Her Code
        "2": Maddy Used Her Code
        "3": Tag 1
        "4": Card
        "5": Code5
        "6": Code6
        "7": Code7
        "8": Code8
        "9": Code9
  - action: input_number.set_value
    data:
      value: "{{ trigger.event.data.parameters.userId | int(0) }}"
    target:
      entity_id: input_number.gate_lock_user_code
  - action: input_text.set_value
    data:
      value: |
        {% set user_code = trigger.event.data.parameters.userId | int(0) | string %}
        {{ codes.get(user_code, "Error") }}
    target:
      entity_id: input_text.gate_lock_last_user
mode: single

If you continue to have problems, you could copy/paste the “reset” action to the end of the automation so it is cleared before the next event even happens… but that might not fit with any other ways you are automating based on that entity.

That seems to have done the trick, I’ll run a few tests tomorrow.
Thank you ever so much, It has been driving me crazy