moving ALL of my Automations from Home Assistant to Node Red Ep1 - Presence Detection

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i finally made the biggest smart home decision of the year i'm going to be moving all of my automations from home assistant into node-red i want to get that complete ui view of all of my automations working in one place it's going to be easy to actually remember which automations i've got running today we're going to be using that to create some basic automations that anyone can use you're going to find a copy of this video in the node-red course if you already subscribed to the membership you can get ad-free access to it if not there's a link in the description down below if you want to get access to this video ad free plus all the other videos now i'm going to assume you've already got node red installed and home assistant with a couple of devices integrated we're going to be creating two different flows in node red we're going to be creating a leaving home flow which you can see on top over here and we'll be creating a coming back home as you see at the bottom the leaving home routine is going to use an occupancy sensor which is going to look if we are home or not and then it's going to find all the lights that can't really on and it's going to turn them off so in a blank canvas drag and drop the event state node once you're in here give it a name i'm calling it empty home the server is your home assistant server that you've set up the entity here you're going to pick your occupancy entity that you created previously let me show the one i created the hung occupancy sensor i built is using templating the output will be either true or false so if it's true if somebody's home it's false if it the house is empty so you can see the code over here is pretty straightforward i'm using a sensor i've named the sensor home occupancy i've got a friendly name someone home question mark i'm using an icon template which is set up in this way so it's got a simple if statement so if the state of the sensor is on then we're going to be using the home account mdi and else the home outline so this is the mdi for when people are out you don't really have to do this it's just for the icon what actually really matters is the value template and it's going to give you a couple of things so we could just simply use the home care presence trigger that i set up in my previous video however i'm also including an input boolean to define if there's a guest or not so if there is a gas then this will be overridden if gas is on then there will be someone home even if i've left with the home kit presence center so once you've got all this set up save your configuration and restart home assistant back into node red at this point you should be able to pick it up from here once you've picked the entity then go and click on if state put is and then put false you could put is not true it's really up to you how you want to build the node so once that's done click done now i'm also using this injector you can see over here the purpose of the inject is to test out the node so the beautiful thing with node-red is that you can test things as they go to drag this inject node in you can find it here on the common inject or you can use the search bar and type it in so once you've dragged it in remember to drag this node right to the next node and then we're going to drag this one which says is true which then goes into here the get lights which we're going to be talking about right now the get entities node is what you're going to need you can find it it's got a little paper with this uh object over here so this you just basically drag it in over here now you could just use a simple turn all off lights right so that is possible to do in home assistant but what you don't want to do is sending these messages across your network to all of your devices let me go to the developer tools and explain this to you in a bit more detail so three things that you can do with the lights you can toggle the light so it will flip and that simulates your current switch so if the light is off you'll turn it on if it's on it will go off it's reversing the state of the light the turn off will turn off even if the light is really off so it's not going to take any effect and if it's on then it will take effect same for turn on it's the reverse so really you don't want to send a turn off command to a light that's already off because that's inefficient so we need to compile a list or an array of lines that are actually on and we can do this for lights and switches and anything really to be honest so give this a name i'm calling it get light star on pick the home assistant server that you're using the property id we need to look at the entity underscore id now this is a cool thing with node red you can use something like starts with so your entity id needs to start with light and light dot which we know is the domain for light the state that we're looking for so these lights need to be on now you could do this with anything you could do i want to find all lights that have a brightness percentage higher than 50 or all lights that are green you can use any property that you want from the lights remember the the property needs to be shared across all lights for this to work so state is obviously always there so we're gonna use state and we're gonna pick is and we're gonna put on and one thing you need to change the output type so the output type we're going to be using an array and the output location will be this message dot payload so we're going to be pushing this message dot payload across to explain how these messages work in node-red imagine you have a plumbing system when you have tube and you have some water flowing from tubes and what you want to do is you're going to have water flowing up to a curtain point and once you connect a tube up right you make it and the water continues flowing so the same thing with this node read how it works the data flows from the left from the first thing that you've got and it will pass on the message to the next one and then the message will be passed on to the end i'm actually going to show you this with the message.payload where you can actually see what's actually ended up at the end what message flowed now we need to use the call service the call service you'll find it over here just drag it in like you normally do and connect these dots together give this a name call it turn it off whatever name it would be easy for you to find out what this is later on the main pick light service turn underscore off data so this is what you're sort of going to need to put in yourself so let's click on the three dots let me show you in a bit more detail so we're using something join right to join in and you can say that this is the separator that we're looking for so the array right is gonna hold entity id so it's gonna hold uh and they're gonna be comma separated so what we're basically doing here is is that we're basically telling it to join them all together and based on this common delimited expression type that in exactly as that is cool so that's sort of done the message payload you can add that in also it's a debug node you're going to need a find so if you scroll down you should find it here the debug node drag it in and connect it up i'm just going to create two of them so you can actually find out what's going on now let's see what happens if i click on inject you actually see the results so it's successfully injected but no results were generated and you can see it from this results no results uh message over here so we're going to turn a light on and then we're gonna need to uh simulate this so now turn the light on we can try this again so i'm gonna inject and we got our call off message now i'm looking at the debug tab if you don't know how to get it just click on the three tabs view show sidebar and then click on this little bug and you can see the debug so we can see information from the message.payload you see and an array of four objects one two three four objects if you click on it and expand expanding you can see the four objects you want to see four entities over here so i only turn one light on and you might and ask yourself why are there four entities you can also see the action that the the light's been the lights have been turned off and you can see that sort of working and i can actually check yes the light has been turned off which is right behind here looking at the object we can find out uh the entity so this entity over here is a light dot colored group so this is a group so um when one light is on and it's part of a group it also um turns that on so you can see the inspiration room light is another group we have first floor lights we have a group and the third one is the actual object itself so if you had a smart way of excluding groups maybe with your naming convention or you could also think of even more efficient ways of doing that but ultimately we're only sending a command to four uh lights instead of sending it to 30 or 40 depending on how many lights you have in your home for example so now i've plugged in the message payload after the call service so we can actually see what's the output of the call service this is crucial and fundamentally even if this is working for you you really need to understand how node. works semi-tap inject and we can get it all across again so we can see the information coming from the message we have two different things so we have a message and the message page the message payload it was traveling across from this message over here which is exactly the same that we observed earlier this is the actual message coming from this object so we can see object domain light service was turned off and this is the actual data so you can see that it what it did was it uh used uh every single part of the array and concatenated it into one entity id with a comma so it created that and that's what home assistant needs to actually turn off multiple entities in one go to find that actual information to in the call service node remember to check the show debug information if you're really enjoying this video and you want me to keep making these free no dread courses here on youtube remember the smash that like button we want to get at least 200 likes so that we can actually keep on going with episode two and remember to subscribe to actually know when episode 2 drops coming back home let's look into it we've got the same principle over here we have the same inject node and we have a back home it's exactly the same as going away but this is true instead of it being false so you can literally just pick this up ctrl v ctrl c ctrl v go in here double click on it change the name over here change the status from false to true job done now we're going to create a notification that could go to your mobile phone to actually give you a couple of options the options that i'm going to be looking at either opening the front door opening the garage are the normal actions that i might take when i enter the home zone be aware if sometimes you just entered the boundary of the zone you'll get this notification even if you don't really intend to go back home so that's also fine so even taking no action is sort of something that might occur the way we need to set this up this is a standard core service node by clicking on it you can see that what i've set up is the domain as notify give it a name i've set up the service by using the actual device that home assistant is installed on we've got a message now the message you could click on for the three dots this will be empty for you at the beginning so you can click on load example data and i will like pre-fill it in and once you've done that click on the three dots and you can actually uh get this sort of sense of over here so you only really need a message and a title this part over here the data part is something that you're going to need to actually create yourself to actually give those actions to a home assistant you have two ways of changing this you can change with the edit json or the visual editor now the visual editors that allow you to do things like insert below add item to actually organize this yourself you can also change some of the types so if you can click on something like for example data and you can click it you can have different options like a string number boolean array or object however it's some sometimes easier i would say just to copy and paste the code and paste it inside here and then make some of your changes so what do you need to change now i'm going to be using also a camera stream just because we don't have to do this so you can put a camera dot and whatever the camera of your front door is going to be the actions i'm going to be taking currently i have two actions if you want to add one more action you just gotta usually just grab this code copy it paste it and just align the bracket again and add a comma here between the two and you can create another action called whatever you want so in the actual untitled you're going to need to do a couple of things the action it needs to be in all caps for home assistant with no spaces and same for the one this one over here these are exactly the same thing and the title well the this is what you can see in the notification itself so let's say open front door and open garage doors what we're going to set over here so once you're sort of happy with it even if you're working in edit json it's good to go to visualize to see if it compiles if you do have an error here so let's say you forget to close the bracket apart from you can see it over here already sort of telling you if you go to visualize the table so you give you a json path error says expected curly bracket so you can sort of put the curly bracket back in you can see the red spot goes away and the visualizer works so click on done now i want to set a nice welcome message so i want to do a text-to-speech message called announce welcome home so we suggest that you get another cool service drag it in and give it a name like announce welcome home use the tts if you're using uh nabukasa like i am that should be available for you to use at the speaker that's closest to the place you know where you're going to come in for me that's going to be the kitchen and same as before you can load some example data in the data part and go three dots and modify it the language actually normally is formatted by the initial of your language so en and if you're in the us you put us or gb if you're in the uk um so there's a full list on the website if i remember i'll put in the link in the description too so you can sort of change the language but the language is not really compulsory uh again you can check invigorator so once it's done click done once you're happy so you would connect the notify like this straight into here okay because you don't have this bit yet now what is this actually doing over here so this is gonna allow me to uh prevent that the welcome home gets announced each time that the notification sent out so really actually waiting for something to happen and this object this node over here is the um wait until right to drag a couple of weight untils i've got two because there were actually two entries in the home so i'm i'm either coming from the front door or from the garage door so i would look at this and let me show you put the name correct name use the entity that you're going to be tracking so i'm going to be tracking a contact sentence on my front door i'm looking for the state and the state needs to be on the timeout is two minutes means that the that node red is gonna check for two minutes if um for any reason you uh from the moment that notification is sent the door doesn't open in two minutes that means that you're sort of not coming in the home so the whole process will exit so if you do decide to come in afterwards you're not gonna get the welcome message that's also the way this is set up safe for the garage door to be fair same time out um actually probably could increase the time a little bit more maybe perhaps because i'm coming with the cars and maybe take me a bit longer to to get out of the car and everything but that's uh one way of doing it i've also added this little delay node and you can find the delay node over here if you scroll down you can see delay and this is very simple to set up you just put fixed delay for the amount of seconds i've put 15 seconds you could put random delays but this is really not relevant so 50 seconds means that by the time you open the door around 15 seconds just give you enough time to actually walk into the house you know get in before you get your nice announcement which could be anything i'm just it's just for the posted videos awesome i hope you're enjoying it if you remember to smash that like button let's go to the notification part notification trigger so at the moment these two patterns they really ain't doing anything so this trigger over here is uh you're gonna have to think about this as a event watcher so it's looking for a specific event and this is captured by this event all node node and the event type that it's looking for is a mobile app notification action so if i inject this previous flow right we can see that we've got um the message has been sent now i'm going to pick up my phone i'm going to show you the message itself so we this is the actual notification we've got open front door and open garage door if i click one of them then this will actually trigger now let me tap on open front door i've currently disconnected it so it's not actually going to do anything so tap on it and now we can see that the message payload so this message over here is of populating if you look at the message payload if you expand the the little triangles you can actually find out the uh object so this is sort of the hierarchy there's our object over here there's a payload and then under the payload you have an event type the event id and the event itself so when basically it's an object means it can have multiple things under it just to give you an idea what it means and this action is open door which is of what we defined over here if you remember in the previous tab if you look at it again we have open door so we're expecting this open door and we're also expecting this open garage door those are the two events that we depending on what gets uh tapped on the mobile phone itself at this point you really need one of these so you need a switch node the switch node you can get it over here and this is gonna actually enable you to do either one or another thing so it's basically like a path you're rooting the message either one way or another and the way you root the message is with this over here this is the message right so you can see the message object the payload is this right payload the event so every time there's a dot we're going down a hierarchy or a tree so the event is this event over here and then the last part is action right so you can see that that then if you pass that property if you pass that property will get open door so the double equals mean that it's a comparative equal and not an assignment so we are looking for open door and that's going to be the uh branch number one and open garage door branch number two so this is reflected by these two over there and you actually can see hover on top of them and make it super clear which one is which now at this point it's really easy what you do is you create two service call nodes one is going to be for the opening the front door lock the other one is going to be to open opening the garage door which you can see over here with the open cover garage door and you just connect it all up and this will flow depending on what gets pressed now this is a generic thing for all events really so if you have multiple notification events that you're using probably really you want to move this to a specific flow over here where you can have them all together but at the moment because this is very coupled and tied to this piece of flow and logic i'm keeping it all together but just to make you understand this actually can encapsulate many more messages obviously the event names need to be unique across your whole system so if you stay for this whole entire video i'm sure pretty much you've appreciated it remember to like the video because i'll be looking at how many likes this video got to determine if i'm gonna make an episode number two i hopefully will and it will come out next week sometime if it's already out you'll link it over here and you're gonna access this whole playlist where we're gonna be automatically expanding all of the home automation that i've got in my home and putting them in the node red this is the makers see you in this video over here ciao
Info
Channel: Smart Home Makers
Views: 28,348
Rating: undefined out of 5
Keywords: home assistant, smart home, smart home makers, automation, home automation
Id: xvQr6n31A4s
Channel Id: undefined
Length: 20min 36sec (1236 seconds)
Published: Wed Jun 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.