KIOSK text field in perspective

I have a system with kiosk screens. When I tap my card it also enters a line itself in my value. I am using a text field and have 3 conditions to follow,

  1. If my length is < custom property altMax then my text field should refresh after 20 seconds as my user will be entering value manually
  2. If my length == altMax then my text field should refresh after 5 seconds
  3. If my text field contains a value and my user leaves the screen the text field should be back to " "

Here is a code that was working for the first two conditions

def valueChanged(self, previousValue, currentValue, origin, missedEvents):

    # Ensure the field does not take more than altMax characters
    self.props.text = self.props.text[:self.custom.altMax]

    # Import the necessary function for delayed execution
    from threading import Timer

    # Define a function to reset the value
    def reset_value():
        # Set the value to an empty string
        self.props.text = ""

    # Check the length of the currentValue
    if len(currentValue.value) < self.custom.altMax:
        # Set the timer for 20 seconds (20000 milliseconds)
        Timer(20.0, reset_value).start()
    else:
        # Set the timer for 5 seconds (5000 milliseconds)
        Timer(5.0, reset_value).start()