From 93f22e689ae84b8918b69561ab57273ca1fac300 Mon Sep 17 00:00:00 2001 From: thoscut Date: Thu, 1 Nov 2018 09:49:28 +0100 Subject: [PATCH] Add message template support for alert component (#6859) * Add problem text to alert message if available * Revert "Add problem text to alert message if available" This reverts commit 78ba3a59a736db98d49feac0a0d5cf9381c16489. * Revert "Added info about templates (#6554)" as no template support is available for name or done_message. This reverts commit dfda4b3324e4e6dbbc82a300b0f295d8c0b0a0d0. * Add message template support for alert component documentation --- source/_components/alert.markdown | 46 ++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/source/_components/alert.markdown b/source/_components/alert.markdown index 033cd918873..5c97d5cf4a1 100644 --- a/source/_components/alert.markdown +++ b/source/_components/alert.markdown @@ -51,15 +51,9 @@ alert: {% configuration %} name: - description: The friendly name of the alert. This can include a [template][template]. + description: The friendly name of the alert. required: true type: string -done_message: - description: > - A message sent after an alert transitions from `on` to `off`. Is only sent - if an alert notification was sent for transitioning from `off` to `on`. This can include a [template][template]. - required: false - type: string entity_id: description: The ID of the entity to watch. required: true @@ -87,6 +81,19 @@ skip_first: required: false type: boolean default: false +message: + description: > + A message to be sent after an alert transitions from `of` to `on` + with [template][template] support. + required: false + type: template +done_message: + description: > + A message sent after an alert transitions from `on` to `off` with + [template][template] support. Is only sent if an alert notification + was sent for transitioning from `off` to `on`. + required: false + type: template notifiers: description: "List of `notification` components to use for alerts." required: true @@ -192,4 +199,29 @@ following notification. For example, if the garage door opens at 2:00, a notification will be sent at 2:15, 2:45, 3:45, 4:45, etc., continuing every 60 minutes. +### {% linkable_title Message Templates %} + +It may be desirable to have the alert notifications include information +about the state of the entity. +The following will show for a plant how to include the problem `attribute` +of the entity. + +```yaml +# Example configuration.yaml entry + office_plant: + name: Plant in office needs help + entity_id: plant.plant_office + state: 'problem' + repeat: 30 + can_acknowledge: True + skip_first: True + message: "Plant {{ states.plant.plant_office }} needs help ({{ state_attr('plant.plant_office', 'problem') }})" + done_message: Plant in office is fine + notifiers: + - ryans_phone + - kristens_phone +``` + +The resulting message could be `Plant Officeplant needs help (moisture low)`. + [template]: /docs/configuration/templating/