Template: how to sort by attribute and treat as int

Tags: #<Tag:0x00007f7395fcc7d0>

I am trying to do the following:

states.sensor|sort(attribute="state")

but it is being sorted as string. How can I sort on attribute but treat state as int?