Node Red + Home Assistant - Master Class 1. Beginners guide, basic flow with state, call service +_

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone i'm simon from homesite and today we're going to be looking at the basics of node red now it's a bit of a beginner's guide however it might fill in some gaps if you've been using it for a little while now i've got a lot of automations i can show you and this is the first one of many videos on node-red let's go [Music] so first of all i'm assuming you've got node-red installed if you haven't take a look at the top because i've got a guide for it now what is node-red it is a big canvas or multiple canvases where you can drop on triggers you can drop on inputs outputs and processes and that's essentially what it is it's a way of of taking an input and triggering an output and that input might be a time it might be a doorbell it might be anything you want if you can imagine it you can pretty much make it happen and quite frankly it's brilliant so let's start taking a look so i've opened no red and we are running version 1.1.3 just for reference so starting here on the left hand side these are all of the nodes that are installed now these things here these are all these little squares here these little rectangles we can drag those on and we can drag multiple versions of these on and they are notes up here we've got different flows now this is what i like to call a canvas so we can drag multiple nodes onto a single canvas but it is important to remember that this is a flow and if we string together a few of these nodes that is technically called a sequence not a flow might seem daft but it'll all make sense at the end so we can have multiple versions multiple flows up here and we can name them just by double clicking and calling this whatever you like you can put description in i'm just going to call this demo just for today now you'll notice we've got this deploy button that goes red now if i drag anything on for example i'm going to drag on one of these event state nodes as soon as i made any changes this button will go red and i have to press deploy before it then takes effect so you can do anything you like until you hit that deploy and that will then push out those changes so over here on the right hand side you've got various things now we're in info at the moment so we can see drop down all the flows and see the the nodes that are in that flow the really useful one here there is a help one so you can look up various bits to help the debug now that's really useful as well now we'll come back to it in putting a debug node on and how we use that now by default this is going to look at all the nodes in all the flows now you can change this to be selected nodes or just the current flow and i find that pretty useful especially when you're debugging a new sequence that you're putting in up here we've got a hamburger menu and yes that is what that's called there's three lines it's called a hamburger menu we can click on that now one of the cool things is the ability to input or export flows now if i press import i can just copy and paste in the json language which you might be familiar with by now you can paste that in and it will add it all into this node i don't want this flow rather or you can export it so if you're looking for help you put on one of those helpful communities on facebook you can export your flow and other people can import it and try and fault find it for you which is pretty cool another thing down here i'm going to point out is called the manage palette now there's certain things in here these are all of the palettes that are currently installed but there's a bunch of them that aren't installed 2869 are available and if there's something in particular you want you might want a let's just put in time and see what comes up there's a time switch there and that might be the one that you want now there's a you can do most things with the with the standard ones but for example there's some really good ones for sonos now i'm a bit of a sonos fan i like my sonos system there's some great sonoff nodes that we can install but i'm not going to do any of those right now it is just a case of pressing install and seeing and waiting i'm going to press close to that so now we're back at our canvas so let's create our very first sequence on our demo flow so we've already dragged on our event state so this is the first thing we're going to use now this is going to look at when something changes it's going to then check to see whether what you've entered is true or false so let's show you so if you double click on the node you'll be able to see here yours will just show add new server to start with so this is the you only need to set the server up once but if you click on the little pencil we can give it a name now i'm going to just leave mine as home assistant we can tick i use the home assistant add-on and all you've got to do is hit add now if you don't use the home assistant add-on you will have to put in the ip address of the home assistant server as well as an access token now easiest way is just to keep it on your home assistant instance and allow it to manage it now i've already got mine set up so i'm just going to click home assistant now i'm going to click select an entity id now these will normally pre-populate now i'm going to run it from apir which i have here on my desk this is called this is a binary sensor type now if you're not sure what it's called i like this little on the little hammer here in the developer tools we can look up all of our entities so we can find our pir side and in fact if we trigger it we can even see the state change you see that went from off to on so we can copy it from here or it should pre-populate now we know that as we just looked in developer tools when it's triggered it goes to on so we can say if state is on and you've got various options are there you could say it's not it's greater than is less than and you might be using some of those for some of your lights for example if something is greater than or less than so if state is on in this case and i'm going to want it to go immediately for 0 minutes then you could change that to two if it's on for five minutes or five milliseconds five days for example so we're going to keep it nice and simple and this is for zero minutes means it's going to trigger as soon as it happens now nice thing as well friendly name i'm going to call this pir on done so you can see that's changed the name now and it's got these two little points here now if you hover over them we can see that pops up and says if state is true or if state is false now the very next node we're going to string together is a call service node now this is a do something for example turn on the light and turn off the lights toggle a light so we're going to drag from this point here if state is true if pir is on we want it to run this call service node and if we double click on that it'll ask us to configure it and i'm going to call it light on server that's the one that we've configured earlier on home assistant domain now i'm going to have a switch turned on so i can put in there switch alternatively you can just click on the drop down and it should give you all of the domains that are available in your network now i've got quite a few because i've got quite a complex system you could be a light it could be an mqtt system now all i'm going to do is just do a basic switch now the service if you click on that gives you the option to toggle turn off or turn on well when the pir is triggered i wanted to turn that on now we can click on our entity id now this isn't going to pre-pop this isn't going to pop up with a full list but when you start to type it should appear so i'm going to put in bootroom now i've got a little boot room light and this pir let's pretend it's in the boot room the data here now for this basic functionality we don't need to do anything we don't need to put any additional data in for some things you will for a dimmer for example you need to tell it what to do you need to tell it what brightness to put it on for an rgbw controller you need to tell it what level of red what level of green what level of blue so for this one nice and simple we don't need to do anything i'm just going to press done to that and also what i'm going to do is i'm going to copy this now simple case of selecting and pressing ctrl c and ctrl v like you normally would in any other application now i'm going to wire if this is false and i want that to turn off now my pir is set up that five seconds after it's turned on it automatically turns off now that's in the configuration.yaml so what i should see now if i press deploy oops i forgot to change the name light off well i should see now if i trigger this pir it should turn the light on for five seconds and then off again pretty cool right so i'm going to go to my overview just so you can see here's a visual representation of my house i've created in lovelace and if i now move this pir what you should see is this is here is my boot room it's turned on and then five seconds later it's turned off fantastic so that's our first simple little flow now you want your pir to trigger but you don't want it to turn off straight away so you want your pir to be off again so you can watch out for your next motion however we don't want that to be turning off after five seconds so one of the other nodes which is really useful now you can scroll down to try and find it which is there delay or you could just start typing up here i find this really useful i'm going to start typing delay and i'm going to drag that down here now one thing you'll notice if i drop it over the top of the line the line's gone dotted so this is going to put it in line between pir on and light off it's done it for me now i'm just going to move it around make it look a bit nicer now this is going to delay for five seconds so once it's gone off i want to delay for let's say another 10 seconds so that's going to be 15 seconds delay i'm going to call this 10 sec delay and deploy so now if i come back to my overview and i wave my pir it should turn the light on and 15 seconds later it should turn it off now delays are really useful in multiple cases this is just one simple example now what we also might find is that we want to interrupt that delay so once we've started it it might it will sit there and then it will eventually trigger after that fixed period of time however there is a method of saying actually i want to cancel that delay and that's quite simple but we'll come back to that later so i'm going to go ahead and add a few other nodes onto here the first one i'm going to show you is an inject now my pirs nice and simple i can unclip it from its base and bring it into my office where i'm doing this film now it might not be so simple you might want to simulate that pir going off so i've just dragged on this inject node and i can wire that into my light on and once i press deploy you'll see the last time that was triggered was 22.16 i can press that little button here to the left hand side of the inject node and it will trigger it so that's now gone to 22 18 so that's turned the light on now what it won't have done is obviously kicked off the delay or the light off so i can come back to here and see that that light is on i'm just going to turn it off manually for now now then if i find something isn't working if for example i put on with two ends and deploy if i trigger this waiting for this to go to running there we go i trigger this it's not going to run it's going to run my light off now that's not my expected result just because of a simple typo so sometimes we might need to debug but it's not as bad as it sounds we're going to look for a debug node i'm going to drag that here i'm just going to remove this inject node just remove the wire from there now i'm going to say if state is true i want to go to my message dot payload debug i'm also going to do if the state is false i would still want to go to this debug node now over here on the right hand side i mentioned earlier on there's a debug little icon now there could be a lot of messages in there now i have been a little bit untidy clearly and i've got a lot of debug nodes still running now i can you can press the little clear log button i'm going to change this item here to current flow now this is only going to bring up errors or anything in debug node on this flow itself now remember this demo this whole canvas is a flow so i'm going to press deploy and now when i trigger my pir it's going to send any output from these up to here so that's my pir triggered and that's showing me that my message dot payload is gone to on and it's gone to off so i can check in here and think ah i've made a typo and correct it and now i will get my expected result when i press deploy now that's really really useful now what is this message.payload the payload is held between two nodes now the payload from this light this light on is likely to be different so i'm going to change this one to one i'm going to call that just number one i'm going to copy it with ctrl c ctrl v i'm going to wire up to my light on and i'm going to change that to 2. now what we find if i clear my log and deploy now when i trigger my pir this has gone to on in one and two is also on but it could be this is something entirely different it could have modified that payload now this is the message that this light on is going to send on now it might be a confirmation it could be anything but notice that the message from pir to light on has now been overruled because that message dot payload is always overwritten by every single node now that's pretty cool that's pretty useful however sometimes you want to remember what's been sent in the first instance now we can do that by using other variables we can use flow variables which exist in the whole flow which is why it's important to remember that demo this whole canvas is a flow we can also use global variable walls which are able to go between flows and in fact they exist across the whole of the node-red instance the next thing i'm going to show you is a change node now a change node i'm going to drag that in here and i'm going to drop it in between my debug 2 and my light on now i'm going to have this change my message.payload okay so msg.payload i'm going to have it change to boot room light is on i'm just going to put that as change message for now now then if i press deploy wait for this to go from disconnected to running wave at my pir we should see that node 1 you can see that it says there node one still says on but node two this one here says bootroomlight is on so we've changed that message within our payload now that's quite useful but what we might want to do is say actually i want to set the i want to change that to a flow dot boot room light status i might want to put that as on because i might want to use that somewhere else in this flow i might want to trigger that to start something else i might want to put that onto a delay i can do anything i like with that now another node that i'm going to show you is called the time range node now that's quite useful and i'm going to put that in between my light on i can drag all of these and space them out a bit more now i'm going to say i want this between anything between 20 8 pm and 0 8 zero zero i'm gonna say eight to twenty till zero eight hundred hours and done now this is to say if it's between eight at night and eight in the morning and that's i'm within that time so i can hover over that point and that says within or outside of that time so if i'm within that time i want the light to turn on if i'm out of that time i don't want to do anything i can press deploy now at the moment i'm out of that time so if i run my pir it's going to turn that light on there we go and in about 10 seconds it should turn it back off there we go that's off so if someone were to trigger this pir outside of that time i.e in the day then that lie wouldn't turn on where now where i live in the uk we don't have fixed sunset and sunrises because that would be too easy so you might want to say actually i want to start this at sun set and sun rise and i could say actually sunrise plus one hour and sunset minus one hour and i can press done i want it to be more accurate i should put my latin long in there really which i could just do from a postcode or a zip code lookup i can press done deploy and now that's going to check hang on a minute is the sun i should change the name of that really as well sunset to sunrise deploy now if this pi has been triggered during the day while the sun has risen then it's not going to go off but outside of that time after the sun is set it is going to go off so like i said at the beginning node red is fantastic and i hope you can start to see some of the uses now if you can draw the flow or the logic on a whiteboard or a bit of paper then you can make it happen it is limited only by your imagination so this like i said earlier on is the first video of many that i'm going to do looking at exploring no red i've been simon from home site i hope you've enjoyed this video if you have give it a like subscribe to my channel and make sure you don't miss the next one [Music]
Info
Channel: Home Sight
Views: 72,330
Rating: undefined out of 5
Keywords: Node Red Tutorial, Node Red Home Assistant, Node Red, Home Assistant, Node Red for Beginners, Node Red Example, Home Assistant Node Red, State Node, Call Service Node, Delay Node, Change Node, Debug Node, Time Range Node, Home Assistant Automation, Home Automation, Smart Home, Node Red Automation, Node Red Guide, Node Red Home Automation, Node red Raspberry Pi, Node Red Explained, Node Red Setup, Home Assistant Example, Love lace, Home Assistant Interface
Id: jRy25wXwdds
Channel Id: undefined
Length: 22min 24sec (1344 seconds)
Published: Sat Oct 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.