ESPHome Basic Setup For All ESP Devices

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi there today we're going to have a chat about the basic configuration that I apply to all my ESP home devices these are very useful and in some ways vital to be able to tribal shoot and give some diagnosis I will talk further about each one of these before we carry I just want to make a public announcement I'm am going to be changing the schedule of the channel a little bit and I think you'll like it and I'll tell you why I am adding a video at least one video a week there may be more but that's another story right now I promised you that I would do a long form video every Friday afternoon at 5:00 this is not suiting me at all I thought I could and to be truthful with you the way that my lifestyle is just doesn't allow me to give you a good quality video by Friday afternoon so I am moving everything to Saturday that will allow me some flexibility in time to be able to give you something decent but in the good news there is now a new series called the quickies and the quickies are going to be tutorials that are going to be under 10 minutes they are additional to my long form videos of the of the Saturdays but also they will cover installations that may be needed for the Saturday video or they will cover things that I haven't talked about in the previous video or questions that come from you before I start coding there are a few things that I need to highlight about ESP H's basic configuration first of all there are some configuration that exists only for the esp32 or only for the ESP 8266 well you get the picture these are not going to be included in this video I will talk about the little variances between the different microcontrollers in another video which is coming out next week in which I will speak about Bluetooth and the web server this said one of the philosophies that I use in my base code is minimalism but minimalism not at a cost of not being able to troubleshoot so everything that I'm going to give you today is minimalistic but will allow you to troubleshoot and diagnose problems that's very important because these little fellows have limited memory have limited space on them and have limited speed so we need to say minimalistic but if something goes wrong we need to know what goes wrong and we need to Output that to the logs what you're going to see now every single one of my ESP devices has that in it I call it my Foundation configuration from there I will add other sensors one last thing that I want to say is the ESP home site and the ESP own documentation is absolutely incredible I've written my share of API documentation and I can tell you this documentation has never let me down how about we start with the top and we're going to be talking about the code step by step let's not delay any further and get to do some coding see you there how about we start as you can see I've taken all of the previous devices out and we are back to a blank canvas inside of a us home so first thing that we're going to do is add a new device we don't care much about this we are going to call it Foundation Foundation device and we're going to click next it's anp32 and forward I will be using exclusively esp32s particularly this one which is a node MCU esp32 version 1.1 so let's click on esp32 we're not really interested by this we're going to close it click edit and I am going to delete everything up to here now why am I going to do that because I am actually going to put some code that I am going I am about to inst it I just want to copy this okay and we're going to delete it the first code block we're going to talk about are the substitution variables now we've got another name for them in coding which is called constants it's you set them once and that's that you can't set them again you can't change them it's over but those are called sub substitution variables inside of ESP home okay so what are we going to put in there I'm putting the device name I'm putting the device Wi-Fi name because the device name has to have underscore and the Wi-Fi name has to have dashes I'm putting the device friendly name and IP address I will talk about the device something time a little later but in short it's how many times we going to query a sensor per minute or per hour or per day for that matter now we don't want to overcrowd the MCU because once we start to overcrowd the MCU it's going to get slower and slower and it's going to start kicking errors it has a limited speed and we need to be mindful of this but we'll talk about this a bit later possibly in another tutorial right now though I'd like to speak about the naming convention and you will see it later I'm just going to put up a uh the convention on the screen for you to see and then I'll take it out you'll see it later this is my naming convention every ID will have the device name which is the name that we will have here and then the Sens the sensor name is followed by that it's underscore sensor underscore name so a temperature sensor would be Dollar open curly brackets device name close curly brackets underscore temperature okay let's move on from there next we're going to talk about globals unlik substitutions which is set it once and then you can't anymore you can change globals throughout the code that can be very useful I'm going to use Wi-Fi as an example and it might not be the greatest of the example but at least it initiates it as false and that the log can be very useful now a place where actually two places where this could be very useful are number one to set a state of a sensor instead of getting an unknown or unavailable you will get something that makes sense the second one is to use into internal automations ESP home is capable of doing internal automations so we can leverage from that and you're going to ask me okay fine why would you want to do an automation inside of ESP home when you've got home assistant that can do all of that well it's very simple imagine you've got a door lock with an NFC tag if home assistant for some odat reason is offline and your automation to open the door when it recognizes a specific tag is on home assistant what will happen it won't open because home assistant is offline but now imagine that the same microprocessor is controlling both the NFC Reader and the lock and it has the ability to recognize that that NFC tag can open the lock well you still can get into your house because it has the ability to do so so these are fairly important things to think about when you start building your ESP home device next is board configuration the short about the board configuration is we are going to give it a name and then we going to give it what microprocessor and on which board now it might not be something that you think a lot about a lot of people will just put the standard uh board in there I don't so first we're going to put in the basic board configuration which you've seen a great many time and that is the name and the friendly name now we haven't changed the name and the friendly name to what it's supposed to be so I'm going to quickly do this and I'll see you right afterwards a few moments later I've uh changed the name and a little note about um my changes here you will see that everything is prefixed with ESP home and you might think to yourself well that's pretty obvious you are in ESP home after all you know it's an ESP home device the problem that I face often is when I go and search for that specific device inside of the developer tools it's easier for me to know that it is an ESP home device because it goes and puts itself a bit everywhere so I can start looking for all ESP home devices and pick the one that I want we talked about the second part of the board configuration which is currently missing and this is why we've got these squiggly red lines there but before I do I want to just touch on a couple of things regarding espo espo has two Frameworks one of them is the Arduino framework they're actually the one that I started using originally when I was Ling around with these things just over a year ago and the second one is the ESP IDF which I recently started using for some little projects also there are only five platforms that we can use inside of ESP home currently the ESP 8266 thep 32 and all of its variants the rp2 4 which is the Raspberry Pi Pico this is still in development so there are a lot of things there that I'm missing having said that I have a fully functional a fully functional device with um light sensors humidity sensor temperature sensor presence sensor and even a screen moving along there is the beckon from libertiny and there is the real Tech from Li Libra tiny I will not talk about those at this point in time I haven't had time to play around with them I think I may have one device that can actually take one of those two there is also the framework now the framework I would leave to recommend it except that in some cases for me I've had to push it above what recommended is now I don't know which one is recommended right now but I know that I had to push to 2 I can't remember it was 2.9 or 09 or something like that and it had to do with the way that the screens work so leave it to recommend it if that works it works otherwise go and check what the latest one is and put that lastly I want to explain to you what this platform actually do it will Define the board and when I say it will Define the board it will Define the MCU type so for example in the SP 32s there are a few there is telica extension there is arm there is risk and there is risk five it will also Define how much SRAM or memory there is it can also in some cases even Define how much PS rank which is extra memory which is required to run a display in some cases which wi-fi type so is it WiFi 4 WiFi 4.1 y55 or whatever the case might be the Bluetooth again same story is that Bluetooth 4 Bluetooth 5 whatever the story may be with that specific microprocessor also what built-in sensors there are for example there is a built-in sensor in the PCO that doesn't exist in the ASP 32s in the ASP 32s temperature will actually give you the temperature of the ESP 32 microcontroller there is an actual temperature sensor on the peod that you can access and that will give you Environmental temperature it will also give you how many spis to I no i2c i2s and art you have available to you it will also Define the GPI op pins which one you can use which one you can't use which ones are for SPI use which ones are i2c and so forth and that was just to mention a few things so I do generally try to get the right board and if you want me to expand on that please leave a comment below and I will show you where I find these things in a quickie okay so let's move on here it is esp32 the board is an esp32 Dev which is this and the framework is are Doo now there are a couple of things about IDF and R doino that I need to quickly cheat about and that has to do with certain things are not compatible with the other I know that for example the web server will work fine on the Arduino framework but not on the um ESP IDF so or I should say the IDF framework so you got to know these little quotes uh I I do believe that in the case of the web server it has been orted I think that nabasa is trying to get the two of them uh aligned funny enough the Arduino framework for esp32 is based on the IDF framework the next piece is logging now I'm not going to hop much around logging because well we're trying to limit our time here here and this is possibly going to be a long video loging and you will see there is a lot of options now I do not put this as a standard on my devices but I wanted to talk about it nevertheless there are different login levels that exist and you can go to the SP home documentation to find that info is in between so it's not verbos or varibles and it's not just you know sensor data if there is an error it will show it at N4 having said that you don't need all of that this is perfectly fine because that is the default for info the next one that we're going to tackle is the home assistant API and there I have a few things to say recently I had a question on my personal uh GitHub regarding this and the question was why can't I get any data on my ESP home from home assistant and this is why if this is not right if this is not correct if you do not have an NP an API key you will not talk to home home assistant so you will not be able to extract information out of home assistant you will not be able ble to synchronize the time from home assistant in fact yes it will see it but you won't be able to initialize it properly in home assistant I think I've covered that quite well and the code is very simple API reboot Time Out is 0 seconds so basically it will try to get as soon as possible a connection with home assistant the encryption Keys over there and we've talked about key exclamation mark secret API encryption key in the past it's in the secret in the secret file and as I've told you I do not use multiple keys I use a single key for all of my devices a single password for all of my devices and this is just because I can't be bothered remembering 30 devices passwords okay so don't worry about the squiggly lines they will disappear in time it has to do with the fact that there are other things that I'm missing like Wi-Fi so we'll move on and I'm going to talk a bit about over thee a updates they will disappear in good time this is possibly why I absolutely love ESP home over the air updates actually prevents small gray hair and as you can see I've got my share of those first of all we enforce safe mode what happens is that once it has acquired the update what it will do is that it will reboot into safe mode cancelling all connections canceling all unnecessary goodies and it will focus on updating itself once it's updated itself it will immediately reboot but in the event that that it doesn't we're going to put a reboot time out of 10 minutes that will restore the old version reconnect and we can try to rep push again that's assuming nothing is corrupted in between the number of attempts would be five so it's going to try five times to do the updates before it gives up the password well I use the same password than my web server there you are now you know everything again all my devices use the same passwords there is a reason for that my brain is not meant to remember all those passwords and they are highly complicated trust me I use 16 characters with special characters with numbers with whatever else you can think now comes the big one Wi-Fi and as I say in my notes what would be an iot device andet of things if it wasn't connected to a network well it would be pretty useless some of the examples of connectivity that we've got available to us on the esp32 and inside of ESP home are Wi-Fi Bluetooth ethernet Lura zigby RF I haven't used Laura zigby and RF inside of ESP home but I do believe it's possible I haven't used ethernet but it is part of the cor networking system of ESP so I'm not confir I'm not worried about that so let me show you the configuration first here it is before we even look at what's below here and the only part that you really need is this section so Wi-Fi network the SSID would be your Wi-Fi access point name a password obviously for that Wi-Fi AP so if you use it like this DHCP will then give it an IP address you will have to go to the logs to go and check that IP address now I keep all of my IP addresses in a spreadsheet and I know where every single one of my devices is and what it is that allows me to also troubleshoot my network should there be a problem this is why I use manual IP addresses because I know where the device is I know what it does and I can also know if something is trying to intrude in my network so here we are this is my Foundation configuration for Wi-Fi although I need to be honest with you because my devices do not go outside of my network I do not use DNS I seem to to have a problem device IP address is not recognized what have I done oh you see device IP address is incorrect I completely forgot to update it and I hope you are all screaming at me so it will be zero and for today we'll use 160 and I'm going to go back over here and all the squiggly lines are gone because N is a network let's talk about the next block here which would be the AP block could it fail to connect to you a valid and known access point what it will do then it will become an access point that you can connect to and the SSID is in correct so I'm going to go and correct it give me a second a little longer than a few minutes later all fixed as you see I'm using one of those substitutions in this case which is the Wi-Fi name to come back to what I was trying to say in the event that it cannot access a access point a Wi-Fi access point it will then become an access point itself that you can connect to now there is a caveat here don't try to use this with a Pico it just doesn't work properly in fact with the picco the captive portal doesn't work either what the captive portal does is it allows you to set a access point so you could theoretically not have any Wi-Fi details whatsoever I've never tried I'll be honest but no Wi-fi detail whatsoever and just use the captive portal to set your Wi-Fi details and voila so that's for the Wi-Fi I think I've covered most of the things oh yes let me check my notes I have forgotten one thing if it goes into captive portal you'll have to connect to it using the Wi-Fi details that you have set here in the AP so the SS ID would be would become basically the name of the device and you would have to use that password to get onto the Wi-Fi and then you would have to go to http1 192168491 picco and I have no idea if it works with the real teex but it works 100% with the esp32 and the SP 8266 a little thing about the web server number one the port is 80 which is a standard HTTP Port we're running version two we are including the internal variables now the internal variables are not reported back to home assistant but there are reported back to the web server so it's an extra little thing to allow you to diagnose your problem obviously there has to be authentication to get into it username and password and then okay local cre is it puts the JavaScript onto the device why would you want to do that my devices do not talk outside the network so I want it on that device next is a status LED it is the T if it's useful or not personally I use it to see if it connects to the network properly to the Wi-Fi properly then iul it this is how I do it I assigned the pin where that specific LED is and then I inverted because I don't want to see it now it's odd because sometimes you have to invert it and sometimes you don't it depends on the board you'll just have to play it by ear and check usually you'll see it blink a few times and then go quiet you know that that board is a false otherwise the light keeps on thereafter and that's a trueth I will want to move on to the time now there are various ways to get the time onto your iot device these are SN sntp which requires internet access or the IP of the sntp server I do not want my devices to talk to the internet therefore this is never used the next one is GPS if you've got a GPS sensor attached to your esp32 you can get the time from the GPS another one would be RTC in the case of RTC or realtime clock you will require RTC hardware and ideally a battery to keep that RTC clock from drifting number one and from disappearing number two now I don't use RTC and I do know for example that the Pico has a built-in RTC if memory serves me well and I don't use it I don't use it for a simple reason home assistant gives me all of that information and even if home assistant suddenly decides to disappear the internal clock will still carry on as long as it's got power it's when it doesn't have power anymore that it will reset the code for time with home assistant is really straightforward there it is time platform home assistant now I want you to remember for the future that platform home assistant because it's going to be very important in other things that we're going to do like getting other information from home assistant to us in such a way that we can actually use it within ESP home for displays this is extremely important I think we've got this one down and I am going to then talk about our first real sensor and the first real sensor that we're going to talk about is a binary sensor now a binary sensor in L manone is on or off true or false that's all it does it can be very useful though so this binary sensor gives us the status of the device it's not a required sens answer by any means however what it does in nor my assistant is that if it's not available it will tell you FSE and you could kick off an automation saying hey I got a problem here this iot device is no longer with me there are there is value in it at the end of the day we're going to move on to a whole bunch of other sensors inside of the esp32 that are pretty useful they are focused on diagnostics and they are focused on things that will give us the ability to troubleshoot the first one of these has got to do with Wi-Fi this is my sensor section and the first one is Wi-Fi signal how is that useful to us well if it's too far away the signal will not be strong enough and just to give you an idea I have a little list because I do not remember this off the top of my head but in short and maybe uh I will put it over there anything that is greater than minus 50 dbm is excellent anything that's in between minus 50 and - 60 dbm is good anything that is in between - 60 and -70 is fair and anything that is below minus 70 is poor this was our first one the next one is a bit more complex at it first I'm going to give you the very basic of it up time now up time is I started 5 days ago and I'm still going strong this is what that sensor gives you but it gives it to you in seconds now I have some of my sensors that have been running non-stop for I don't know how many thousands and tens of thousands of seconds do you think that I know how many days that is yes I could go and punch it and calculate sure but to be honest with you there's code for that and let me give it to you now there we are it's failing let me tell you why it's trying to publish the state here to this sensor and this sensor over there doesn't exist yet so again just to tell you how far they've gone with the editor of ESP home again it shows us quickly n something is wrong we're not too worried about that right now this here is the state that is going to send back and you can see we're getting this the seconds translated to days the seconds translated to hours the seconds translated to minutes and with that it becomes far easier to read and I'll show you that a little later let's move on and let's talk about another type of sensor which is the text sensor now the text sensor gives you output text whereas the sensor can output integers cannot put dates which is technically an integer cannot put a few other things now text sensors are slightly different as I said they output text now what why would you want to add text well let's take the Wi-Fi information for example we would want to know which IP address we are on which access point we are connected to and even the MAC address now why would you want to know the MAC address well if you don't want to assign an IP address inside of espo itself you could go to DHCP server and assign the address then to be able to assign an address on the hcp server you need the MAC address so let me show you this code there is the code text sensor and as promised the first part of it is the Wi-Fi information including the IP address the connected SS ID and the MAC address the second part of the teex sensor here is the ESP home version not strictly needed but it's nice to know on which version you are I have some devices that are not up to date and uh yes espon will tell you so but you can also report it inside of Home assistant and say whoa I do not have that done I don't have an automation that does that but it does help me knowing where I am in the updates and lastly we've got another one that I was talking about earlier and that would be the uptime human reible sensor and where do have we heard from that before right here this is the one that we are using so now we've got that sensor as well and there is just a couple more and I'm hoping that this video will not be too long for the next one is our default switches which are switches that are part of the ESP 32 and this SW these switches are restart and restart into safe mode now restart can be useful in some conditions particularly if you want to be able to restart from home system restart in safe mode will help you troubleshoot things I've never hate to use it but I'd rather be save then sorry by the way if you ever wonder what anything is for there is a little T hover over it it will tell you as I say they've got an they've done an amazing job on the documentation but also they've done an amazing job with the editor the last piece is the intervals again strict not strictly needed I use it for the Wi-Fi so as you've seen earlier the Wi-Fi was set to false initially and what this does is that it checks the connection all the time so are we connected are we not connected are we connected are we not connected and it sets it accordingly that's all this does that's the entire usefulness of this and again this is useful when you've got a screen not so useful without it that concludes the configuration file now we need to compile it we need to see if the debug works then we need to add it to home assistant and see if it works in home assistant so let's compile it first things first let's make sure that the device is plugged in sorry it doesn't Focus let's hit install and like I showed you previously plugged into this computer and it will tell us that ESP home is not running in HTTPS but it will still compile it and it takes a minute I will Fast Forward a little longer than a few minutes later it has compiled we can download the project here we go it's now downloaded we can open ESP home and you will see this is https web ESP home.io so it's https therefore it should work we are going to to connect again you can see it's the USB 2 serial we're in and we're going to say install we're going to click on the uh Bin file the firmware drag it and drop it and we're going to say install again this might take a second but I love about this is obviously that it's erasing it first I'll fast forward through this a few moments later well it is finished installing we're going to close this and we are going to close espb home and we're going to close this and we're going to close this and we are going to wait for a second and we are now online first thing that we do is we check out the logs so we are online everything is working and there is the First Data sent it will send it at the regular interval now I'm going to visit and make sure that the web server is working as I've said they all have the same password but it is a complex password you can see relatively long and like last time we've actually got data now we know that we are logged on to an AP called v9- iot we know that we've got ESP home version 23129 we know that we are running on IP address 192.168.0.1 16 I'm not going to read the MAC address but we have two switches one of them is called restart and the other one is safe mode up time is 1 minute 49 seconds and you can see the uptime sensor is at 109 seconds lastly we've got the Wi-Fi signal sensor which is sitting at 51 dbm now if I check my list 51 dbm is good and then we can also send a file for update and over here we've got our logs being sent we will then close this and we'll go to device and services it hasn't picked it up so what do we do in a case like that well let me show you we go go to ESP home and it's going to ask what host and our host here is 1 192.168.0.1 and we said 60 this is where the magic happens the encryption key without that encryption key home assistant will not talk to the ESP home device will not take talk to the home assistant device so I'm going to have to go and get that offline I'll see you once I've got it a few moments later I entered my API key and I clicked save and here we are what area are we in now this is a foundation device this was a demonstration so I'm not going to put an area to it I will talk about areas in a future tutorial I'm going to say finish and now we are going to have an ESP home device inserted over here and we can see there is one device with one entity now if you ever end end up in this situation where there is one device with one entity there is only one thing that I can recommend to you is to wait for a minute and once you've waited for that minute go back and refresh and voila we now have it inside of Home assistant let us recap what we've learned today we've learned what we should be putting on every ESP home device it's not a complete and exhaustive list however it's a good start we've compiled it we've checked the web server and we add it to home assistant I think that wraps off today's video but before I do a few things more I'll explain the issues with the web server and hi it clashes with other sensors in my next long form tutorial this starting configuration has never let me down so use it don't use it that's your choice I wrap it off here to make sure that you don't miss any of my tutorial will you please click the like button to let me know that you like what I do subscribe and if you really want to know when the when the next one is out hit the notification Bell this is Pascal signing off see you in the next [Music] one
Info
Channel: Home Automator
Views: 1,792
Rating: undefined out of 5
Keywords:
Id: LeeDXzEbvXc
Channel Id: undefined
Length: 44min 20sec (2660 seconds)
Published: Sun Feb 11 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.