Alert component is very useful because it has a unique possibility to execute action multiple times until the end of a certain condition. This is not easy to achieve in other ways.
Strangely, as far as I understand, alert components can call only notification service, and can’t call other services. Because notification is one of the many useful services, it is hard to understand why to limit the alert component so much.
For example, I want to make repeated announcements via TTS if a door is open until the door is closed. TTS currently can’t be used via notification service, and alert component not allows to call TTS service. So the mission is impossible.
Please change the alert component so it will be able to call any service like automation.
Thank you in advance!
Good point.
In the meantime, you can create an empty Notify Group. Then create an automation that triggers on that notification.
notify:
- platform: group
name: xxx
services: []
automation:
- trigger:
platform: event
event_type: call_service
event_data:
domain: notify
service: xxx
action:
- service: ...
In the alert use xxx
as the notifier. Kind of a hack, but it should work.
@pnbruckner Interesting solution. Thank you. The question is how can I pass the message from notification to service
For example, I have
alert:
alarm1:
name: My alarm
message: My alarm message
done_message: My done message
entity_id: sensor.washing_machine_state
state: 'full'
repeat: 40
can_acknowledge: true
skip_first: true
notifiers:
- xxx
I suppose I should use something like:
- trigger:
platform: event
event_type: call_service
event_data:
domain: notify
service: xxx
action:
- service: tts.google_translate_say
data_template:
message: "{{ ??? }}"
So what I need to put inside {{}} to get the message from the alert?
message: "{{ trigger.event.data.message }}"
ha how cool that would be. thanks for the hack (a true hack indeed, since the list is not optional… never new an empty list would be accepted as a valid list )
anyways, I tried it like this:
- alias: Notify to service alert Kist
trigger:
platform: event
event_type: call_service
event_data:
domain: notify
service: notify_service
action:
- service: tts.google_say
data_template:
message: >
{{trigger.event.data.message }}
alert:
test_notify_service:
name: Notify to service
message: Light Kist is on until you acknowledge
done_message: Light Kist turned off
entity_id: light.kist
state: 'on'
repeat: 1
can_acknowledge: true
skip_first: true
notifiers:
- notify_service
but receive an error about the tts being empty:
Error on init TTS: No TTS from google_translate for ''
the alert works alright:
@pnbruckner @Mariusthvdb
I checked. And it should be
{{ trigger.event.data.service_data.message }}
Oops, sorry about that. I actually captured a notify event on the EVENTS page, but forgot the details before I answered that last question. Glad you figured it out.
yes!
Now I would love to have the done-message spoken to me too, so guess we need a service template for that also based on the trigger.event.data.service_data.to_state
?
would
{% if trigger.event.data.service_data.to_state == 'on' %} {{ trigger.event.data.service_data.message }}
{% else %} {{ trigger.event.data.service_data.done_message }}
{% endif %}
do it?
well, it won’t for now… must be the incorrect service_data.
But, and that’s the good news, the template isn’t necessary in the first place. The alert chooses the appropriate message, and when the alert is turned off, fires the event for the automation along with the done_message