Right format adding date and time in notification

Hi All,

I have configured a mail notification when my alarm is being triggered. I have added the time and date to the message. it looks like this:

- id: send_mail_when_alarm_triggered
  alias: Send notification when alarm triggered
  initial_state: 'on'
  trigger:
- platform: state
  entity_id: alarm_control_panel.ha_alarm
  to: triggered
  action:
- service: notify.gmail_notify
  data:
    title: 'ALARM!!!'
    message: "ALARM! The alarm has been triggered at {{ states.sensor.time_date }}!"

But i am receiving this:

ALARM! The alarm has been triggered at <template state sensor.time_date=16:14, 2019-05-15; friendly_name=Time & Date, icon=mdi:calendar-clock @ 2019-05-15T16:14:01.021251+02:00>!

How can i format this properly?

You need to use data_template.

From there use these options to get the time stamp you want.

What is the actual timestamp you are looking for?

2 Likes

Try this:

  data_template:
    title: 'ALARM!!!'
    message: "ALARM! The alarm has been triggered at {{ now().strftime('%H:%M %A %d %B %Y') }} "

Should give:

ALARM! The alarm has been triggered at 00:33 Thursday 16 May 2019

If you want a different format use this reference: http://strftime.org/

5 Likes

In addition to the error identified by silvrr (use data_template:, rather than data:) there’s another error. The template contains this:

{{states.sensor.time_date}}

which explains why it produced the long-winded string you saw.

It should use this:

{{states.sensor.time_date.state}}

or this:

{{states('sensor.time_date')}}

Alternately, you can follow tom_i’s suggestion and use strftime to customize the time/date format to whatever you desire.

1 Like