Custom timestamp error

I have a sensor that I want o get the last time (hour and minutes) it was last trigged

{{ as_timestamp(states.binary_sensor.kattlucka_grovkok.last_changed) | timestamp_custom("%H:%M") }}

The template give me last time the sensors was trigged in hours and minutes in developer tools but when I but it as a sensor in my yaml file I get this error

Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected '%') for dictionary value @ data['sensors']['kattluckan']['value_template']. Got '{{ as_timestamp(states.binary_sensor.kattlucka_grovkok.last_changed)| timestamp_custom(%H:%M) }}'. (See ?, line ?).

This is my code

    kattluckan:
      value_template: "{{ as_timestamp(states.binary_sensor.kattlucka_grovkok.last_changed) | timestamp_custom("%H:%M") }}"

Please help me! :slight_smile:

Wrote (“%H:%M”) instead off (‘%H:%M’)

For future reference, instead of using the as_timestamp() function, you can get the timestamp of last_changed directly:

 kattluckan:
   value_template: "{{ states.binary_sensor.kattlucka_grovkok.last_changed.timestamp() | timestamp_custom('%H:%M') }}"