So actually, there is a much better way to do this. That is, using a python_script as opposed to “regular” scripts.
First, add the following line to your configuration.yaml file (if you don’t already have it):
python_script:
Then create a directory in your <config> directory (i.e., the directory that contains configuration.yaml) named python_scripts. Then add a file to the <config>/python_scripts directory named dismiss_notifications.py and enter the following code into it:
for notif in hass.states.entity_ids('persistent_notification'):
hass.services.call(
'persistent_notification', 'dismiss',
{"notification_id": notif.split('.', 1)[-1]})
This python script does not remove my notification for “Login attempt or request with invalid authentication from localhost (127.0.0.1). See the log for details.”
Probably because that service did not use to exist (and there wasn’t even a “dismiss all” option in the notifications area), so it took work to write scripts to get rid of all existing notifications, hence these forum topics. But now that there is a service to do the job, nobody is asking anymore (because it says how to do it in the docs), so no new topics on the subject, just these stale, old topics that are out of date.