How to Trigger Smart Home Automations with Notion & Webhooks

Did you know that you can use webhooks to trigger automations? While webhooks aren't new, using them in creative ways can unlock powerful results. In this post, I'll show you how to harness Notion and Node-RED to trigger automations, either within your smart home or directly inside Notion.

What You’ll Need:

1. Notion– A powerful note-taking tool that can create databases, buttons, links, and more.

2. Node-RED – A flow-based tool for wiring together devices, APIs, and online services. Though I use it with Home Assistant, you don't need Home Assistant for this automation.

What Are Webhooks?

Webhooks are simple: they are URLs that trigger actions on a server when accessed. Think of them as links that can spark automation. For this tutorial, we'll create custom webhooks that, when activated, will trigger actions on Node-RED that can affect your Notion database or smart home.

Learn to create links in notion to trigger automations built using node red

Step 1: Setting Up Webhooks in Notion

Notion allows you to create links that point to custom URLs. These URLs are webhooks that will trigger specific actions on your Node-RED server. For example, when you click a link in Notion, it can start an automation on your smart home system or even perform actions within Notion itself, like transcribing audio or summarizing content on a page.

To do this, you'll create a link in Notion with the URL set to a specific endpoint on your Node-RED server. Simply select the text you want to convert into a link and click the “add link” icon. A popup window should appear where you an input the IP address and designated endpoint of your Node-RED server. The IP address will typically be the IP address of the computer the server is on at port 1880. So for example if the computer Node-RED is on has the IP address of 10.0.0.41 then the full link would be http://10.0.0.41:1880/testendpoint. (for this tutorial i will be using test_endpoint as the endpoint to trigger automations)

Step 2: Automating with Node-RED

Within Node-RED, you can set up various automations to take advantage of Notion's features. For example, you could create an automation that updates Notion with additional context, such as transcribing audio or summarizing the contents of a page. This setup allows you to use your own AI models, such as LLaMA, rather than relying on third-party services like GPT.

To create an webhook, use the HTTP IN node and double click into it. Set the url to test_endpoint and the the method as GET. Add a debug node and an HTTP Response node and connect both to the HTTP In node. Double click into the Debug node and set the Output to “Complete msg object”. The debug node will be used to see the output from the HTTP In node when we trigger it while the HTTP Response node ensures that the connect properly closes. To test it click the link in Notion. This should open up a webpage which is a side-effect of clicking hyperlinks in Notion. If you check Node Red you should see a debug message from the action you took in Notion.

Step 3: Creating Webhook Links Automatically

Manually creating webhook links in Notion can be tedious. To streamline this, I’ve built an automation in Node-RED that updates any Notion document with dynamic links. These links trigger automations on your Node-RED server, making it easy to control everything programmatically without repetitive manual setup.

Understanding the Automation Flow

To explain how this works, there are a few key nodes in Node-RED:

  1. Trigger Node: This node starts the automation, triggered by anything you choose—pressing a button in Home Assistant, using an Inject node, or hitting a webhook from Notion.

  2. Query Function Node: This node filters for the Notion documents you want to update. It checks specific properties in the Notion database, such as whether a checkbox is marked as "true" and whether the document is marked as "not started."

  3. Notion Node (Query Database: This node connects to your Notion database using the information passed from the previous nodes. It pulls all the relevant page IDs from the database, so you can update each one.

  4. Get Page Id: Gathers all the page ids from the documents passed from the previous node. This is to help the split node fire with only the information needed.

  5. Split Node: For each page ID, the Split node runs the subsequent flow for each blockId in the array passed by the previous node.

  6. Function Node (Link Creation): This node creates the payload Notion needs to create the webhook links.

  7. Notion Node (Append block): Uses the payload provided by the previous node and adds the content to the page with the given block id.

When you click one of these links in Notion, it passes a block ID back to Node-RED, which uses this ID to identify which page triggered the action. From there, the automation will update the page with the new data.

Wrapping Up

By combining Notion and Node-RED, you can create dynamic automations that span both your smart home and your productivity tools. The flexibility of webhooks allows you to trigger all kinds of actions with just a click of a button, whether you're updating documents, controlling your home, or processing data.

If you're ready to take your automation skills to the next level, check out my YouTube video, where I walk you through this setup in more detail and demonstrate it in action. I'll also include the Node-RED code, so you can try it yourself!

Previous
Previous

100% FREE & LOCAL Transcription

Next
Next

Transcription Automation using GPT and Node-Red