Grocery List

Ever gotten to the grocery store and realize you forgot your grocery list? Or you just happened to go by the store, but had not gone home first? Never forget the grocery list again. With smart phones we have plenty of methods to organize and maintain our shopping lists, but I decided to take it one step further. I don’t like opening an app to find my list, and I don’t like writing it out in a note editor on my phone (do you know anybody other than a 10 year old that has the right-sized fingers for a phone keyboard?). So how about a sequence that would be able to tell when one of us are at a store (and it can be a specific store), and retrieve a shopping list from Alexa that was then pushed to our phones?

Grocery List

That’s where Node Red and Life360 comes in. This is just a little example of something cool you can do with home automation to make life easier. The hardware requirements can be pretty light for this, just a Raspberry Pi and your phone. In this case, I’m going to use Hubitat, Node-RED, Alexa, and Pushover. See my guide on installing Node-RED to get started with Node-RED if you haven’t installed it before.

Getting started

So, how does it work? You’ll need a few Node-RED connections to start with:

  • Some sort of geofencing application on your phone that has a Node-RED integration or can at least send location events (I use Life360 through Hubitat, but Owntracks with a Geofence node palette also works without a hub)
  • The Alexa Cakebaked node palette
  • A notification handler (i.e. Pushover)

Set up the flow

First up, let’s set up the triggers for your sequence. In my case I use Hubitat to centralize most of my device events. Hubitat has a nice Life360 integration that is native to the device, but I prefer to use a community-based driver written by one of the community members since it pulls all the data from Life360. If you’re not sure what Life360 is, head over to their webpage to check it out. I use it to keep tabs on my better half and to trigger various presence-driven home automations. I promise its not as creepy as that sounds.

Trigger the grocery list

Triggering the grocery list is relatively easy. First, I am using my Life360 presence from Hubitat. Using the custom driver that pulls all attributes from Life360, I have configured the presence node to use “address1” as the trigger attribute. Second, I’ve dropped a switch node to filter out the address. Think of your switch nodes as a filter node; they filter incoming message payloads and send the output based on the message payload. Importantly, realize that while the trigger is sending what we call a message payload, you are interested in the actual value of the payload. Thus, you will have to specify in the switch node that it needs to look for the msg.payload.value in the property field. Likewise, you have to be specific in your place definitions. Because this is essentially visual-based coding, basic coding rules apply: “Food Lion Grocery Store” is not the same as “Food lion grocery store“. Capitalization counts!

  • grocery trigger
  • grocery trigger config
  • grocery presence trigger

Pull the grocery list from Alexa

Alexa grocery list node

Once the flow triggers it will attempt to pull the list from your Amazon Alexa account. To do this, you need the Alexa-cakebaked node palette installed and you will use the Alexa List node. If you haven’t done so already, set up your Alexa account following the directions on the node’s GitHub page. Once authenticated, make sure you have selected your account in the drop-down. With your account selected, next select “Get List Items” and then select which list you want sent.

Transform the grocery list into something readable

grocery list message
Transform sequence

This is the meat of the sequence: turning the list into something you can actually read. When the list is first sent, it dumps out everything you’ve ever added as an array. An array is a data structure that stores a collection of data elements of the same type; in this case a list.

Split the array

First, we split the array using a split node. I’ll be honest, I have no idea how this works. I had some help from the forum over at Hubitat to get this working. However, I do know that this node splits each data element in an array to a separate message. Now, instead of a massive array of one payload we have separate messages containing the information of each data element.

grocery split node
Split Node

Filter out completed items

Next, we need to filter out items that have already been checked off. When we split the array we split each data element out; each element has several pieces of information. When you check off an item in Alexa, it is marked “complete”. Since you don’t want your list to include everything you have already bought, we need to filter those out. Using a switch node, we tell the sequence to pass along only the items marked “not complete”. This information is passed along in the msg.payload.completed property as a Boolean (true/false) value. Therefore, in the switch node we define the property as msg.payload.completed and we only want it passed along if it is false.

grocery switch completed items
Filter Completed

Set the payload

Continuing, we now want to only get the actual value of the message. We have split the array and only passed along incomplete items. Each element contains the item we want (e.g. “cereal”), plus some other information. We are only interested in the actual item, not the information Alexa uses to categorize and store each item. Using a change node, we set the message payload (the entire block of passed data) to only the msg.payload.value property (the actual name of our items).

grocery set message payload
Change node

Join the items into one message

Wrapping up, we need to take each item we have split and filtered and combine it into a nice list. Again, I haven’t the foggiest idea on how to get the specific details for this node since I had help from the community forum. That being said, what this node does is take each payload, creates a text (or string) message, and passes it along after a set period of time. As I found out the hard way, you need to specify a timeout in the join node or it will not pass the payload. For this purpose, 2 seconds is more than enough.

grocery join node
Join node

Give the message a title

This node is easy: we’re simply giving the message a title so you know what it is when you get the notification. Using a change node, we are adding a topic to the payload by setting the msg.topic property to anything you want (i.e. “Grocery List”).

grocery message topic
Message Topic

Send ‘er off

Finally…send the list as a notification or SMS message. I use Pushover as a notification service since it has a Hubitat integration and Node-RED integration, but you can use any service with a Node-RED palette. As a tip, I have the Pushover node configured and embedded as a subflow so that I don’t have to set the API key and User Key each time I need a notification sent via the Pushover node.

grocery notification handler
pushover grocery list

Wrapping it up

Now that we’ve set up the above sequence, we’ll never forget the grocery list again. A couple of tips to iron out a few last bugs: first, you may need to watch the address or location name as it comes through on your location integration. It took me a few tries to get the switch node set right to pass the correct trigger location along because I didn’t know exactly how the address was being passed out of the location node. Second, if the store is particularly large (i.e. Walmart), you may want to add a cancel sequence in before the switch node. I’ve noticed that our Walmart displays a couple of addresses, and you don’t want the list being sent multiple times just because you’ve walked from one end of the store to the other. Lastly, don’t forget to tell Alexa to check off your items! This is (currently) a one-way integration, so unless you remember to tell Alexa that you got everything, she’ll keep sending it until you mark those items off.

** Update 4/19/21 (Alexa-remote2 to Alexa-cakebaked)

Zack
Author: Zack

Pharmacist, tech guy, pianist, lover of beer, gamer, beach bum. Probably missed something. Just assume I'm into a little bit of everything.

Categories:

Comments are closed