SOLVED: Remove 'jitter' on notifications?

Hi Guys

I’m not sure how to get this done. I have set up a few automations for notifications about new youtube videos and weather alerts.
When people upload videos to youtube, quite often they fix a headline or add tags or something like that, and that makes the automation resend the notificaton (I’ve set it up to react on ‘state change’).
How do I make it, so that if a state is changed within like 10 mins, it will not resend the notification?

You can add a condition to wait a certain amont of time before performing the action again.

      - condition: template
        value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.automation_name.attributes.last_triggered) | int > 120 }}

The 120 is 120 seconds. Change that value to the number of seconds you want to wait.

You can test the template in the developer tool, if it renders true it will allow the action to occur. If it renders false it will not proceed.

1 Like

Or if your triggers are state triggers, and you don’t mind a delay, you can just add a for: statement so that the state has to be stable for a certain period of time before triggering. e.g.

  trigger:
  - platform: state
    entity_id: binary_sensor.new_youtube_video
    to: 'on'
    for:
      minutes: 5
1 Like

@silvrr That is pretty cool, thankyou for the help!
@tom_l Thanks Tom, but I would like to get the notification ‘immediately’

No worries, just putting the option out there.

I use both solutions. I use the template condition in some automations where I want the first notification right away and the state time in other automations where I don’t care about timeliness - just because it’s easier to write.

1 Like

And I love the option !:wink:

Hmm for some reason I don’t get any notifications now, is it the automation that’s to blame?

- id: '1566214902542'
  alias: Youtube - videorelease - DrZzz
  trigger:
  - entity_id: sensor.drzzs
    platform: state
  condition:
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.youtube_videorelease_drzzz.last_triggered)
      | int > 600 }}'
  action:
  - data:
      message: Der er en ny DrZzz video ude nu
      title: Ny DrZzz video frigivet
    service: notify.webpush_mobil

I’ve tested the webpush itself, and that works fine.

You need to tell the template that last_triggered is an attribute.
Adjust your condition as shown below.

  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.youtube_videorelease_drzzz.attribute.last_triggered)
      | int > 600 }}'

As rule I always test my templates in the template developer tool before implementing. Helps debug things like this.

I also try to do that: If I test mine, I’m told that there is no ‘last_triggered’, if I use yours, I get:
Error rendering template: UndefinedError: ‘homeassistant.core.State object’ has no attribute ‘attribute’

I tried a similar condition a year or two back but I had to remove it because it was preventing the automation from triggering at all if it had never been triggered since a restart (therefore there was a null value for last_triggered). I wonder if this attribute is now persistent across a restart?

Sorry its attributes not attribute.

I tested a automation that is currently null and it returns true with the template fribse is using. Therefore it would allow the automation to complete.

1 Like

Ahaaa, thankyou, that seems to work, at least in the template test.
Now I just need one of the guys to release a video, so that I can see if it shows up :smiley:

The result:

- id: '15987234266214'
  alias: Youtube - videorelease - Paul Hibbert
  trigger:
  - entity_id: sensor.paul_hibbert
    platform: state
  condition:
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.youtube_videorelease_paul_hibbert.attributes.last_triggered)
      | int > 600 }}'
  action:
  - data:
      message: Der er en ny Paul Hibbert video ude nu
      title: Ny Paul Hibbert video frigivet
    service: notify.webpush_mobil

He he, now I want to refine it a bit, but the automation doesn’t send out a message when I manually trigger it.

- id: '1566214993715'
  alias: Youtube - videorelease - RepairGuy
  trigger:
  - entity_id: sensor.repairguydk
    platform: state
  condition:
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.youtube_videorelease_repairguy.attributes.last_triggered)
      | int > 600 }}'
  action:
  - data:
      message: Der er en ny RepairGuy video ude nu
      title: Ny RepairGuy video frigivet
    data_template:
        url: '{{ states.sensor.repairguydk.attributes.url }}'
    service: notify.webpush_mobil

If I remove the data_template part, it works as before.