Node-RED + Home Assistant How-To

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I haven't seen the video yet (can't atm), but is this really HomeAssistant + Node-RED or is this Hass.io + Node-RED like all the other video's I found?

I'm using HA in Docker which seems to be different from Hass.io, including the way you integrate Node-RED. I'd really like to integrate Node-RED in my installation.

Anyways, if it is or if it isn't what I need, thanks either way! A video like this is always helpful.

👍︎︎ 6 👤︎︎ u/Azerdion 📅︎︎ May 14 2018 🗫︎ replies

You could group up your wifes device tracker and your device tracker. I'm doing this with my PC and my TV:

groups.yaml: niklas_zimmer_state: binary_sensor.niklas_pc, binary_sensor.samsung_tv

In Node-Red I can just use the group.niklas_zimmer_state it change from not_home to home when one of the devices is on.

👍︎︎ 6 👤︎︎ u/Skaronator 📅︎︎ May 14 2018 🗫︎ replies

I guess I'm a little more thick headed than I originally thought.

I've been reading for months about how NR is just "better" than yaml and native automations for HASS. I finally bit the bullet, installed, and gave it a shot.

I just don't get it. I tried to set up what I thought was a simple enough notification sequence using a geofence to indicate if I'm in a specific area. I know that the part of the sequence that gets my location from MQTT is working. And the sensor I'm using thto trigger the notification is working. But all I've been able to do is send the notification ALL THE TIME, without regard for my geofence and location, or never send the notification.

👍︎︎ 4 👤︎︎ u/OEMBob 📅︎︎ May 14 2018 🗫︎ replies

Nice video, I've been using node red with home assistant for a little while and picked up some useful info. I like what you're doing with this channel, keep it up :)

👍︎︎ 5 👤︎︎ u/Progressive_Overlord 📅︎︎ May 14 2018 🗫︎ replies

Written transcript of the video on my website: http://www.thesmarthomehookup.fun

It's probably confusing without the visuals though

👍︎︎ 6 👤︎︎ u/DarkbunnySC 📅︎︎ May 14 2018 🗫︎ replies

These videos are seriously awesome. Thank you!

👍︎︎ 3 👤︎︎ u/bobby-t1 📅︎︎ May 15 2018 🗫︎ replies

Looks like the youtube scene is getting competitive!

https://i.imgur.com/l1XOGi6.png

(I know you respect DrZzs, just funny coincidence)

👍︎︎ 2 👤︎︎ u/[deleted] 📅︎︎ May 14 2018 🗫︎ replies

YES. Thank you for this!

Edit: Strange that this got downvoted?

👍︎︎ 2 👤︎︎ u/w00master 📅︎︎ May 14 2018 🗫︎ replies

Hey would you happen to have an idea how to create the following: If both husband & wife status = just arrived then turn light 1 red if husband = just arrived then turn light 1 green if wife = just arrived then turn light 1 orange

This is assuming there are 2 current state nodes being called at the same time. I'm just not sure how to run boolean logic vs in YAML it was very easy.

👍︎︎ 1 👤︎︎ u/barqers 📅︎︎ May 15 2018 🗫︎ replies
Captions
today on the hookup we're gonna learn how to integrate home assistant a comprehensive smart home component platform with node-red a simple and powerful automation platform a fair warning before we start this video is a lot longer than I had anticipated if this is your first time using node-red i'd suggest you watch it from the beginning to the end if you don't have node-red installed yet click that link right there to go check out my video on how to get it set up and running with home assistant thanks Rob carry on if you've been using node-red for a while and you just like to jump around the video here's a basic table of contents for you to scrub through to the parts that interest you I've been coding in different languages for about 10 years now and I feel pretty confident picking up new languages on the fly but for some reason automations and scripts in Y amel always felt unnecessarily difficult to me not only was I confused by the mixing of syntaxes but I was often discouraged from trying more complicated automations because I had a hard time troubleshooting them when they didn't work enter node-red a platform that combines visual flowcharts with simple scripting and programming to produce a fantastic automation experience today we're gonna write some example flows to learn how to use each of the most useful nodes in node read and even some optional notes before we start let's talk about a little bit of terminology over on the left here you've got a bunch of these little round square things each of these is called a node type if I drag two of the same type out I would say that I had two nodes but only a single node type next at the top we have all of our different flows I'm actually not thrilled about this terminology a flow in node read actually refers to everything in one of these tabs at the top I tend to make the mistake of calling a set of connected nodes of flow but I believe the actual terminology for that is a sequence so a single round in square is a node a series of connected nodes is a sequence and all of the sequences on a single tab are called a flow this may seem like worthless terminology and knowledge but it's actually important for understanding the different variable scopes in node read the information sent through a single sequence is called a message object and it can contain as many individual variables as you want each of these variables will have the prefix MSG dot the default message variable sent out of a node is called message dot payload a variable with the message prefix only exists in the current sequence meaning that if there isn't aligned connecting nodes together the message from one node cannot be processed by another node a different type of variable scope is called flow these variables can be called by all the nodes in the same tab which if you recall is called a flow all the variables in this scope will have the prefix flow a third type of variable is called a global variable global variables can be called by any node anywhere in node read ok let's start with an easy example I have an input boolean setup in home assistant for Rob home that's me and one for Lindsay home that's my wife these input bullying's are toggled when our phones connect or disconnect from Google Wi-Fi in order to use these states to control the house occupy boolean I have the following two sequences in node read the first node type we're going to look at is the home assistant events state node this node will send a message anytime the selected home assistant entity changes states and the payload of that message will be the state that it switched to setting up these nodes is super simple because it will auto-populate the entity ID as you start typing in this automation we've got two events state nodes that correspond to the lindsay home boolean but each of them has a different halt if condition set if halt if on is selected it will only send the message on if she leaves the house if hall Tia off is selected it will only trigger when she comes home in the event that my wife or I come home it doesn't matter whether the other person is home we always want the house to be set to occupied we do this with a home assistant call service node these nodes are slightly more difficult to configure because you have to use JSON to specify the entity ID this is a necessary evil because using JSON allows you to pass additional arguments with your service data this would be things like brightness if you were calling the light turn on service or a message if you were using the notify service if you don't feel comfortable writing your own JSON that's okay you can just go to your services developer tool in home assistant and use the drop down menus to generate the correct JSON the call service node for an input boolean lets us either turn it on turn it off or toggle it in our case we want to specifically call turn on and not toggle this is just about as simple of a flow as you can get conversely in the event that one of us leaves the house we don't automatically want to set the house do not occupied in these events we utilize a different home assistant node the current state node the current state node is set up almost exactly like the event state node the only difference is that it never triggers a sequence it only goes in the middle of a sequence by using this current state node we can check if I'm still in the house when my wife leaves if I'm still in the house meaning the Rob home input boolean is on the flow will be halted there if I'm not home it sends the message on to the next current state node this node checks an input boolean called houseguests because we don't want to be turning out the lights on our guests if my wife and I happen to both leave the house at the same time if that boolean is on the flow stops and if it's off it continues on to trigger the call service node this time this call service node triggers the turn off service my favorite part about node red is how logical it is let's just talk through this sequence really quick Lindsay left because Rob home if not are there houseguests if not that means the house is unoccupied it's simple and intuitive if you're ever troubleshooting a sequence and you can't figure out where things are going wrong you can attach this debug node to the sequence and see what's contained in the message object that's passing through that node if you ever want to see what would happen when a node is triggered with a specific payload you can also use the inject node for the inject node you choose what kind of payload to send from it via the drop-down box once you've set up your inject node hit deploy and then you'll be able to click this small square to trigger your message to fire let's kick this up a notch and do an automation with multiple variables in this automation I want to send an actionable iOS notification to my phone and my wife's iPhone when a window is open in our house I want the notification to include a message stating which window opened a picture from our security cameras of that window and a button that would allow us to manually trigger the siren on the house if we don't like what we see in the picture before starting the sequence we need to make sure we've already done a few things in home assistant number one you'll need to install the home assistant iOS app number two you'll need to enable the iOS component in home assistant number three add a push action under your iOS component and then restart home assistant number four go back to the home assistant iOS app and enable notifications and then tap update push Settings here's how the sequence works to start I have an event State node for each window the sensors on my window send one of three message types open closed or a replaced battery message that includes the current voltage of the battery these three states are the three possible message payloads that will come out of the node but I don't really care about the closed message so I have a halt if condition set for the closed payload the next node type that it runs into is called a switch node this node is like a fork in the road each fork can have different conditions associated with it and it's possible for more than one of those conditions to be true causing the payload to split off in multiple directions in our case I want the conditions to be message payload equal to open or message payload not equal to open the reason that I have it set up this way is that I won't know what the battery voltage is when it comes through so I can't know the exact message that it would be equal to another way I could have set this up is to use the contains flag and set it to a value of replace because I know that message will always say replace battery next we're going to set the value of the notification properties to do this we use a change node I'm not going to change the original message which is passed as message payload instead I want to set a new variable within this message I'm gonna call this variable message dot window name and I set it to the message that I want to appear in my notification in this case family room window open I'm also going to set another variable called message image where I put the URL of the snapshot from my camera's I had to blur out most of this URL but I'll include a generic version of it in the github code I'm not sure if the home assistant people intended for this snapshot URL to be known but it works great for this purpose now that we've got all the parts of our message we just need to put them in the right format to do this I'm gonna use a function note I like to cheat a little bit here and use a Hamel to JSON converter not because I can't write JSON but why do more work than you need to the actionable notification documentation on the home assistant website has a few errors in it so I'll post both the Yamma and the JSON for successful notification down in the description you can see that the message and attachment properties have the variables message window name and message image called instead of hard-coded values after passing these through the function node our message payload now contains this perfectly formatted JSON code the final step in our actionable notification is to pass this nicely formatted JSON to a call services node the trick here is to just put a set of empty curly brackets in the data field because our message dot payload is automatically included in there and already has the correct format there's another branch that comes off this function node and it checks to see if our exterior alarms are armed and if they are it sends a load of other messages out to activate the sirens and lights on our house the last little thing on this automation is the other paths on the first switch node this sequence passes a low battery warning message in a standard non actionable notification to my iPhone only because let's be honest the wife is not going to replace the batteries on the window sensors so far we've used the standard node red nodes inject debug change and switch we've used the home assistant nodes event state current state and call service we also used another node I'd like to say a quick word about the function note the function note is probably the most powerful node type in node read and I'm sure a very common criticism of this video is going to be that I could have combined a lot of the nodes and my sequences with a single function node and that's true but the whole reason we're using node read in the first place is to move away from having to write significant amounts of complicated code for our automations the purpose of this video is to show how simple it is to use node read to do these complex automations and putting too many function nodes in it is a good way to confuse home automation enthusiasts who are not also JavaScript programmers I might do a video in the future about using JavaScript to do crazy stuff and node read but this is not that video moving on now that we know about the most important node types let's tackle variables we made a great flow earlier to determine whether the house is occupied or not but we haven't done anything with that information yet let's look at an automation that sets the exterior doors to notify mode and turns off all the lights in the house when it's unoccupied we don't want to come home to a dark house so we also need to find a way to save the previous state of each light so that when we come home every light will turn on exactly the way it was when we left to do this we're going to set some flow wide variables normally when you use a variable as part of the message object it only exists in the sequence during the time the sequence is active a flow wide variable exists within the entire flow which means it can be recalled by any node on the page and it persists until you restart node red or you clear it using a change node when our house occupied input boolean switches off it will trigger each of these current state nodes these nodes will return either on or off payloads based on the current state of the device will store each of them in a flow wide variable while our variables are storing will delay the payload for one second in this other part of the sequence before we call the turn off service for each of the lights in the house when the house occupied input boolean switches back on the payload will then pass through each of these switch nodes to check the value of the different flow wide variables that contain the stored States from before we left if the stored state is equal to on meaning the light was on when we left the house it will then pass through to call the turn on service for each specific light if the stored variable was off the sequence is halted in that particular node which prevents the turn on service from being called the last fancy part of the sequence uses one of my favorite add-on nodes the light scheduler node you can install it in the palette manager by searching for node red contributor I have a few lights in my house that are on schedules turning these lights on and off based on their previous state gets a bit tricky since it's possible that I left the house before they were scheduled to turn off and then I came back to the house after they were scheduled to turn off this would result in the lights being turned on during a time when they were scheduled to turn off which I'm sure we can all agree would be a total disaster in addition to a lot of other cool features the light scheduled a node can deal with this exact situation by sending a payload of off to the node it can override any schedule and send the off payload to the attached nodes will send this off command when we leave the house and then when we return we want the light to return to its normal schedule to do this all we have to do is send a payload of auto this removes and overrides that we previously put on it checks the current time and it sets the payload to the correct value now our house effectively hibernates when were not home and it returns to its previous state immediately upon our arrival I was a long video hopefully this was enough of a primer on the node types with enough examples to get you started in node red I'll post all of the flows I talked about in this video down in the description if you want to use them as a starting point in your projects you can select import clipboard from the menu and paste in the code that I've posted a fair warning if you import the flow before installing the necessary node types in palette manager you're going to get spammed with error messages in your debug window so make sure you do that before importing the sequences this is part one of a three-part series that I have planned called mastering node read the next edition will cover Amazon echo integration and the node-red dashboard if you've got any suggestions for specific sequences you'd like me to walk through go ahead and leave them in the comments section and I'll add them to a future video now for a personal note this is a new channel catering to a fairly niche market I'm not a YouTube partner yet which means that these videos have zero monetization normally I make at least a few bucks from people using my Amazon part links in the description but we didn't build anything in this video so I don't have any Amazon links to post if you'd like to support me and you need to buy something on Amazon anyways go ahead and click the link in the description for the new Amazon echo spot you don't actually have to buy the spot anything you buy on Amazon after arriving with my link will earn me a small refer fee which allows me to buy new products to showcase and motivates me to make more videos so far I'm still a few hundred in the red for this video making venture but that's not really why I'm doing this so no big deal if you don't need to buy anything right now anyways if you enjoyed this video please consider subscribing and as always thanks for watching the hook-up [Music]
Info
Channel: The Hook Up
Views: 407,238
Rating: undefined out of 5
Keywords: home automation, home assistant, smart home, hassio, node-red, nodered, node red, diy, technology, automation, yaml
Id: SuoSXVqjyfc
Channel Id: undefined
Length: 17min 44sec (1064 seconds)
Published: Mon May 14 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.