Try replacing the empty string with a states()
function that reports the sensor’s own (previous) value.
- platform: template
sensors:
amount_spent:
friendly_name: "Amount Spent"
value_template: >
{% set amount = state_attr('sensor.sm_g977u_last_notification', 'android.text') %}
{{ iif(amount is not search('AMZN|online|GOOGLE|PAYPAL', false), amount.split()[2], states('sensor.amount_spent')) }}