{"id":13666,"date":"2024-02-21T18:27:23","date_gmt":"2024-02-21T18:27:23","guid":{"rendered":"https:\/\/www.rjt.org.uk\/home\/?post_type=home_assistant_tip&#038;p=13666"},"modified":"2025-03-16T17:34:34","modified_gmt":"2025-03-16T17:34:34","slug":"using-a-to-do-list-for-messages","status":"publish","type":"home_assistant_tip","link":"https:\/\/www.rjt.org.uk\/home\/archives\/home-assistant-tip\/using-a-to-do-list-for-messages\/","title":{"rendered":"Using a To-Do List for Messages"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>Adding a message is as simple as calling the todo,additem service call.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">service: todo.add_item\ndata:\n  item: Title\n  description: Description\ntarget:\n  entity_id: todo.messages\n<\/pre>\n\n\n\n<p>The next challenge was to get a compact view on the dashboard as the standard To-Do list is very large.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"776\" height=\"164\" src=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image.png\" alt=\"\" class=\"wp-image-13667\" style=\"width:256px;height:auto\" srcset=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image.png 776w, https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-300x63.png 300w, https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-150x32.png 150w, https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-768x162.png 768w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><\/a><figcaption class=\"wp-element-caption\">No outstanding messages<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"782\" height=\"376\" src=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-1.png\" alt=\"\" class=\"wp-image-13668\" style=\"width:257px;height:auto\" srcset=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-1.png 782w, https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-1-300x144.png 300w, https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-1-150x72.png 150w, https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2024\/02\/image-1-768x369.png 768w\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" \/><\/a><figcaption class=\"wp-element-caption\">with a message,  note the red icon <\/figcaption><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">type: vertical-stack\ncards:\n  - type: custom:mushroom-template-card\n    primary: |-\n          {{states('sensor.date_full_format')}}\n          {{states('sensor.time')}}\n    secondary: >-\n      {%- from 'easy_time.jinja' import  easy_time %}\n      {%- from 'tools.jinja' import days_till, time_of_day -%}Good\n      {{time_of_day()}}.\n      {%- set count =\n      state_attr('sensor.downloads','number_of_files')|int %}\n      {%- if count > 0 %}\n      {%- for file in state_attr('sensor.downloads','file_list') %}      \n      \n      ({{loop.index}}) Voicemail - \n      {%- set datestring = file | replace(\"\/media\/downloads\/voicemail-\",'')|\n      replace('.mp3','') %}\n      {%- set fmat = \"%Y%m%d%H%M%S\" %}\n      {%- set datetime = strptime(datestring, fmat) | as_local %}\n      {{- ' '}}{{easy_time(datetime)}} ago \n      {%- endfor %}\n      {%- endif %}\n    icon: mdi:message\n    tap_action:\n      action: call-service\n      service: input_boolean.turn_off\n      target:\n        entity_id: input_boolean.notify_light\n      data: {}\n    badge_icon: ''\n    icon_color: |-\n      {% if states('todo.messages') | int  > 0 %}red{% endif %}\n    entity: todo.messages\n    multiline_secondary: true\n  - type: conditional\n    conditions:\n      - condition: numeric_state\n        entity: todo.messages\n        above: 0\n    card:\n      type: todo-list\n      entity: todo.messages\n      card_mod:\n        style:\n          .: |\n            ha-card.type-todo-list div.header {\n              display: none;\n            }\n            ha-card.type-todo-list .addRow {\n              display: none;\n            }\n            ha-card.type-todo-list div.divider {\n              display: none;\n            }\n            ha-card.type-todo-list mwc-list#checked {\n              display: none;\n            }\n          ha-check-list-item$: |\n            mwc-checkbox {\n              display: none;\n            }<\/pre>\n\n\n\n<p>The next job was to update the <a href=\"https:\/\/www.rjt.org.uk\/home\/archives\/home-assistant-tip\/extracting-voicemails-from-email\/\" data-type=\"home_assistant_tip\" data-id=\"13550\">Voicemail automation<\/a> and <em>Rubbish automation<\/em> to use the new messages.   Then to change the phone and tablet charging routine to send and clear messages when needed.<\/p>\n\n\n\n<p>When new messages arrive we need to be able to see them.   So I have a couple of automations to handle that.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Send Notification when items added to to do list such as Messages or Shopping<\/h4>\n\n\n\n<p>This will send a standard notify.notify message each time something is added to any To Do list.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">alias: >-\n  Send Notification when items added to to do list such as Messages or Shopping\n  List.\ndescription: Lists can include any todo list such as Messages or Shopping List\ntrigger:\n  - platform: event\n    event_type: call_service\n    event_data:\n      domain: todo\n      service: add_item\n    variables:\n      date: \"{{now().strftime(' %A %d\/%m at %H:%M')}}\"\n      list_name: >\n        {{ state_attr((trigger.event.data.service_data.entity_id)[0],\n        'friendly_name') }}\n      item: \"{{ trigger.event.data.service_data.item | title }}\"\n      description: \"{{ trigger.event.data.service_data.description}}\"\n      user_name: >\n        {% set uid = trigger.event.context.user_id %}\n\n        {% set user = None %}\n\n        {% set matching_users = states.person | selectattr('attributes.user_id',\n        '==', uid) | list %}\n\n        {% set user = matching_users | first if matching_users | length > 0 else\n        \"Jarvis\" %}\n\n        {{ user if user == \"Jarvis\" else\n        state_attr(user.entity_id,\"friendly_name\") }}\ncondition: []\naction:\n  - service: notify.notify\n    data:\n      title: \"{{list_name}}: {{item}}\"\n      message: |\n        {{description}}\n           - added by {{user_name}} on {{date}}.\nmode: single\n<\/pre>\n\n\n\n<p>This turns on the Warning Light in the Living Room when there are outstanding messages and the Living room becomes occupied.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">alias: Turn notify light when a new message arrives\ndescription: >-\n  This can be enhanced to turn on light for other reasons.  It should only turn\n  on once the Family is Home.\ntrigger:\n  - platform: state\n    entity_id:\n      - binary_sensor.living_room_occupied\n    to: \"on\"\n  - platform: state\n    entity_id:\n      - todo.messages\ncondition:\n  - condition: state\n    state: \"on\"\n    entity_id: binary_sensor.living_room_occupied\naction:\n  - if:\n      - condition: numeric_state\n        entity_id: todo.messages\n        above: 0\n    then:\n      - service: input_boolean.turn_on\n        data: {}\n        target:\n          entity_id: input_boolean.notify_light\n    else:\n      - service: input_boolean.turn_off\n        target:\n          entity_id: input_boolean.notify_light\n        data: {}\n    alias: If there are messages turn on flasher else turn off\nmode: single\n<\/pre>\n\n\n\n<p>In all I have around a dozen automations which now send messages this way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using a web hook to process internal messages from other servers<\/h2>\n\n\n\n<p>In addition to Home Assistant I have several other servers on Proxmox which are monitored by using <a href=\"https:\/\/github.com\/louislam\/uptime-kuma\">Update Kuma<\/a>.   This can call a web hook so I have an internal message hook which takes the payload and then uses the standard messaging to pass it on.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">alias: New Internal Message\ndescription: \"\"\nmode: single\ntriggers:\n  - allowed_methods:\n      - POST\n      - PUT\n      - GET\n    local_only: false\n    webhook_id: internalmessage\n    trigger: webhook\nconditions: []\nactions:\n  - metadata: {}\n    data:\n      title: Internal message\n      action: create_message\n      message: \"{{trigger.json.message}} {{trigger.json.msg}} \"\n    action: script.messages_update<\/pre>\n","protected":false},"template":"","class_list":["post-13666","home_assistant_tip","type-home_assistant_tip","status-publish","hentry","comments-off"],"_links":{"self":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip\/13666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip"}],"about":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/types\/home_assistant_tip"}],"wp:attachment":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/media?parent=13666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}