Using Grafana and InfluxDB with Home Assistant.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
do you like graphs i love graphs and i love little widgets and gauges and all kinds of pretty colorful things so today i'm going to show you how to do a little bit of grafana work using my data coming in from home assistant so let's get started [Music] okay so the first thing you're going to want to do is go to uh home assistant and go to supervisor so you can get to the add-on store and the add-on store you're going to search for influx db i already have it installed so i'll show you a couple things here first you want to click on show on site in sidebar and that's going to show it over here so you'll see a little icon that shows up there you can also expand this out and see it that way and then also you're going to want to find out what port it's on typically the default port is 8086 and so we'll just leave it there this little section of the url is important too since i use docker containers the home assistant services talk to each other talk to each other's containers and they're aware of which container is which using this id so we'll use that id to configure grafana here in a little bit also you're going to want to install grafana which i have as well already installed and same thing here with show and sidebar make sure that's turned on and you'll see grafana show up over here in the sidebar everything else in the configuration is the same is go into influx db itself and you need to create a database and you need to create a database user and to do that we go to influx db admin and we're going to create a database now i already have this mostly done but i'm just going to create one for demonstration purposes so we'll call this one demo and click on the check mark so now we have a demo database the retention policy is forever uh you can change this to delete things at a certain interval you know one day one month forever infinity whatever you want to do if you want to keep stuff forever that's great at some point you may run out of space on your device if you want to purge it after a certain amount of time you can set the retention policy here all right so we've created a database now we need to create a user and again i have a grafana user that i use for uh my grafana instance already but i'll create a demo user so we'll call this demo and we'll call a demo we'll call the password demo and all the permissions will be for everything um which will have to all right thank you we'll have to set here so we have permissions to everything all right so those two things are done because we're going to go into home assistant now we're going to configure home assistant to send its data to influx so then influx can be the source that grafana uses to pull the data all right so next up is to open a terminal you can use whatever whatever editing device you want i'm doing this directly in configuration.yaml and so i've already gone into the configuration.yaml file and i have added a section called influxdb i've added the host name of my my home assistant instance that is known to my network i've added the port that you looked at 8086 is the default for for influx again the database name that you just created demo or whatever i use home assistant because that was what i already created and then i use a secrets file for the username and the password that's the user and password that you just created in influx for that user max retries and default measurement i leave at 9 and the default measurement is state meaning that when you go in to configure something in grafana that it's going to pull up the state all right so that's all you need there do your config checks and your restart and then when you're done with that you should start seeing data come into influx db okay now that you've restarted home assistant you should start having data show up in your influx db so your next step is to go over to grafana and we're going to configure a data source for grafana your your interface depending on the version of grafana and how you have it set up may look a little bit differently but the concepts are the same you need to have a data source before you can do anything else and so for me the gear icon is here and then you click on data sources i'm not going to add a new data source i've already configured the data source so i'll just show you what i have configured i will say that maybe this should be something a little more descriptive like home assistant or ha or something that you know is your data source for your home assistant data the url is what we talked about earlier it's this little id kind of url and then the port number that is defaulted to 8086 and whatever you set up in your configuration everything else is the same except for the database name and the user so whatever this database was that you set up in in influx db use that one and then grafana user would be the user i set up so use whatever user that you set up within there so once you have data sources set up then the next step you're going to do is go to add a dashboard and for that we click on this little set of squares here and then click on manage so we'll just do a new dashboard and automatically it's going to go to this section that says add a new panel so let's do that now and it's going to take you into a panel just blank with nothing on it and then you're going to um start adding your information the first thing you want to do well you can go a number of different ways right this is kind of the order that i go in first i want to make sure on my interface the visualization that i'm going to be using is the correct one and it defaults to graph i think in most cases and that's what i'm going to use as a graph so you can see you can do stats single stats gauges bar gauges tables text heat maps etc there's a whole bunch of plugins you can use that add additional functionality to the type of visualizations you can use so we'll go with uh graph and then we'll go with um starting the query here the first thing you want to do is make sure that you specify your database in some of my stuff i have multiple data sources and so you want to make sure using the right data source here and for me that's going to be influx db because that's why we named it or what i named it and that's why i say name it something that makes sense to you so you know what it is so if you have a whole list of data sources in here you need to make sure you understand which one is which so influx db is the one i'm using which is also the default by the way so i could have chosen default or influx db and then we'll go to a measurement and i'm going to add outside temperature so i have an integration with my um ambient weather station that's in my backyard and i talk to the ambient api through home assistant and it feeds me data and stores that it influx and so i know i can go get that data from influx and display here and that's what i'll show you so in the us of obviously i'm in fahrenheit so what i want to do is look for the default or the fahrenheit measurement and that's down here at the bottom i just happen to know that so if i click on fahrenheit and immediately you're going to see all this junk in here because we haven't specified an entity to take the measurement from so this is pretty much everything that has a fahrenheit measurement in my system and it's just a bunch of gibberish right now it doesn't make any sense so in order to narrow it down we want to go ahead and specify um what we're actually measuring with entity so i will choose entity id in this case and then once you do that if you have data within your in influx db you should have options to choose from a number of different entities that you have in there if you don't see any data here or any entities one of two things you need to wait a little bit longer for it to populate some of this so if you if you have a device that records every 30 minutes or something like that it may not show in here for the the interval it may not show up until it actually makes an entry into the influx database so obviously i've been running this a while so i have a whole bunch of things in here so i'm going to choose what i know is the outside temperature for my my weather station and it'll be um not that one but the temp uh oops uh new butt creek temp all right so now i have my temperature displaying and you'll see down here that it says fahrenheit mean so it's the the mean value of the fahrenheit or of the the the measurement that's not very descriptive to me so i'm going to give it a name an alias so i'll say outside and when i lose focus from that you'll see it automatically changes to outside all right the other thing you'll notice is in this particular case this particular entity updates quite often during the during the like every 60 seconds during the day and maybe a little bit less at night but it does not update very often and leaves a bunch of holes though on entities that don't update very often you would have a dot here and a dot here and a dot here so the way we fix that we come over here to our display and we come down to this section where it says null value and all these little spots here have time stamps but in the database there's nothing there so that's a null value we want to connect all those null values together to make a nice pretty line so let's click on connected for null value and now you have all of this stuff connected you can do other stuff you can play with this you may not want an area fill so you can take area fill or you may want a lot of area fill make it really thick depends on what you're doing with it i'm going to take it off for now because in addition to adding the temperature i want to know what it actually feels like outside so here where i live we have temperature and we have humidity and both of those together and i say where i live in the world anywhere you have temperature in your humid humidity or temperature and wind chill and those two values actually make it make up what it feels like so it might be let's say right now it might be 100 degrees outside but if the humidity is high it's going to feel like a lot hotter so i want to overlay the field like or the real feel temperature on top of this graph to show me what it really feels like in addition to what the actual temperature is so to do that i'm just going to add a second query and i'm going to come down here again and select my measurement which will be fahrenheit and then again everything with a fahrenheit thing is showing up here so we want to narrow that down to the actual entity i'm most interested in so entity id and then i want to choose the feels-like temperature and now you can see that i have both the temperature which is the bottom line now and the the actual what it feels like so um and a couple other things we need to do for housekeeping purposes is we don't want to see panel title because when you go back to the dashboard itself you're you're not going to know what this is necessarily oh and and by the way this says f mean remember let's name this uh feels like feels like and now we have the outside temp and uh i don't like outside let's just say temp since we already know what it's going to be so temp and feels like and then this panel title i will change up here under settings i will call it outside and now i look at the outside graph and it tells me what the temperature and the feels like graphs are or feels like values are and once you do that you have a couple options in this particular interface you can apply it or save it so this applies save changes and saves the dashboard or this just applies the changes and goes back to the dashboard without actually saving the dashboard i'm going to save it because i want to go back to the dashboard and you can call the dashboard something i'm going to call it demo because that's what we're doing today and i'm going to you can put it if you have multiple folders or whatever you could call this environment or whatever you want to do i'm just going to save it under general folder and now you can see that we've created our first graph using values from home assistant to populate it some other things you can do here number one is i like to see six hours is cool and all but i don't really like to see six hours for temperatures i like to see the last let's say 24 hours so i'm gonna drop this down and and click choose last 24 hours now you can you can choose this on the fly for whatever value you want but when you do a save after you've changed this time value it's going to ask you if you want to save the current time range as the dashboard default so i'm going to do that you can add notes if you want to describe what changes you made i'm only only one messing with this so i don't need to tell my team or anybody else that i made a bunch of changes i'm just going to save it because i don't really need to know all that oh and one other thing too is i might want to have this on a the full line so i can drag this around and make it full width of the screen and this changes um dynamically when you resize your browser and again save it again now notice this time since i didn't change the time reference it doesn't ask me to save the time reference as part of the dashboard default so i've saved it and now i have 24 hours of temperature data um so that's that's the uh um the the what's it called the uh i've forgotten what it's called this type of visualization right it's the line graph so now i want to go back and i want to add a um let's say i want to add a gauge so to do that i go back into this or i click on this button here add panel and i'm going to add a new panel and it's going to throw it at the top and it's again defaulting to the graph visualization but i want to add a gauge to my panel instead and all of the same stuff applies here as far as the query goes one thing i like to do with gauges when i'm looking at temperatures or doing stuff like that is um first of all let me define everything for you so again same thing fahrenheit for this one um let's do uh entity id is going to be let's do um our attic temperature my attic or there's that attic or that must be the garage because it's a lot hotter in the attic right now so that's the temperature in my garage and i use that little aotek multi-sensor six and i've done a video on that shows you how you can install it i actually did the one for the attic you can see how i configured that one and install it but this is basically my uh just the value from the the garage sensor so same thing you can name it uh whatever you want um i could i'll name it temperature and then the panel title i'll say garage all right so we have the garage and we have uh the temperature display now i want to know what from a visual indication i want to know when i should be interested in things or when things should be an issue so i want to set thresholds because i want to know whenever i get to a certain threshold it starts to turn a different color just kind of a quick visual indication or reference of what's going on around my house so in order to do that you have to come down to field and this is different in different versions of grafana this is something new i had to learn because it wasn't in this particular area before was actually down below here in a setting so depending on your interface this might be in a different spot but it functions similar so right now we have anything from zero or na whatever the lowest value is they call it base up to 80 degrees will be green we're at 95 right now so that means that we are above the 80 degree base threshold i want to make 80 actually kind of yellowish or orangish because 80 is not that hot for the garage especially in the summer time so i'm going to add another threshold that makes it turn let's say at 100 degrees it turns red so right now from base to 80 degrees is going to be green so this number would turn green and then from uh 80 degrees to 100 degrees it'll be yellow which is where it is now or orangish and then from 100 above will be red so if i look at this graph or this this gauge from it from a whole bunch of gauges that i have displayed i would be able to see right away whether it's a value that i'm concerned with and really uh the garage you know it doesn't really matter what it does in there unless it gets to be really super hot you can also do things like if we go back to panel you can come over here to display and you can show the threshold labels if you wanted to so now i know um that the the threshold it looks like the minimum is 77 the maximum is a hundred that means that the lowest it got to was 77 the highest it got to 120. so it auto set those those minimum and maximum maximum values i don't like that display on there looks kind of cluttered so i'm just going to turn those off you can also turn off the markers too right you can just have it be this color and even that's cleaner right so i don't need to see where it changes that might be fun for some of y'all but i'm going to turn it off it gives it a cleaner appearance so i just look at one graph it's yellow and it just tells me that i'm in the yellow arc for that particular value i set the threshold for now one thing i'm curious about which i haven't looked at is the minimum and maximum and here we go right here so i can set it's set to auto so i want to set my minimum i know in the garage in this in the summertime in the summertime it stays pretty warm but let's just say i'm setting this up for year round and i want the minimum to be um 20 degrees fahrenheit and i want the maximum to be 100 and when it got to 120 yesterday which is kind of hot for the garage so let's just say 125 no 11 25 125 all right so and i don't want any decimals so hopefully it just does that uh and so um [Music] there is now this threshold that goes all the way from here to here so i'm at 95 over 125 and it can come all the way down here to 20 as a minimum you could actually come down here and set another threshold i don't think you can well yeah look at this so this is what i wanted oops that's what i want to do you'd actually have to change these so i could set another threshold to make it blue if it fell below 60 degrees for example all kinds of stuff you can mess with so what we also want to do is i want to say fahrenheit in here and so i'm looking for is all right here it is that's what i was talking about so now you can if you want to display as fahrenheit you can again if you can't see this i apologize but i'm going into the drop down for uh temperature and i'm choosing the fahrenheit value and so now you can see that it automatically puts the fahrenheit indicator on this this graph or on this gauge all right so you can also do other things like if there's no value for some reason home assistant doesn't give you a value or in this last 24 hour period whatever thing you have on the gauge is not giving you a valid value something that updates every 48 hours for example you can actually set it to um to do something else like zero or n a or whatever you want to do you could set it to do something there all right so i'm going to go ahead and save this which saves the dashboard and takes me back to the dashboard and it again it asks for notes uh if i was wrong so apply takes me back to the dashboard and saves it too big for a gauge for me so i'll move this over here and what i'm talking about doing the visualization this actually is pretty cool because you can then see this one other thing i want to show you on this graph is let's let's edit this graph right here let's say i want to have a full seven days worth of temperature data and i don't want the time window up here to affect that i can click on query options here and i can set the the relative time to seven days so i want to i want a week so automatically it's going to notate that here and it's going to give me a week's worth of data so if i apply now and take that back over here it saved my dashboard i'll just double save it just in case and i can see what the temperature has been doing over seven days and if i change this value to six hours it doesn't mess this up what it does is it mess it adjusts any other graphs on the page that aren't set to relative time so that's one way for something that updates every infrequently infrequently like once a day every once in a while then you can set that to be a relative time that always stays that way all right so um if you want these graphs to stay um [Music] or you want them to auto refresh for you you can choose all of these times here so let's say i want to refresh every five minutes now my graph will automatically refresh every five minutes let me save it so it knows that so when i come into this dashboard it's gonna default to this time except for the relative time and it will refresh every five minutes okay so let me just take you through a couple of uh things a couple of my dashboards that i use in home assistant and um i will give you a kind of quick rundown of what i'm doing with it this is just a demo right so let me go back here and i can click on that up here or i can click over here and come back to home either way it gets me back to my dashboard list so one of the cool ones i like is the quick glance and you'll see now why i use those colors for the gauges because i can take a quick look at all of these gauges up here these are all my temperatures for and humidity around the house and outside currently 99 feels like 105 and then different other things around the house i use this i can tell like it's a little bit warmer up here than it should be but at 105 feels like it's probably normal when we were going to and from work i used to have well i still do this is my uh travel time my vehicle to and from and i just used to look at this when i was at the office or at home seeing how long it's gonna take me to get home or to work i like to keep up with my speed uh internet speed so i run a speed test once uh i think it's once every three or four hours and just keep that plotted here uh and the latency goes along with that um these are interesting here this is this might require a whole another video you can see i've done relative time on these so i can't show anything um as a matter of fact let me just change the relative time on this one so you can see what we have so my relative time is one hour i'll just remove that entirely so once you remove it entirely you can see what happens here and let me go back to the dashboard guess apply takes me back again new interface getting used to it still all right so now you can see that i have had motion on all of these sensors at these periods of time and the way i do this is i rewrite this value it comes across as either a zero or one because it's a binary sensor so if there's motion the binary sensor goes to one if there's a motion it goes back to zero well i'm marking every time this binary sensor changes to one and because influx is a time-based database it just kind of puts a tick mark in the database for that value at that specific time and then i can plot it on here but we have um if i did one for all of these different ones there would be just one continuous line at the the one mark or the the one value so the way i'm able to display this is i take and set each one of these to a different value so for example um i don't know if it's showing yeah here we can see the value here let me let me drag this and zoom in a little bit it's going to reload this whole dashboard with this time frame all right so for example um it's hard to see this but the front haul sensor gets a one the kitchen sensor gets a two uh and then i think there's a three and a half a 0.5 or something whatever whatever these other values are right and all it does is it allows me to plot my motion sensors on a time-based value graph because i'm rewriting the the value instead of becoming a one it comes across and that might be something if you're interested in in me doing that post a comment in the video below or in the comments below yeah post a comment below thank you and i will show you how to how i did that and same thing happens with these door events um what is my time frame here let me go back to the last uh six hours same thing with the doors i want to know when the doors are open or closed and again it's a binary sensor and then what what i do with the door instead of just saying okay the door is open or closed um i actually give it a different value so you have two would be uh close maybe two two two would be open two and a half would be closed for one door uh three would be open and three and a half would be closed so not only do i see the time that they were open but i can tell when they're closed because they're in a little bit different value line here and so you can see how many times the the front entry was open how many times the garage door was open and closed and you can see how long it was in that state because it goes from this upper level value which might be open to this lower level value which might be closed so that's how i do that i also am able to visually see whenever one of these boxes turns red based on value i'm able to tell whether a door is open or unlocked and then of course my uptime is a single stat all these are single stats single stat visualizations uh another graph shows my water usage um this is my travel time i take this travel time i also graph it visually so i can see when the peaks and valleys are so i know when the best time is to travel and i know this video is getting super long but i just wanted to show you all the little cool things i've done uh one quick other thing here we'll go to environment and i'll show you one more little thing i've done with this similar thing i've colored these graphs to 85 this turns yellow and at 95 it turns red so when i'm visually looking at the temperatures for outside i can tell right away whether they're in the like really hot range and you can see definitely that we've kind of sit in the hot range since about 10 30 this morning we've been in like the the the you know approaching the sun and then we got to surface of the sun over here uh and and then of course i've got one two three four five six different things on this graph for inside temperatures water usage again and then humidity usage for my different sensors and this is a cool thing i've done as well is i can tell you how long my air conditioning is running based on the the value that is returned to me from um from the system so if it's a one if it's a zero it's off if it's a one the air conditioning is running if it's a two which we don't have any right now because it's summertime it would be uh up here as the heater running so i can actually look at these things and see when my ac or air conditioner or heater is running and when it's not running and i did that because i want to see how long during the day it actually runs so there you go with all this stuff [Music] i just want to show you a few things on how you use grafana with home assistant and i hope it gives you some ideas if you have questions let me know i've played around with it a little bit i know a little bit of things but i'm no expert i will do my best to answer your questions if you have any ideas or things you want me to make videos on regarding home assistant or grafana or electronic toys or whatever just let me know leave me some comments make sure you subscribe it's very important helps me keep making these videos it lets me justify to my family why i'm doing this and then make sure you hit the alert bell so that you know whenever i drop new videos and then we'll see you on the next one
Info
Channel: mostlychris
Views: 13,946
Rating: undefined out of 5
Keywords: Home Assistant, InfluxDB, Grafana
Id: SeaOP4AK3DI
Channel Id: undefined
Length: 31min 9sec (1869 seconds)
Published: Wed Jul 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.