Template: last_changed to specific state?

now that I have the Code i need to insert It into a yaml Code card

I have tried something like this but got no results

{% set napa = (states('switch.ladron_pasillo_0_enchufe_1.last_changed') if is_state('switch.ladron_pasillo_0_enchufe_1', 'on' )) %}
{% if napa - now() <= 2 %}
{{ 'hello' }}
{% else %}
{{ 'bye' }}
{% endif %}

What card are you talking about?
As for standard cards - only a Markdown card supports jinja templates.
Besides, this template may cause errors if a variable is unknown.

It is a custom button card. I just want to animate a shape via card_mod

More precisely I want to change animation rate, thats why i needed the time.