Adding leading zeros to Notification

Hi there,

I do have a notification with regard to opened windows:

The {{friendly_name}} was left open at {{now().hour}}:{{now().minute}}:{{now().second}}.

How do I reformat “{{now().hour}}:{{now().minute}}:{{now().second}}” in order to have leading zeros/digits?

Best wishes

datetime.strftime can handle that.

{% set friendly_name = "foo" %}

The {{friendly_name}} was left open at {{now().hour}}:{{now().minute}}:{{now().second}}.

The {{friendly_name}} was left open at {{now().strftime("%I:%M:%S")}}.

Results in:

The foo was left open at 8:47:0.

The foo was left open at 08:47:00.

Use %H if you want 24-hour clock hours.

1 Like

For completion, there’s also time.isoformat:

The {{friendly_name}} was left open at {{now().time().isoformat("seconds")}}.
1 Like