I have an email notification automation which sends the timestamp of the last time a helper button has been pressed (input_button.hallwaypir_firsttriggerofday) which works fine but the format is not very readable.
Using below code in notification ‘message field’ body within the automation: Hallway First Trigger: {{ states("input_button.hallwaypir_firsttriggerofday") }}
it comes out like this in email: Hallway First Trigger: 2025-12-12T05:32:20.537596+00:00
Ideally I’d like it to display in dd/mm/yy hh:mm:ss format
Any ideas? I’ve tried a range of versions from various posts but it seems to fail (syntax errror) or come back with ‘unknown’ in the email body instead.
Not sure what I did wrong.
Notifcation email Message body:
Overnight line crossing counts - sent at {{ now().strftime('%H:%M:%S') }}
Back patio: {{ states("counter.counter_gcam_backpatio_linecrossing") }}
Charge pillar: {{ states("counter.counter_gcam_front_charger_pillar_linecrossing") }}
Front Porch: {{ states("counter.counter_gcam_front_porch_linecrossing") }}
Side Door Camera: {{ states("counter.counter_gcam_sidedoor_linecrossing") }}
Side Door PIR: {{ states("counter.counter_sidedoor_pir") }}
Hallway First Trigger: {{ states("input_button.hallwaypir_firsttriggerofday") }}
{{ as_local(as_datetime(state_attr('sinput_button.hallwaypir_firsttriggerofday', 'datetime_23'))).strftime('%-I %p') }}
Error given:
Error rendering data template: ValueError: Template error: as_datetime got invalid input 'None' when rendering template 'Overnight line crossing counts - sent at {{ now().strftime('%H:%M:%S') }} Back patio: {{ states("counter.counter_gcam_backpatio_linecrossing") }} Charge pillar: {{ states("counter.counter_gcam_front_charger_pillar_linecrossing") }} Front Porch: {{ states("counter.counter_gcam_front_porch_linecrossing") }} Side Door Camera: {{ states("counter.counter_gcam_sidedoor_linecrossing") }} Side Door PIR: {{ states("counter.counter_sidedoor_pir") }} Hallway First Trigger: {{ states("input_button.hallwaypir_firsttriggerofday") }} {{ as_local(as_datetime(state_attr('sinput_button.hallwaypir_firsttriggerofday', 'datetime_23'))).strftime('%-I %p') }}' but no default was specified
Delete the “s” from the front of sinput_button.hallwaypir_firsttriggerofday
Also, where is the attribute datetime_23 coming from? That’s not a standard attribute ID for an Input Datetime entity. If you are using a custom integration to create the entity or you are customizing its state object, you should tell us what you are doing.
Ok my string was just an example. You need to first have a read about Jinja and date times - it is possible your sensor was already a datetime. Also my example strftime format is almost certainly not what you want.
Use the template editor in developer tools to test just the last portion of your message body, removing all the filters then adding each back in.
You still have an extra “s” in each of those… the entity ID should be input_button.hallwaypir_firsttriggerofday, not sinput_button.hallwaypir_firsttriggerofday.
Good spot on the extra ‘s’ this has been removed but still not working.
‘datetime_23’ was from the example @zoogara provided, I haven’t referenced it anywhere else.