Use
value_template: "{{ states('sensor.time') == (state_attr('input_datetime. sunrise_time', 'timestamp') - 300) | timestamp_custom('%H:%M', false) }}"
or
value_template: "{{ now().timestamp() | timestamp_custom('%H:%M') == (state_attr('input_datetime.sunrise_time', 'timestamp') - 300) | timestamp_custom('%H:%M', false) }}"
→ 300 = seconds
I use this trigger, too, and never had a problem. What does the automation debug trace say?