Include timestamp in notify

This is probably something super simple and I’ve tried a couple of ideas but have had no luck. I am using twitter to notify me of an alarm triggering but twitter is rejecting duplicate messages. I figure if I include a timestamp (hh:mm:ss) that this will bypass this scenario.

I tested and it will send out if I manually change the message each time so now I just need to automate it.

I’d prefer a text (SMS) really but I only saw the one $ option for that.

Why you do not use an other channel like Slack, Pushbullet or others. See https://home-assistant.io/components/notify/ for the full overview.
To include a timestamp in your message you can use templating.

For example:

alias: Test notification
trigger:
  - platform: time
    minutes: '/05'
    seconds: 0
action:
  - service: notify.Slack
    data:
      message: 'Test {{now.now().strftime("%Y%m%d-%H%M%S")}}'
1 Like

I will try this out tonight. Thank you!

I looked at those but basically I did not want to install yet another app onto the wife and my cell phones as they seem to get bloated down so easily This is why I would really prefer a text message (as I always check those) or twitter (since we both use this already). I may rethink this before it is over though.

I opened a messagebird account but have not decided if I want to pay for a service as this may be the beginning of a larger notification system for my HA (I try to avoid recurring costs :grin: ).

1 Like

You could also look into HTML5 push notifications. No charge and no extra software required (except for dependencies on the Pi).

I wanted something that would pop up on my phone and without another app or paid service. I opted to open a home assistant named gmail account and just use the SMTP notify component to send my main e-mail a message as needed. The e-mail will provide an instant notification on my phone and the e-mail will have the time stamp. One option of many available.

1 Like

Did you have any issues setting up the gmail portion? I saw multiple posts about needing to set up ports and then repeating every 90 days. I did not want something that was dependent on me re-configuring it.

No issues. You do identify a port but I believe that is on the g-mail side not your side. Setting up ports and a 90 day clock sounds like they are using let’s encrypt which is to secure your remote access, not related to this. I could be wrong though, feel free to link a post.

1 Like

I have basically lived on this site every night for the last month trying to customize and add to my HA to I may have mixed posts in my mind. I will look at it again.

The timestamp worked! I’ll continue to play with it and may set up the Gmail after all… or both :smiling_imp:

So i was not only able to get the gmail working but since my cellphone service has a email to sms service, I can get a text out of it!! I am super excited (and getting odd looks from the wife). This works splendidly!

Once again, thank you for all of the assistance. I’m sure there will be more needed before it is all over. I only hope that I can pay it forward to new users in the future.

[quote="michel.settembrino, post:2, topic:4192"]
    alias: Test notification
    trigger:
      - platform: time
        minutes: '/05'
        seconds: 0
    action:
      - service: notify.Slack
        data:
          message: 'Test {{now.now().strftime("%Y%m%d-%H%M%S")}}'
    [/quote]

I’ve been trying to use this code, only using notify.notify and I keep getting:

16-11-16 16:11:36 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=139714167055080-8, service_data=message=Test {{now.now().strftime("%Y%m%d-%H%M%S")}}, domain=notify, service=notify>
  File "/usr/src/app/homeassistant/components/notify/__init__.py", line 107, in notify_message

Any ideas?

It is due to next breaking change:

The template methods now and utcnow have been changed from variables to methods. To get the current time replace now with now().

So use:
message: ‘Test {{now().strftime(“%Y%m%d-%H%M%S”)}}’ instead of
message: ‘Test {{now.now().strftime(“%Y%m%d-%H%M%S”)}}’

2 Likes

Thanks, much appreciated.

How did you get the twitter notifcation to work so it also notifies you?
I only get a DM but as it’s from myself I don’t get any notification on my phone of a new message.

I set up a secondary account just for the HA system and had it direct messages to the account I actually use. I later abandoned it in lieu of text messaging as I am 100% more likely to hear & check that.

This was my twitter setup:

notify:
  name: notify
  platform: message_bird
  api_key: !secret mb_api_key
  name: twitter
  platform: twitter
  consumer_key: !secret twitter_consumer_key
  consumer_secret: !secret twitter_consumer_secret
  access_token: !secret twitter_access_token
  access_token_secret: !secret twitter_access_token_secret

For email/text I use this and directed it to my cellphone’s direct number @tmomail.net which comes across as a text:

notify:
  name: gmail
  platform: smtp
  server: smtp.gmail.com
  port: 587
  sender: !secret gmail_sender
  username: !secret gmail_user
  password: !secret gmail_password
  recipient: !secret gmail_recipient
  starttls: true

In my automation I have:

################################
### alarm light flash on
################################

- alias: Triggered Flash
  hide_entity: True
  trigger:
    platform: state
    entity_id: alarm_control_panel.ha_alarm
    state: 'triggered'
  action:
    - service: script.turn_on
      entity_id: script.light_flash
    - service: notify.gmail
      data:
        message: 'Home Alarm Triggered {{now().strftime("%Y%m%d-%H%M%S")}}'
################################
### alarm light flash off
################################

- alias: Disarmed Off
  hide_entity: True
  trigger:
    platform: state
    entity_id: alarm_control_panel.ha_alarm
    state: 'disarmed'
  action:
    - service: script.turn_off
      entity_id: script.light_loop
    - service: notify.gmail
      data:
        message: 'Home Alarm Reset {{now().strftime("%Y%m%d-%H%M%S")}}'
1 Like

Additional to this post, to have a custom time stamp with “:” or “/” use:

{{(now().strftime(“%s”) | int | timestamp_custom(“%H:%M %d-%m-%Y”))}}

3 Likes

It´s possible to use sensor.time in a notification. Add {{ states.sensor.time.state }} in the message for a timestamp when the notification is sent.

3 Likes