A sensor that shows the latest notification and hold the history of notifications

You can st this up this yourself. I keep a log of all TTS messages that are played. Basically so I can repeat the last message if I missed it. You can do the same thing for notifications.

Set up the file notify platform:

notify:
  - platform: file
    name: "TTS History"
    filename: /config/www/tts_history.txt
    value_template: "{{ value_json }}"

And a sensor to read the notification file:

  - platform: file
    name: "TTS Last Message"
    file_path: /config/www/tts_history.txt last line of that text file.

Then when you send a notification, also “notify” the file to write whatever data you want to log to the file.

    - service: notify.tts_history
      data:
        message: "{{ (now() ~ ' ' ~ message)[0:250]|replace('\n',' ') }}"

And here is where I read the last line and replay the message. The text file retains all of the historical messages until you delete them, but the file sensor contains only the last line.

    - service: script.tts_play
      data:
        message: >
          {% set message = states('sensor.tts_last_message')[33:255] %}
          {% set time = as_datetime(states('sensor.tts_last_message')[0:32]).strftime('%-I:%M %p') %}
          {{ message }} at {{ time }}
        tts_service: tts.cloud_say
        media_player: media_player.kiosk_internal_player
        quiet_play: true
        night_play: true
        ignore_away: true

It would be cool to have it built in for notifications though, and my solution would only show the last one so ya got my vote.

1 Like