Open to-do list as a notification with action buttons

After today’s release of Home Assistant I wrote up this little notification. It shows you how much unchecked boxes there are in a given grocery list in the notification and a handy link to a lovelace dashboard containing the grocery list as a full panel view.

service: notify.mobile_app_nothing_phone_1
data:
  message: >-
    There {% if states('todo.boodschappenlijstje') | int < 2 %} is{%else%}
    are{%endif%} {{ states('todo.boodschappenlijstje')}} {% if
    states('todo.boodschappenlijstje') | int < 2 %} product{%else%}
    producten{%endif%} left on the grocery list.
  title: Brian is at the supermarket
  data:
    actions:
      - action: URI
        title: Open grocery list
        uri: /lovelace-home/grocerylist

Combine this with a zone automation (eg. entering the local supermarket) and send this notification to your partner.

9 Likes

I am very new to templates and coding in Yaml how would you go about adding a condition so the notification isn’t sent when the list has 0 open items?

I am also new to this, but I think the answer to your question is to check the number of items in the list as a condition when triggering the automation. Each automation has:

  • Trigger
  • Conditions (optional)
  • Actions

The YAML above just shows the Action part which is to call the notify service.

The entire automation might look like:

alias: Zone Based Automation
description: ""
trigger:
  - platform: geo_location
    source: person
    zone: zone.market
    event: enter
condition:
  - condition: numeric_state
    entity_id: todo.shoppinglist
    above: 0
action:
  - service: notify.mobile_app_nothing_phone_1
    data:
      message: >-
        There {% if states('todo.shoppinglist') | int < 2 %} is{%else%}
        are{%endif%} {{ states('todo.shoppinglist')}} {% if
        states('todo.shoppinglist) | int < 2 %} product{%else%}
        products{%endif%} left on the grocery list.
      title: At the supermarket
      data:
        actions:
          - action: URI
            title: Open grocery list
            uri: /lovelace-home/shoppinglist
mode: single

With the above YAML the condition will prevent the message from being sent if the shopping list is zero length. NOTE: I have never used the geo_location trigger, so that part of the YAML may need changes.

That is not how the Geolocation trigger works… you want a Zone trigger.

I’ll switch to using a zone trigger as suggested but right now, I’m focused on the actual notification part. Every time I click the notification using the code posted (modified to point at MY phone and referencing MY shopping list), HA TRIES to load but says it’s not available. The same as I get if the connection to the server fails for some reason.

BUT if I change the uri to include the IP address and port number, HA does load but it shows my default dashboard j instead of the shopping list.

This is the action portion of my notification (as shown, tapping the notification shows the default dashboard):

data:
  message: >-
    There {% if states('todo.walmart_shopping_list') | int < 2 %} is{%else%}
    are{%endif%} {{ states('todo.walmart_shopping_list')}} {% if
    states('todo.walmart_shopping_list') | int < 2 %} product{%else%}
    products{%endif%} left on the grocery list.
  title: At the supermarket
  data:
    actions:
      - action: URI
        title: Open grocery list
        uri: 10.20.0.2:8123/lovelace-home/walmart_shopping_list
action: notify.mobile_app_pixel_9_pro_xl

This code results in the screen shown below in the screenshot:

data:
  message: >-
    There {% if states('todo.walmart_shopping_list') | int < 2 %} is{%else%}
    are{%endif%} {{ states('todo.walmart_shopping_list')}} {% if
    states('todo.walmart_shopping_list') | int < 2 %} product{%else%}
    products{%endif%} left on the grocery list.
  title: At the supermarket
  data:
    actions:
      - action: URI
        title: Open grocery list
        uri: /lovelace-home/walmart_shopping_list
action: notify.mobile_app_pixel_9_pro_xl

Lastly, this is the shopping list in question:

Everything you have described sounds like you are trying to open an address that doesn’t exist… there have been significant changes to the Shopping List/ToDo integrations since the original post on this thread, so that address/format may not be valid anymore. The uri you are using does not look like the one I see on my instance, you should check the actual address on yours… the following works for me:

action: notify.mobile_app_pixel_9_pro_xl
data:
  message: >-
    {% set state = states('todo.walmart_shopping_list') %}
    There {{ 'is' if state == '1' else 'are'}} {{ state }} product{{- 's' if state != '1' }} left on the grocery list.
  title: At the supermarket
  data:
    actions:
      - action: URI
        title: Open grocery list
        uri: /todo?entity_id=todo.walmart_shopping_list
1 Like

Thanks. I’ll try that. I thought the the same thing about it seeming like a bad URI issue. But I couldn’t find any place that tells me what the correct URI is for a particular list.

Thanks! That worked. The only thing left is that when I tap the notification, it doesn’t go away – I have to manually swipe it away. Is there a way to force it to go away when HA opens the list?