I created a script that I use to send notifications via email, HA notification, and mobile. I then call this script from automation notifications, so that I do not need to repeat the boilerplate to call multiple services for alerting.
The script calls persistent_notification.create
and requires the caller to pass in a variable that is used for notification_id
. This allows each automation to have its own persisted notification where there is only one active at a time.
I’d like to avoid having to keep track of ID’s, and just use the ID of the automation itself.
E.g. something like this.id
, or whatever the entity id of the script is called?
Is it possible to get the entity id as a template variable from within an automation?
E.g.
alias: "Notify: Solar Generation Low"
description: Send notification when solar generation is low
trigger:
- platform: numeric_state
entity_id:
- sensor.energy_production
for:
hours: 24
minutes: 0
seconds: 0
below: 1000
condition: []
action:
- service: script.notify_multiple_services
data:
identifier: "1005" <- Replace this with the auotmations' ID
message: Solar Generation Low
title: Solar
mode: single