This.state in template sensor not working at all

Or asked differently, what is wrong with this template:

{{ this.state if this is not none and this.state is defined and this.state is not none else 0 }}

I would expect it to either render 0 or the previous value. But again it causes the same weird error message instead.