Hi All, I am in the process of creating a single reusable notification script that will notify Alexas, Google Assistant, and mobile entities all in one shot.
Though this script is triggering I donβt get notifications on Alexa or Google, I am getting mobile notifications on HA App.
Can someone review and tell me what am i doing wrong? I wanted to pass the list of Alexa and Google Homes as parameters for this.
alias: Script Notify Displays
description: Send notification to key devices
fields:
name:
description: Subject of the message
required: true
selector:
text: null
example: You are awesome
message:
description: Message content of the notification.
required: true
selector:
text: null
example: Notifications are awesome
notify_alexa:
description: Notify Alexa Devices
default: true
selector:
boolean: null
example: 'False'
notify_google_home:
description: Notify Google Home Devices
default: true
selector:
boolean: null
example: 'False'
entities:
description: List of Google Homes to notify
selector:
target:
entity:
domain: media_player
example: media_player.kitchen_display
alexa_entities:
description: List of Alexa Players to notify
selector:
target:
entity:
domain: media_player
example: media_player.kitchen_display
emergency:
description: Notify even if the device is in DND Mode.
default: false
selector:
boolean: null
example: 'False'
logbook:
description: Add entry to Log Book
default: true
selector:
boolean: null
example: 'True'
title:
description: Title for permenant notifications
required: true
selector:
text: null
example: Permanent notification Title
mobile:
description: Send Mobile Notification
default: true
selector:
boolean: null
example: 'True'
permanent:
description: Create a permanent notification?
default: false
selector:
boolean: null
example: 'True'
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ notify_alexa }}'
sequence:
- service: notify.alexa_media
data:
title: '{{ title }}'
message: '{{ name }} {{ message }}'
target: '{{ alexa_entities.entity_id }}'
data:
type: announce
method: all
- choose:
- conditions:
- condition: template
value_template: '{{ permanent }}'
sequence:
- service: persistent_notification.create
data:
title: '{{ title }}'
message: '** {{ name }} ** {{ message }}'
- choose:
- conditions:
- condition: template
value_template: '{{ mobile }}'
sequence:
- service: notify.xxx_phone_group
data:
title: '{{ title }}'
message: '{{ name }} {{ message }}'
- choose:
- conditions:
- condition: template
value_template: '{{ logbook }}'
sequence:
- service: logbook.log
data:
name: '{{ name }}'
message: '{{ message }}'
- choose:
- conditions:
- condition: template
value_template: '{{ notify_google_home }}'
sequence:
- service: media_player.play_media
target:
entity_id: |
{{ entities.entity_id }}
data:
media_content_id: >-
media-source://tts/google_translate?message="{{ name | replace("
", "+") }} + {{ message | replace(" ", "+") }}"
media_content_type: provider
metadata:
title: 'Back Door is open '
thumbnail: https://brands.home-assistant.io/_/google_translate/logo.png
media_class: app
children_media_class: null
navigateIds:
- {}
- media_content_type: app
media_content_id: media-source://tts
- media_content_type: provider
media_content_id: >-
media-source://tts/google_translate?message="{{ name |
replace(" ", "+") }}+{{ message | replace(" ", "+") }}"
mode: single
icon: mdi:speaker-wireless
From your field examples: you are passing the echo device entity_id string as alexa_entities, then your target template is trying to extract a non-existent entity_id attribute out of that stringβ¦
I have no experience with google homeβ¦ but it looks like youβre trying to do the same thing i.e. extract a non-existent attribute from the entities string.
Sorry about that. That method worked when I manually entered an entity_id, but I neglected to test it using the selector, which output a dictionary. The following is working for me using the selector:
sequence:
- service: notify.alexa_media
data:
title: '{{ title }}'
target: >
{{ alexa_entities.get("entity_id") }}
message: '{{ name }} {{ message }}'
data:
type: announce
method: all
I donβt know how much you use the yaml editor in the Services tool, but you may want to edit the example field for alexa_entities so that it reflects the correct data type and fills in correctly if you use the βFill Example Dataβ button:
alexa_entities:
description: List of Alexa Players to notify
selector:
target:
entity:
domain: media_player
example: {"entity_id": ["media_player.living_room_dot","media_player.kitchen_display"]}
im still pretty green with this stuff, to use this code do i create a script and paste it in the yaml, then can i call the script in a automation as a notify service or what?
Thank you for your work, wanted to create something similar with multiple notifications and supporting few more integrations. So I modified your script for my needs, you work helped me a lot.
I publish my modified version here, someone might find it useful.
Message Types can be localized to any language (in array and dropdown the strings must be identical)β¦
notify_all:
alias: Script for Notifying multiple devices
description: Send notifications to multiple devices
variables:
message_types: {"Information":"info", "Warning":"warning", "Alert":"error"}
fields:
message_type:
name: "Message type"
required: true
example: warning
selector:
select:
mode: dropdown
options:
- ""
- "Information"
- "Warning"
- "Alert"
title:
name: "Title"
description: Title for notification
required: true
selector:
text: null
example: Notification Title
message:
name: "Message"
description: Message content of the notification.
required: true
selector:
text: null
example: Notifications are awesome
tts_google_entities:
name: "Google TTS Entities"
description: List of Media Players to notify via Google_Translate TTS
selector:
target:
entity:
domain: media_player
example: media_player.kitchen_display
tts_cache:
name: "Cache TTS audio file"
description: Cache the generated audio file for offline use
default: false
selector:
boolean: null
example: 'True'
alexa_entities:
name: "Alexa Entities"
description: List of Alexa Media Players to notify
selector:
target:
entity:
domain: media_player
example: media_player.kitchen_display
kodi:
name: "Kodi"
description: Send notification to KODI TVbox (if online)
default: true
selector:
boolean: null
example: 'True'
enigma:
name: "Enigma"
description: Send notification to Enigma receiver (if online)
default: true
selector:
boolean: null
example: 'True'
pushbullet:
name: "Pushbullet"
description: "Send notification via Pushbullet service"
default: true
selector:
boolean: null
example: 'True'
client:
name: "Client mobile App"
description: Send notification to HA Client mobile App
default: false
selector:
boolean: null
example: 'True'
sms:
name: "SMS"
description: Send SMS notification to cellphone
default: false
selector:
boolean: null
example: 'True'
logbook:
description: Add entry to HA Logbook
name: "Logbook"
default: true
selector:
boolean: null
example: 'True'
persistent:
name: "Persistent"
description: Create HA Persistent notification
default: false
selector:
boolean: null
example: 'True'
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ kodi }}'
- condition: template
value_template: '{{ states.media_player.kodi.state is defined and states.media_player.kodi.state != "off" }}'
sequence:
- service: notify.kodi
data:
title: '{{ title if title != "" else "HA Message"}}'
message: '{{ message }}'
data:
displaytime: 20000
icon: '{{ message_types[message_type] if meessage_type != "" else "info"}}'
- choose:
- conditions:
- condition: template
value_template: '{{ enigma }}'
- condition: template
value_template: '{{ states.media_player.vuplus.state is defined and states.media_player.vuplus.state != "off" }}'
sequence:
- service: notify.enigma
data:
message: '{{ message_type + " - " if message_type != "" }}{{ title + ": " if title != "" }}{{ message }}'
data:
displaytime: "20"
#messagetype: '{{ "\x22" + ((message_types.keys()|list).index(message_type) + 1) | string + "\x22" }}'
#messagetype: '"{{ 1 | string }}"'
messagetype: "1" # only static value works, not sure why templates(above) don't
- choose:
- conditions:
- condition: template
value_template: '{{ sms }}'
- condition: template
value_template: '{{ states.sensor.sms_myphone1.state is defined }}'
sequence:
- service: notify.sms
data:
message: '{{ message_type + " - " if message_type != "" }}{{ title + ": " if title != "" }}{{ message }}'
target: "{{ states('sensor.sms_myphone1') }}"
- choose:
- conditions:
- condition: template
value_template: '{{ persistent }}'
sequence:
- service: persistent_notification.create
data:
title: '{{ message_type + " - " if message_type != "" }}{{ title if title != "" else "HA Message"}}'
message: '{{ message }}'
- choose:
- conditions:
- condition: template
value_template: '{{ logbook }}'
sequence:
- service: logbook.log
data:
name: '{{ message_type + " - " if message_type != "" }}{{ title + ": " if title != "" else "HA Message"}}'
message: '{{ message }}'
- choose:
- conditions:
- condition: template
value_template: '{{ pushbullet }}'
sequence:
- service: notify.notify
data:
title: '{{ message_type + " - " if message_type != "" }}{{ title if title != "" else "HA Message"}}'
message: '{{ message }}'
- choose:
- conditions:
- condition: template
value_template: '{{ client }}'
sequence:
- service: notify.mobile_app_g8441
data:
message: '{{ message_type + " - " if message_type != "" }}{{ title + ": " if title != "" }}{{ message }}'
- choose:
- conditions:
- condition: template
value_template: '{{ tts_google_entities is defined }}'
- condition: template
value_template: '{{ tts_google_entities.get("entity_id") | count > 0 }}'
sequence:
- service: tts.google_say
data:
message: '{{ message_type + "!" if message_type != "" }}{{ title + "..." if title != "" }}{{ message }}'
entity_id: '{{ tts_google_entities.get("entity_id") }}'
language: sk
cache: '{{ tts_cache if tts_cache is defined else "false" }}'
- choose:
- conditions:
- condition: template
value_template: '{{ alexa_entities is defined }}'
- condition: template
value_template: '{{ alexa_entities.get("entity_id") | count > 0 }}'
sequence:
- service: notify.alexa_media
data:
title: '{{ message_type + "!" if message_type != "" }}{{ title + "..." if title != "" }}'
message: '{{ message }}'
target: '{{ alexa_entities.get("entity_id") }}'
data:
type: announce
method: all
mode: single
icon: mdi:speaker-wireless