Template: how to sort by attribute and treat as int

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?

Hi,
I just managed to get a solution for a similar problem

It may help if you are still looking

Cryptic