Because the state option is computed before the attributes option.
state
attributes
Change your sensor’s state template so that it doesn’t reference its own attributes.