Unleash the Power of SmartThings with Advanced Automations Using Node-Red

1. Introduction

I had been using SmartThings for many years and out-grown what I could automate with SmartThings Routines and Rules, so started looking at how to implement more advanced automations.

After reviewing the SmartThings Apps feature, I concluded that it was not for me. The process seems convoluted and the requirement for me to provide a web endpoint, open to the internet was a shop stopper.

So I investigated alternatives and discovered a great way to build advanced automations which, run locally, are simple to build and importantly does not require me to open up my home network to the internet.

I thought others SmartThings users would be interested in the approach.

I now build all my advanced automations using this method and tools as they are: quick to build and maintain, run on my home network and enable me to develop any automation idea, however complex.

2. Here’s how I build my Advanced Automation.

An Advanced Automation consists of two parts.

image

Trigger

The first part of the advanced automation defines WHEN the Automation will be initiated. E.g. when a switch is turned on, or a button is pressed, or when it is manually initiated from the SmartThings App.

A set of one or more Triggers are built by creating a SmartThings Routine using the SmartThings App. Assuming you are using local edge drivers, the SmartThings Routine runs locally on your SmartThings Hub.

When the trigger conditions are met, the SmartThings routine sends a HTTP

requests, using Todd Austin’s Web Requester edge driver, to initiate

an Automation running locally on a separate, always-on, dedicated Automation Box.

Automation

The second part of the advanced automation defines the sequence of actions that are executed when the trigger event is raised.

The Automation is built with the Node-RED tool and the SmartThings Node-RED library, published by Samsung, for interacting with SmartThings devices.

3. Examples

3.1 Motion Sensor Controlled Lighting

Description

This is a very simple example which turns the kitchen lights on when motion is detected and turns them off when motion is no motion is detected. This automation is simple enough to be implemented with just a couple of SmartThings Routines. It is included here to demonstrate the architecture of Advanced Automations.

WHEN Triggers

image

image

DO Automation

image

3.2 Smart Lounge Lighting

Description

This is a slightly more advanced automation example that controls the lounge lighting using a simple button.

Clicking the button incrementally raises the light levels from 0% to 3%, then to 25%, then to 50%, then to 100%.

Double Clicking on the button turns the lights off.

Holding the button turns the lights to 100%

WHEN Triggers

image

image

image

DO Automation

image

5. Why Node-RED?

I have found Node-RED to be an excellent tool for developing and running Advanced Automation. The key benefits are:

  • Simple to build using graphical editor
  • Open platform
  • Powerful library of standard node functionality
  • Unlimited extensibility via JavaScript
  • Easy to use external Internet APIs
  • The ability to develop IOT dashboards
  • Node-RED is a mature tool.
  • The project was initiated in 2013 and is now on release 3.1
  • Node-RED is actively being enhanced
  • Large active community
  • Google yields answers to common questions
  • It is used extensively for industrial IOT

6. Automation Box

The key pre-requisite to harnessing the potential of Advanced Automations is to get yourself an Automation Box.

This article describes how to install node-red on a Raspberry Pi.

10 Likes

Excellent write up, thank you. :sunglasses:

We should probably add that Node-Red is not part of the official SmartThings platform.

From the official definition

Node-RED is a flow-based, low-code development tool for visual programming developed originally by IBM for wiring together hardware devices, APIs and online services as part of the Internet of Things.

Since its original development, IBM contributed it to an open source project, so it is now an independent open source program designed to give you a visual interface for creating “Internet of things” automations.

You will need something to run it on. Probably the most popular is a raspberry pi, which tells you something about the level of technical skill of most users. But some people run it on a laptop, and there is also an android app called Termux which lets you run it on an android mobile device.

These days it is usually called a “visual flow editor,“ but of course, that assumes you know what a flow is. :wink:

Anyway, there are lots of resources for learning more about node-red.

Here’s the official site:

https://nodered.org/

2 Likes

And we should also probably say that if you are one of those people without a technical background who finds all of this pretty overwhelming, but you still want to create some advanced automations for your smartthings setup, you can do something very similar but with easier setup with the third party rules engine from SharpTools. It has a free tier which can do basic stuff, and a paid tier at about $30/year at the time of this posting, which can do much of what node-red can do but without requiring the same level of technical skill. You can run it in pretty much any web browser. It’s very popular in this community so you can find lots of forum threads about it.

Those with a strong technical background and a commitment to open source projects may well prefer node-red as a flow editor. But I did just want to mention that there is another alternative for those of us looking for something that’s more of an off the shelf option, even if it has somewhat fewer features. :sunglasses:

8 Likes

I evaluated SharpTools. It is a great tool but I was looking for a tool that unlimited potential for advanced automations.

For me, Node-RED running locally on my Automation box, integrated with SmartThings via native SmartThings Routines is the best solution when balancing the requirements of: ease of use, execution speed and unlimited automation power. The fact that Samsung have published a node library for the Node-RED is just the icing on the cake and give simple access to all my SmartThings devices.

The learning curve for Node-red is rapid. There are plenty of resources on the web.

This approach give us back the power we used to have with Webcore.

For example, I have built the following advanced automations:

  • An extended version of the standard SmartThings SmartThings Home Monitor app
  • Sensor Logging
  • Web Scraping
  • Integration with AI models such as GPT
  • AI Chat Bot
  • AI driven Circadian lighting

I feel UNLEASHED from the slow development pace of the SmartThings platform!

3 Likes

Josh, founder of SharpTools here. I totally agree that Node-RED is a really neat solution! Especially for people who want to really get their hands dirty running things on their own SBC/NAS/PC!

In fact, prior to our introduction of expressions in SharpTools (math, logic, functions), I had a number of automations in Node RED myself!

These sound like really cool projects - nice work! I would note that our community has implemented really neat projects just like these using SharpTools Rules as well (except for the chat bot). Between expressions and HTTP actions + triggers, you end up being able to do quite a lot! That being said, Node RED has some really neat plugins that can help with advanced / niche cases!

For example, here’s a thread where I got the itch to have ChatGPT summarize the weather in fun ways and ended up putting together a short tutorial using the OpenAI APIs:

Edit: I totally forgot that someone extended the ChatGPT concept in SharpTools and integrated a general purpose ‘GPT Input’ feature where they could enter a question and the rule would perform the GPT API calls and then speak the result using TTS on their tablet.

4 Likes

Here was my GPT Integration inspiration.

Hats off to Michael. VERY :sunglasses:

Michael uses the Home Assistant platform, but the same techniques can be used with SmartThings thanks to the Advanced Automation approach described above.

UNLEASHED!

3 Likes

If you would like to learn more about Node-RED, here is a great resource.
Its a series of videos which gently introduces you to Node-RED.

Enjoy

2 Likes

Node-RED on an Automation Box

WEBCORE 2.0

Wow! Wow! Amazing. What a great idea…

Not quite sure what I need it for…but I’ve gotta try it (The OpenAI stuff that is)

1 Like

This is intriguing: Would this run on a QNAP NAS? Can you do this just for a few, but not all of the automations? Can it use calculations to adjust things that dim?

And JD, I’d like to add, the Sharptools community, just like this one, is very responsive when you pose a question or a problem. In fact, I’ve gotten replies from Josh, the founder of Sharptools, not very long after posting. Now that’s service! :+1:t2: If I could get that kind of response from my cable, cellular or internet providers, my technology world would be a bit rosier place. :joy:

4 Likes

Does this part work locally? My impression was the SmartThings API the Node-RED plugin uses is cloud based.

1 Like

If it’s using the ST API, then ultimately it’s cloud based. So while the Trigger and Automation logic may be local, the actual device interactions would not be. That’s different from Routines which can run locally on your hub and make use of the Edge driver for local device control.

4 Likes

right, that was my thought.

Hello,

I would love to start evaluating node red for smart things automations.

Does anyone have a simple guide to follow on how to get node red talking to smart things locally?

5 posts were split to a new topic: I miss the old SmartThings

This post is all about sharing my success with extending the capabilities of SmartThings using Node-RED to build advanced automations.

Can I kindly ask that Sharptools references be taken to a separate post.

Thank you.

4 Likes

Here is the Node-RED Export of the Smart Kitchen Automation.


image

[
{
“id”: “3203c09f69cff4ca”,
“type”: “tab”,
“label”: “Smart Kitchen Lighting”,
“disabled”: false,
“info”: “”,
“env”:
},
{
“id”: “313a06f5fb61d80a”,
“type”: “http in”,
“z”: “3203c09f69cff4ca”,
“name”: “When Kitchen Motion Detected”,
“url”: “/event/kitchenMotionDetected”,
“method”: “get”,
“upload”: false,
“swaggerDoc”: “”,
“x”: 190,
“y”: 180,
“wires”: [
[
“81170d7f5409d8fb”,
“ec2da4b1dfe11279”
]
]
},
{
“id”: “81170d7f5409d8fb”,
“type”: “http response”,
“z”: “3203c09f69cff4ca”,
“name”: “ok”,
“statusCode”: “”,
“headers”: {},
“x”: 110,
“y”: 240,
“wires”:
},
{
“id”: “ec2da4b1dfe11279”,
“type”: “command-device”,
“z”: “3203c09f69cff4ca”,
“name”: “Turn Kitchen Light ON”,
“alias”: “on”,
“deviceNodeId”: “2694adbf5529ab86”,
“deviceType”: “installed-device”,
“deviceId”: “a7705d14-661a-44eb-a8b8-8115dd78f84e”,
“componentId”: “”,
“capabilityId”: “switch_v1”,
“attributeId”: “on”,
“rules”: [
{
“capaId”: “switch_v1”,
“attrId”: “on”,
“args”:
}
],
“logging”: false,
“loggingEditor”: false,
“loggingConsole”: false,
“outputs”: 1,
“x”: 560,
“y”: 180,
“wires”: [

]
},
{
“id”: “8c8b63389ddf04ea”,
“type”: “comment”,
“z”: “3203c09f69cff4ca”,
“name”: “SMART KITCHEN LIGHTING”,
“info”: “”,
“x”: 180,
“y”: 80,
“wires”:
},
{
“id”: “47f01aeb396df61a”,
“type”: “http in”,
“z”: “3203c09f69cff4ca”,
“name”: “When Kitchen Motion Not Detected”,
“url”: “/event/kitchenMotionNotDetected”,
“method”: “get”,
“upload”: false,
“swaggerDoc”: “”,
“x”: 200,
“y”: 360,
“wires”: [
[
“2f1ce0bd1c815fe8”,
“a24f9333a58cb7f6”
]
]
},
{
“id”: “2f1ce0bd1c815fe8”,
“type”: “http response”,
“z”: “3203c09f69cff4ca”,
“name”: “ok”,
“statusCode”: “”,
“headers”: {},
“x”: 110,
“y”: 420,
“wires”:
},
{
“id”: “a24f9333a58cb7f6”,
“type”: “command-device”,
“z”: “3203c09f69cff4ca”,
“name”: “Turn Kitchen Light OFF”,
“alias”: “off”,
“deviceNodeId”: “2694adbf5529ab86”,
“deviceType”: “installed-device”,
“deviceId”: “a7705d14-661a-44eb-a8b8-8115dd78f84e”,
“componentId”: “”,
“capabilityId”: “switch_v1”,
“attributeId”: “off”,
“rules”: [
{
“capaId”: “switch_v1”,
“attrId”: “off”,
“args”:
}
],
“logging”: false,
“loggingEditor”: false,
“loggingConsole”: false,
“outputs”: 1,
“x”: 570,
“y”: 360,
“wires”: [

]
},
{
“id”: “fc89b04a70930c93”,
“type”: “installed-device”,
“z”: “3203c09f69cff4ca”,
“name”: “My SmartThings Devices”,
“alias”: “”,
“device”: “”,
“devices”: null,
“profileId”: “fc89b04a70930c93”,
“x”: 570,
“y”: 80,
“wires”:
}
]

1 Like

Done. :sunglasses:

I miss the old SmartThings

2 Likes

HERE IS A SIMPLE Node-RED FLOW TO CALL GPT

Here is a simple automation flow to call the AI model GPT 3.5 Turbo with a question and extract the answer.

This example asks “why is the sky blue”, but you can easily change the question to anything you like by modifying the inject node.

You will need to obtain a GPT token from the openai website, and enter it in the Authorization header in the “Call AI” node. Nb. All this is free.

This flow may be enhanced to create advanced SmartThings automations which use the power of AI!

UNLEASHED!

inject

extract answer

display answer

4 Likes