Conditional notification (notify)

I was actually planning on making a post about using this notifier group hack for use with the Alert integration. It’s the only way I’ve found to harness the variable repeat interval and “done message” functions of the alerts while still being able to apply conditional logic so that they are routed to an appropriate output or to insert other actions such as applying volume control to alerts being sent to TTS devices.

FWIW, you can also use an empty set as the value for services:

notify:
  - platform: group
    name: tts_alerts
    services: []
Alert Example
##configuration.yaml
alert:
  cpu_temp:
    name: Alert Hot CPU
    message: "The CPU has reached {{ states('sensor.cpu') }} degrees"
    done_message: CPU is now below 70 degrees
    entity_id: binary_sensor.cpu_above_70
    state: "on"
    repeat: 10
    can_acknowledge: true
    skip_first: false
    notifiers:
      - tts_alerts 
      - mobile_app_d

Automation:

alias: Only Alerts
description: 'Turn volume up, Play message from "tts_alerts", turn volume down'
trigger:
  platform: event
  event_type: call_service
  event_data:
    domain: notify
    service: tts_alerts
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      entity_id:
        - media_player.1
        - media_player.2
  - delay: 2
  - service: notify.your_tts_service_or_tts_notifier_group
    data:
      message: '{{trigger.event.data.service_data.message}}'
  - alias: "Wait for tts to finish"
    wait_for_trigger:
    - platform: state
      entity_id: media_player.1
      from: "playing"
      to: "idle"
  - service: media_player.volume_set
    data:
      volume_level: 0.3
    target:
      entity_id:
        - media_player.1
        - media_player.2

Credit where it is due, I first found out about this hack from this post from 2019 by @pnbruckner

1 Like