Using a To-Do List for Messages

Home Assistant Automation

I first created a new To-Do list called todo.messages. This will receive any Messages which need to be sent to users and displayed on the dashboard. It was simply created on the Helpers tab in Devices.

Adding a message is as simple as calling the todo,additem service call.

service: todo.add_item
data:
  item: Title
  description: Description
target:
  entity_id: todo.messages

The next challenge was to get a compact view on the dashboard as the standard To-Do list is very large.

The display simply shows a greeting when there are no outstanding messages. When there is one or more messages it shows the messages so they can be ticked off when complete.

No outstanding messages
with a message, note the red icon
type: vertical-stack
cards:
  - type: custom:mushroom-template-card
    primary: |-
          {{states('sensor.date_full_format')}}
          {{states('sensor.time')}}
    secondary: >-
      {%- from 'easy_time.jinja' import  easy_time %}
      {%- from 'tools.jinja' import days_till, time_of_day -%}Good
      {{time_of_day()}}.
      {%- set count =
      state_attr('sensor.downloads','number_of_files')|int %}
      {%- if count > 0 %}
      {%- for file in state_attr('sensor.downloads','file_list') %}      
      
      ({{loop.index}}) Voicemail - 
      {%- set datestring = file | replace("/media/downloads/voicemail-",'')|
      replace('.mp3','') %}
      {%- set fmat = "%Y%m%d%H%M%S" %}
      {%- set datetime = strptime(datestring, fmat) | as_local %}
      {{- ' '}}{{easy_time(datetime)}} ago 
      {%- endfor %}
      {%- endif %}
    icon: mdi:message
    tap_action:
      action: call-service
      service: input_boolean.turn_off
      target:
        entity_id: input_boolean.notify_light
      data: {}
    badge_icon: ''
    icon_color: |-
      {% if states('todo.messages') | int  > 0 %}red{% endif %}
    entity: todo.messages
    multiline_secondary: true
  - type: conditional
    conditions:
      - condition: numeric_state
        entity: todo.messages
        above: 0
    card:
      type: todo-list
      entity: todo.messages
      card_mod:
        style:
          .: |
            ha-card.type-todo-list div.header {
              display: none;
            }
            ha-card.type-todo-list .addRow {
              display: none;
            }
            ha-card.type-todo-list div.divider {
              display: none;
            }
            ha-card.type-todo-list mwc-list#checked {
              display: none;
            }
          ha-check-list-item$: |
            mwc-checkbox {
              display: none;
            }

The next job was to update the Voicemail automation and Rubbish automation to use the new messages. Then to change the phone and tablet charging routine to send and clear messages when needed.

When new messages arrive we need to be able to see them. So I have a couple of automations to handle that.

Send Notification when items added to to do list such as Messages or Shopping

This will send a standard notify.notify message each time something is added to any To Do list.

alias: >-
  Send Notification when items added to to do list such as Messages or Shopping
  List.
description: Lists can include any todo list such as Messages or Shopping List
trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: todo
      service: add_item
    variables:
      date: "{{now().strftime(' %A %d/%m at %H:%M')}}"
      list_name: >
        {{ state_attr((trigger.event.data.service_data.entity_id)[0],
        'friendly_name') }}
      item: "{{ trigger.event.data.service_data.item | title }}"
      description: "{{ trigger.event.data.service_data.description}}"
      user_name: >
        {% set uid = trigger.event.context.user_id %}

        {% set user = None %}

        {% set matching_users = states.person | selectattr('attributes.user_id',
        '==', uid) | list %}

        {% set user = matching_users | first if matching_users | length > 0 else
        "Jarvis" %}

        {{ user if user == "Jarvis" else
        state_attr(user.entity_id,"friendly_name") }}
condition: []
action:
  - service: notify.notify
    data:
      title: "{{list_name}}: {{item}}"
      message: |
        {{description}}
           - added by {{user_name}} on {{date}}.
mode: single

This turns on the Warning Light in the Living Room when there are outstanding messages and the Living room becomes occupied.

alias: Turn notify light when a new message arrives
description: >-
  This can be enhanced to turn on light for other reasons.  It should only turn
  on once the Family is Home.
trigger:
  - platform: state
    entity_id:
      - binary_sensor.living_room_occupied
    to: "on"
  - platform: state
    entity_id:
      - todo.messages
condition:
  - condition: state
    state: "on"
    entity_id: binary_sensor.living_room_occupied
action:
  - if:
      - condition: numeric_state
        entity_id: todo.messages
        above: 0
    then:
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.notify_light
    else:
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.notify_light
        data: {}
    alias: If there are messages turn on flasher else turn off
mode: single

In all I have around a dozen automations which now send messages this way.