Christian Schou
  • Forside
  • Blog
    • Programmering
      • C#
      • PowerShell
      • Python
      • SQL
    • WordPress
      • Guides
    • Cloud
    • Boligautomatisering
      • Home Assistant
        • Node-Red
    • Career
  • Services
  • Ordbog
  • About
No Result
View All Result
Christian Schou
  • Forside
  • Blog
    • Programmering
      • C#
      • PowerShell
      • Python
      • SQL
    • WordPress
      • Guides
    • Cloud
    • Boligautomatisering
      • Home Assistant
        • Node-Red
    • Career
  • Services
  • Ordbog
  • About
No Result
View All Result
Christian Schou
No Result
View All Result
Home Boligautomatisering Node-Red
node-red

How to get started with Node-RED and Home Assistant

by Christian
11. oktober 2021
in Node-Red
0

First of all, let’s clarify what Node-RED is. Node-RED is a programming tool for making the automation in Home Assistant more visually. It gives you a browser-based Editor, where you can create the automation flows. The flow is based on nodes you can drag and drop from the left side panel. Node-RED is the perfect companion to Home Assistant and it is very easy to install. The new version of Home Assistant has made it easier to create automation, but in the early days, you would have to write the automation in Yaml.

In this tutorial, I will teach you how to create your automation visually using nodes in flows. You will be introduced to the browser-based Editor and we will go through some of the available nodes from Home Assistant (spoiler – there is a lot of nodes). Also, we’re going to create very simple automation, so you can get started with Node-RED in your Home Assistant setup.

Indholdsfortegnelse
  1. Install Node-RED in Home Assistant
  2. Getting started with the Node-RED editor
  3. Introduction to Home Assistant Nodes
  4. How to make a flow in Node-RED
    • Step 1 – Check for events on an entity
    • Step 2 – Handling of the output from the state change using a switch
    • Step 3 – Turn the lights on with a Call Service Node
    • Step 4 – Let’s debug the output from the service call
    • Step 5 – Getting smart with Time Nodes
    • Step 6 – Getting started with “if” nodes (Current State node)
  5. Summary

Install Node-RED in Home Assistant

Alright, so the first thing you want to do is install the Node-RED addon through the addon-on Store. Open Home Assistant up in your browser and navigate to > Supervisor > Add-On Store > Select Node-Red under Home Assistant Community Add-ons > Click Install.

When the installation is completed, you have to go to Config on the add-on and configure a password that would be used for encryption. If you would like to enable the dark mode in Node-RED you would also have to change the dark_mode value from false to true in the config. It will look like the following:

credential_secret: Some-Random-Key
theme: default
http_node:
  username: YOUR_USERNAME
  password: YOUR_PASSWORD
http_static:
  username: YOUR_USERNAME
  password: YOUR_PASSWORD
ssl: false
certfile: fullchain.pem
keyfile: privkey.pem
require_ssl: false
system_packages: []
npm_packages:
  - git+https://github.com/hardillb/node-red-contrib-owntracks
init_commands: []

When you are done, click on Save. Head back to the Info tab, please toggle the switch for “Show in the sidebar” and click on Start. Now you will have Node-RED in the left menu panel in Home Assistant. Give it some time (probably a few minutes) to initiate Node-RED.

If Node-RED is not showing up in the sidebar, just refresh the browser (F5). Now we got Node-RED up and running and it’s available in the sidebar.

NOTE: If you got remote access set up in Home Assistant, you won’t need to set up port forwarding rules with Node-RED. This Node-RED add-on already supports Ingress. What this means is that you can access Node-RED securely from your Home Assistant instance no matter where you are.

Getting started with the Node-RED editor

Node-RED is separated into sections. Below is a list of the sections with a short description:

  • The header includes the logo and has a Deploy button, that allows you to deploy in three different ways.
  • Starting from the left, we have our Palette containing all the Nodes you can youse within a Flow. You can install more Nodes if you would like to.
  • In the middle (where the fun stuff happens), you got Workspace where you can drag and drop nodes from the Palette. To make them work, we can drag a wire from one to another. When doing that you are creating a flow.
  • In the last column in the right next to our Workspace, we got the Sidebar. This will show us details about the currently selected node, when on the info tab. These are also the columns that give us the debug panel, which might become your best friend. The debug panel will output all messages passed to a debug node within a flow. I will give you a short introduction to the debug node in a moment.
Node-RED Workspace

Introduction to Home Assistant Nodes

At the moment we have 18 available Home Assistant nodes in Node-RED. These nodes are already pre-installed when installing Node-RED in Home Assistant, so there is no need to do any further stuff. At the same time, there is no need for extra configuration for Node-RED to communicate with your Home Assistant instance. Alright – to get started, let’s have a quick look at the following nodes:

  • events: state -> Checks for a state change on a specific entity and will then output the change. This will result a flow to be triggered.
  • call service -> The Call Service is being used when you would like to send a request to Home Assistant in order to trigger a service. This could be a request for open the garage gate or turn on / off the lights in the garden.
  • current state -> Current State will get the latest known state of the selected entity. This could be useful if you would like to trigger different commands depending on a state in Home Assistant. You can see this node as what a programmer would call an if statement within the code.
Node-RED Nodes

How to make a flow in Node-RED

What a lot of you are here for is some guidance on how to set up your first flow in Node-RED. As an example, I will be creating simple small automation that will turn off the lights in my office depending on the state of my laptop. If my computer is turned on, we are going to turn on the lights and of course, if the computer is off – so will the lights be off.

Step 1 – Check for events on an entity

At this step, we have to check if the computer is running. To do this, we will use the events: state node as described earlier. Drag and Drop the node from the Palette into the Workspace. Double click the node to open the settings. As you can see the Home Assistant Server is already selected for you. You only need to enter the id of your entity. In my case, I would like to check for state change at the switch at my office desk.

State Node – Node-RED

When you type in one of the following fields, you will get suggestions for auto-completion.
– Entity ID
– Domain
– Service
– Data
By having autocompleted on, you will minimize the risk of making typos resulting in lots of errors.

Step 2 – Handling of the output from the state change using a switch

To make decisions based on the output from the event change, we can use a Switch node from the palette. This node allows us to add multiple outputs for further interaction. Drag and drop the switch node into the workspace and connect the event state node to the switch node with a line.

Double click the Switch node to open the settings and configure it as I have done below:

Edit Switch Node

When you are finished, click on the Done button. Now we got two outputs on the node. If you hover one of the outputs you will be able to see a label with a value. This gives you an easy way to figure out what output you need to connect other nodes to.

Step 3 – Turn the lights on with a Call Service Node

Okay so now we can check if the power for the desk has been turned on or off. This leads us to the call service node. Drag and drop two of these into the workspace and connect one to each of the outputs on the switch node.

Double click the node and give it a name that is easy to recognize. Configure the domain to be of type light and set the service to turn_on. For the Entity ID, you need to select the light you would like to turn on. If you got Philips Hue bulbs you can parse further data into the data field. This could be if you would like to trigger a special profile for the light. I will show you how to do this in another article – for now, leave it empty as we only want to turn on the lights. Do the same exercise for the off output and remember to change the service to turn_off.

Call Service in Home Assistant

TIP: You can copy a node by clicking CTRL + C (On Windows) or (CMD + C) on MAC.

Node-RED Flow

If you have followed my guide above, you should now have a flow like the one above. Don’t worry about the messages below the on and off nodes.

Step 4 – Let’s debug the output from the service call

Almost there – Before we deploy our flow, we can connect a couple of Debug nodes to the end of our on / off flow for the lights. By using the debug panel (can be found in the sidebar by clicking on the debug tab).

When one of your nodes connected to a debug node is triggered, you will see the payload output in the debug panel. If you hover the message in the sidebar Node-RED will highlight the node in the workspace that made the message. This is a great way to keep track of how far you got in your flow.

Node-RED Flow

Click on deploy and watch the debug panel to check for events when the trigger is activated in Home Assistant.

Step 5 – Getting smart with Time Nodes

Select the node called time range and place it in between our switch and the call service nodes. Double click to open it for settings and change the name of the node. Lat- and Longitude will automatically be set for you. (If you would like to, it’s possible to change these manually)

Now set the start time to sunset and the end time to sunrise.

Your flow should look like the following:

Step 6 – Getting started with “if” nodes (Current State node)

Let’s drag a current state node to our workspace and place it between the time range and call service node. Double click the node and give it a name. Also, specify the Entity ID (the id of your desk lights).

In the if state set the condition to “is not” and the value to “on“. This will now create two outputs on the current state node. The first output will pass on the message that allows us to turn on the light if it’s not already on. The configuration for the “is on” node, will look like the following:

Copy this node and change the if state to on and of course update the name to off or something appropriate for your node. The most important thing is that you can recognize them again and understand your automation. Remember to click deploy to save changes made to your flow.

Summary

I hope my short tutorial on how to get started with Node-RED and Home Assistant has helped you. If we take a look at the entire flow, it’s easy to understand what happens when and why. In short steps – when the desk power is turned on, a message is passed on our switch. This then tests if it’s an on or off command and passes it then to the right output which then turns on or off the lights based on the time and if the light ts is not already turned on.

You also learned a little about debugging your flow with the debug node. In future tutorials, I will cover debugging further to make you a superstar in debugging errors in your flows. If you got any suggestions or questions, please drop them below.

Tags: FlowsHome AssistantBoligautomatiseringNode-REDNodesSmartSmart Home
Previous Post

How to delete files and folders in a directory older than X days

Next Post

Agile vs DevOps – What is the difference?

Christian

Christian

Hello 👋 My name is Christian and I am 26 years old. I'm an educated Software Developer with a primary focus on C#, .NET Core, Python, and PowerShell. Currently, I'm expanding my skills in Software Robots and Cloud Architecture. In some of my spare time, I share my knowledge about tech stuff on my blog.

Related Posts

node-red nodes
Node-Red

The ultimate list of useful Node-RED Home Automation nodes for your flows

by Christian
25. februar 2022
0

Struggling after a list of nodes that are useful for home automation? Look no further! I have created a list...

Read more
Next Post
How to configure ASP.NET Core Web API .NET Core Service Configuration

Agile vs DevOps - What is the difference?

Christian Schou

Christian Schou

Software Developer

Hello - my name is Christian and I am 26 years old. I'm an educated Software Developer with a primary focus on C#, .NET Core, Python, and PowerShell. Currently, I'm expanding my skills in Software Robots and Cloud Architecture. In some of my spare time, I share my knowledge about tech stuff on my blog.

Recent articles

personal website
Career

Top 6 things to add on your personal website to get hired for a tech job

by Christian
7. august 2022
0

Back in the days before the internet was a thing like it is today, we used to have business cards...

Read more
watchdog

The #1 guide to show real-time .NET 6 logs for Web Apps and APIs in a modern way using WatchDog for Free

13. august 2022
get hired for a tech job

5 tips to help you get hired for a tech job

31. juli 2022
restful web api

How to build a RESTful Web API using ASP.NET Core and Entity Framework Core (.NET 6)

25. juli 2022
dynamically register entities

How to Dynamically Register Entities in DbContext by Extending ModelBuilder?

23. juli 2022

Christian Schou

Software Developer

Hello - my name is Christian and I am 26 years old. I'm an educated Software Developer with a primary focus on C#, .NET Core, Python, and PowerShell. Currently, I'm expanding my skills in Software Robots and Cloud Architecture. In some of my spare time, I share my knowledge about tech stuff on my blog.

Recent articles

personal website

Top 6 things to add on your personal website to get hired for a tech job

7. august 2022
watchdog

The #1 guide to show real-time .NET 6 logs for Web Apps and APIs in a modern way using WatchDog for Free

13. august 2022
get hired for a tech job

5 tips to help you get hired for a tech job

31. juli 2022
  • da_DKDansk
    • en_USEnglish
    • de_DEDeutsch
    • hi_INहिन्दी
    • pt_BRPortuguês do Brasil
  • Contact
  • Privatlivspolitik
  • Vilkår og betingelser

© 2022 Christian Schou - All rights reserved.

No Result
View All Result
  • Forside
  • Blog
    • Programmering
      • C#
      • PowerShell
      • Python
      • SQL
    • WordPress
      • Guides
    • Cloud
    • Boligautomatisering
      • Home Assistant
    • Career
  • Services
  • Ordbog
  • About

© 2022 Christian Schou - All rights reserved.

Jeg bruger cookies på min hjemmeside for at give dig den mest relevante oplevelse ved at huske dine præferencer og gentage besøg. Ved at klikke på "Accepter“, du giver dit samtykke til brugen af ALLE cookies.
Sælg ikke mine personlige informationer.
Cookie indstillingerACCEPT
Privat & Cookies politik

Overblik over privatliv

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Altid aktiveret
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
CookieVarighedBeskrivelse
__gads1 year 24 daysThe __gads cookie, set by Google, is stored under DoubleClick domain and tracks the number of times users see an advert, measures the success of the campaign and calculates its revenue. This cookie can only be read from the domain they are set on and will not track any data while browsing through other sites.
_ga2 yearsThe _ga cookie, installed by Google Analytics, calculates visitor, session and campaign data and also keeps track of site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognize unique visitors.
_ga_0J2F6JVWSD2 yearsThis cookie is installed by Google Analytics.
_gat_gtag_UA_84232734_11 minuteSet by Google to distinguish users.
_gid1 dayInstalled by Google Analytics, _gid cookie stores information on how visitors use a website, while also creating an analytics report of the website's performance. Some of the data that are collected include the number of visitors, their source, and the pages they visit anonymously.
YouTube2 yearsYouTube sets this cookie via embedded youtube-videos and registers anonymous statistical data. I embed YouTube videos in my articles/tutorials - you won't get the full experience of the articles if this is deactivated.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
CookieVarighedBeskrivelse
IDE1 year 24 daysGoogle DoubleClick IDE cookies are used to store information about how the user uses the website to present them with relevant ads and according to the user profile.
test_cookie15 minutesThe test_cookie is set by doubleclick.net and is used to determine if the user's browser supports cookies.
VISITOR_INFO1_LIVE5 months 27 daysA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.
YSCsessionYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.
yt-remote-connected-devicesneverYouTube sets this cookie to store the video preferences of the user using embedded YouTube video.
yt-remote-device-idneverYouTube sets this cookie to store the video preferences of the user using embedded YouTube video.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
GEM & ACCEPTÈR
Powered by CookieYes Logo