Adding condition checks in the automation seems to do the trick:
trigger:
- platform: state
entity_id:
- input_button.test_button
not_from:
- unavailable
- unknown
not_to:
- unavailable
- unknown
condition:
- condition: template
value_template: "{{ trigger.from_state is not none }}"
- condition: template
value_template: "{{ trigger.to_state is not none }}"
action:
- service: input_boolean.toggle
data: {}
target:
entity_id: input_boolean.test_light
mode: single