Timestamp in html 5 Push Notifications

Hi, I finally setup push notifications but I’m struggling to get a message with timestamp to work. I mean if I try to launch the service notify.my_notifier with the following JSON string:

{“message”:“This is a test to say what time it is :”, “data”: {
“timestamp”:“now()”
}
}

It is showing my message but without displaying the time. I want to format it using:
{“message”:“This is a test to say what time it is :”, “data”: {
“timestamp”:“now().strftime(’%H:%M’)”
}
}
But as my first JSON does not work properly this one doesn’t work either. Could you please help me to find where my error is? I guess It’s a syntax problem but I don’t get it.:roll_eyes:

No answers yet. Meanwhile, I’ve reread this:


…And it seems that all data info added is not supported by html5 and will be sent back to you in the callback events. So does this mean that we cannot notify and display the exact hh:mm when our notification was triggered?? There should be some way to be able to do that. Thanks!!

I’ve finally found a solution here:
https://github.com/home-assistant/home-assistant/issues/3464
So no data field to include in JSON,and it works like this:

{
“message”: “{{ as_timestamp(now()) | timestamp_custom(’%H:%M’, true) }} - Nest ha encendido la caldera.”
}
:ok_hand::grinning::grinning:

1 Like

do you know how you may use timestamp inside .yaml config file?
I try many format method but it is unsuccessful

Hi, sorry for answering late. I’m on vacation, but what for do you plan to use a timestamp inside the configuration file. I don’t get it.

I use html5 notification but not direct json. I have this setup inside automation.yaml file to send message.

I am able to send message, image, add tag,vibrate but can NOT display the timestamp with the message
I try below but no success

- alias: 'Notify Gate Open'
  trigger:
    - platform: state
      entity_id: binary_sensor.gate
      from: 'off'
      to: 'on'
  action:
    - service: notify.notify
      data:
        title: 'GATE'
        message: 'Open'
        data:
          tag: alert
          url: 'https://hass.com/kiosk/group.garage'
          image: "https://hass.com/api/camera_proxy/camera.gate?api_password=password"
          vibrate: "700, 100, 700"
          renotify: 1
          timestamp: '%H:%M'

OK, now I’m back, sorry again for my delay answering. As I see it yours is the same case as mine, you just have to embed the JSON tempalte inside your message. Look at an extract of one of my scripts:

- data:
    message: '{{ as_timestamp(now()) | timestamp_custom(''%H:%M'', true) }} - Covers are 
              going to be closed.'
  service: notify.my_notifier

or in your example, just change: message: ‘Open’ for:
data:
title: ‘GATE’
message: ‘{{ as_timestamp(now()) | timestamp_custom(’’%H:%M’’, true) }} - Open’

Just give it a try this way. Hope it helps!!

Thank you

just for my understanding. ‘Timestamp’ tag does not work in yaml but your solution is workaround.

Timestamp is showing now that I have implemented your suggestion.

Yes, indeed, timestamp field is not working for html5 push notifications. However you can use this method inside the message tag as a nice workaround and you can format date and time as you wish as described in this link:

https://docs.python.org/3/library/time.html#time.strftime