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?
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
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.
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.
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?
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.
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
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