notify_user.yaml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # - service: script.notify_users
  2. # data_template:
  3. # title: "It's {{ first_name }}'s birthday!"
  4. # users:
  5. # - notify.owners
  6. # message: >-
  7. # It is {{ full_name }}'s birthday today. {% if age is not none %}
  8. # {{- first_name }} is turning {{ age }} years.
  9. # {% endif %}
  10. # Send them a text and say <b>Happy Birthday!</b> to let them know that you appriciate them! :)
  11. # data_object:
  12. # tag: "birthday-notification-{{ context.id }}-{{ first_name | upper }}"
  13. # group: "birthday-notifications"
  14. # color: "#A83285"
  15. # icon_url: "https://home-assistant.kgv14.dev:8123/local/entities/birthday-cake.png"
  16. # actions:
  17. # - action: "{{ action_sms }}"
  18. # title: "Send SMS"
  19. # - wait_for_trigger:
  20. # platform: event
  21. # event_type: mobile_app_notification_action
  22. # event_data:
  23. # action: "{{action_sms}}"
  24. # timeout:
  25. # hours: 24
  26. # - choose:
  27. # conditions: "{{ wait.trigger is not none and wait.trigger.event.data.action == action_sms }}"
  28. # sequence:
  29. # service: notify.owners
  30. # data:
  31. # message: command_activity
  32. # title: "sms:{{ phone_number }}?body=Gratulere med {{ age|string + 'års ' if age is not none else '' }}dagen {{first_name}}!"
  33. # data:
  34. # tag: "android.intent.action.SENDTO"
  35. # default:
  36. # service: notify.owners
  37. # data:
  38. # message: clear_notification
  39. # data:
  40. # tag: "birthday-notification-{{ context.id }}-{{ first_name | upper }}"
  41. blueprint:
  42. domain: script
  43. name: Notify user
  44. description: >-
  45. Notify a user
  46. input:
  47. notify_devices:
  48. name: "Device(s) to notify"
  49. selector:
  50. entity:
  51. multiple: true
  52. default: []
  53. title:
  54. name: "Title"
  55. selector:
  56. text:
  57. multiline: false
  58. default: ""
  59. message:
  60. name: "Message"
  61. selector:
  62. text:
  63. multiline: true
  64. data:
  65. name: "Data object"
  66. selector:
  67. object:
  68. default: {}
  69. tts:
  70. name: "TTS"
  71. selector:
  72. boolean:
  73. default: "{{ false }}"
  74. mode: parallel
  75. variables:
  76. devices_input: !input notify_devices
  77. devices: >-
  78. {% set devices = namespace(entity=[]) %}
  79. {% for device in (
  80. devices_input if devices_input is iterable and (
  81. devices_input is not string and devices_input is not mapping
  82. ) else [ devices_input ]
  83. ) if device.startswith('notify.') or device.startswith('group.') %}
  84. {% if device.startswith('group.') %}
  85. {% for group_device in state_attr(device, 'entity_id') if group_device.startswith('notify.') %}
  86. {% set devices.entity = devices.entity + [ group_device ] %}
  87. {% endfor %}
  88. {% else %}
  89. {% set devices.entity = devices.entity + [ device ] %}
  90. {% endif %}
  91. {% endfor %}
  92. {{ devices.entity }}
  93. title: !input title
  94. message: !input message
  95. data: !input data
  96. tts: !input tts
  97. actions: >-
  98. {% set actions = namespace(name=[]) %}
  99. {% for action in (data.actions if 'actions' in data else []) %}
  100. {% set actions.name = actions.name + [ action.action ] %}
  101. {% endfor %}
  102. {{ actions.name }}
  103. tag: "tag-{{ this.context.id }}"
  104. sequence:
  105. - service: system_log.write
  106. data:
  107. level: warning
  108. message: >-
  109. Notify-devices:
  110. - {{ devices_input|join("\n\n - ") }}
  111. Devices:
  112. - {{ devices|join("\n\n - ") }}
  113. Data: {{ data }}
  114. Actions: {{ actions }}
  115. - repeat:
  116. for_each: "{{ devices }}"
  117. sequence:
  118. - variables:
  119. tag: "{{ tag }}-{{ repeat.index }}"
  120. - if: "{{ tts }}"
  121. then:
  122. alias: "Send TTS"
  123. service: "{{ repeat.item }}"
  124. data:
  125. title: "{{ title if title.strip()|length > 0 else message|truncate(50, true) }}"
  126. message: "TTS"
  127. - alias: "Send notification"
  128. service: "{{ repeat.item }}"
  129. data:
  130. title: "{{ title if title.strip()|length > 0 else '' }}"
  131. message: "{{ message }} {{ tag }}"
  132. data: >-
  133. {{ data }}