Most POWERFUL Home Assistant SENSOR

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i've just found a home assistant gem that no one is talking about i'm going to show you how you can track events like cooking and sleeping by combining multiple sensors into one this video has been made possible thanks to the guys at datacamp which have sponsored this video so you'll know that smart home companies want to collect our own data but what if we understood the power of data and we leveraged it in our favor data camp is an online learning platform which makes it super easy to acquire data skills in an easy and convenient way for everyone i've personally been a data engineer for over 10 years and i absolutely adore this platform if you're a home assistant user i'd recommend you check out the python fundamentals track and if a little bit more advanced the machine learning track you can get access to the first chapter of any data camp course by following the link in the description down below the base and sensor uses states from multiple sensors and different probabilities and outcomes to determine if something's happening or not think of the good night scene you want it to trigger when everyone's asleep but how do you know that what things can you actually track so let's say for example the blinds are down and it's after a certain hour and your phone is charging if you combine all these elements together you can statistically assume that you're actually sleeping you don't have to be a statistician to understand the base on probability theory in a nutshell it's a way to estimate if events have occurred or not how does it estimate well it's estimated based on previous conditions that we've predetermined ourselves in today's tutorial video we're going to be creating the cooking center why am i actually interested in knowing if i'm cooking or not well first of all i want to trigger my robot vacuum as soon as i finish cooking these are the scents that i'm going to be using to estimate if i'm cooking or not i have a contact sense on my fridge so every time i open the fridge or i close the fridge i will know thanks to templating i actually can figure out when was the last time the door was closed or open temperature is also something that changes when we're cooking and you normally see a spike in temperature when we start cooking and then that slowly decreases down as the kitchen cools down so if you've got a temperature sensor in your kitchen perhaps closer to where you're actually cooking and you compare and take a temperature for example from your hallway or somewhere else in your home and you can compare the two and if you could calculate a little difference between the two again thanks to templating you can take that into consideration obvious ones are motion and occupancy in the kitchen someone needs to be in the kitchen now interesting point you could perhaps put something in the oven and then leave the kitchen so even if you don't have occupancy and motion cooking event might still be occurring other senses i actually thought of adding but i don't really have available for this video are energy monitoring so you could be energy monitoring for example the oven and the hob directly vibration sensors you can place them around chopping boards now i think it's going to be easier if i just jump into the code and give you a yaml example jump into your visual studio or phallics or whatever add-on you are using and go to your configuration.yaml in here you can add in from line 480 what i've got binary sensor if you really got binary sensor then skip that and just add form line 481 wherever you have binary sensor in your configuration let me break this down to you two parts the first part is defining the actual sensor so what is the sensor and underneath we have something called the observations so these are the basically the other sensors the real sensors that make up the main sensor so we always need to give it a name i'm calling it cooking you could call it whatever you want remember because this is a binary sensor the outcomes are going to be on or off platform you need to use that is the basin platform now prior what does this mean prior is the um likelihood the statistical likelihood that this is actually occurring that the event is occurring without any of the observations triggering so could we be cooking really without any of this happening potentially potentially it could it could be possible um i've put a low weight on that not 0.1 the probability threshold is actually what we're looking for so this so basically we need to get a sum of all of the observations and the prior needs to be higher than the probability threshold once it's crossed the threshold then the binary sensor will turn on if it hasn't crossed the threshold then it will stay off here we can see the keyword observations and note that we have an indentation and each block is starts with a list and we can use platform like platform state and we can also use things like numeric and template i've currently got three observations set up but you can set up as many as you want first observation is pretty straightforward i've got a motion sensor in the kitchen i'm looking for occupancy if it actually is occupied then i'm giving a score of uh 0.2 and remember to put two states the two state actually means that we're looking for on you could list to reverse so for example if you're looking at um no motion right for example a sleeping scene then you would put the motion sensor off because you expect all motion sensors to be off because you're you know you're assuming someone's sleeping in this case we're doing cooking so when our machine tends to be on i'm always given a probability to give them false zeros so you can give probabilities of the event actually happening even if the current thing is false um i'm just sending it at zero because it's simpler for me but you can change this to whatever value you want obviously this value will be lower than that value to make any sense the second thing that i'm actually doing i'm using a little bit of templating to check when was the last time the fridge was actually you know touched in the last 30 minutes and let me break this down to you so just go copy this code in jump into our developer tools and actually talk you through this piece of templating if you're getting value of this video remember to like it and also share this video as much as you can and i will really appreciate that this is how you can calculate the duration between an event in home system and the current time first thing you need is the current time which you can define as now with these brackets and you can see it on the right hand side the current time the last open time this is really really cool from home assistant basically each attribute that you have has a last change so any anything in homer system you find that the last time the status changed so i know i said last opened actually to be more precise this is last open or closed but because the fridge doesn't stay open that much pretty much we say it's the same thing but it's any status change and when you define it you do states dot binarycenter.fridge.lastchange so once we've got these two together we need to apply a function and then we need to subtract the two together so now we can see expressed in seconds the difference between these two time stamps 43 minutes was the last time the fridge status changed what we can do is we can put a comparison so what i had earlier i had greater than and this is expressed in seconds so say 900 seconds and it gives me my true and false the third way is the temperature in the kitchen now i want a temperature indication to be higher than three degrees now this is three degrees celsius too y free because the hallway is normally always colder than the kitchen and i don't want a false reading so i wanted at least three degrees which i think seems reasonable for a room that's heating up a lot and let's look a little bit at this templating so we are nice false so let's break it down let's get our states we have a nest temperature reading and a hawaii sensor so if i wrap it around brackets we can get the actual values we have 19.7 degrees and this is the kitchen temperature i just do copy and paste this in and get the real sensor there we go so 18.1 so as i said the the hallway is always lower in this case you know one degrees closer to uh bear in mind that in the code then i'm actually showing you there's no rounding so you might want to do rounding before doing the comparison so now once you've got your um binary sensor complete you can as usual check your configuration and restart home assistant and jump into the developer tools once it's back now i'm back in my developer tools now this is where the real fun is going to start and this is where my phone is going to start too you look at this and you're immediately going to need to change your parameters that you've set i can absolutely tell you for now that no one is cooking downstairs but this is on so here we can see what observations are actually triggering and we can see a few observations picking up from here we can see the uh template and we can see other information a kitchen occupancy we can see other observed events happening but for some reason it is triggering so let's go back to the code okay let's look at these one by one so what i would do is take your first occupancy sensor and let's check if this is actually giving me a reading so occupancy is off the fridge door status let's check it again so this theoretically should be false okay so i think i found my first bug it looks like that i'm switching this and this should be switched the other way around to have more than 15 minutes passed yes that is true but i actually don't want that i probably want the reverse so i want the actual less than 900 so we can make our change to the code the fridge has been open in the last 15 minutes now let's take the last one we can go over and troubleshoot it and we can see this is false now even if we have found that the fridge door sensor had a bug in it and the weight of it was 0.3 but the prior weight was 0.4 so my understanding of this is that it should be should sum up to 0.4 and it really shouldn't cross the probability threshold 9.7 so why is it actually giving me this uh reading i've made one more change i put prior to zero i'm trying to debug this and i understand why this wasn't working it will not trigger unless it's one of these three occurrences let me know in the comment section down below which sensors you want to create with this new platform thing is if you really want to take your home assistant game to the next level this isn't enough on its own there's actually one more thing you need to learn which is templating without it you can't really do things like checking when was the last time the fridge was open and other cool stuff and that's why you shouldn't really ignore this video over here it's going to take what you just learned and make it 10 times more powerful
Info
Channel: Smart Home Makers
Views: 36,983
Rating: undefined out of 5
Keywords: home assistant, smart home, smart home makers, automation, home automation
Id: 9ZPKiF0F5nY
Channel Id: undefined
Length: 11min 13sec (673 seconds)
Published: Mon Feb 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.