ESPHome Guide for Advanced and Intermediate Users

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
ESP home has made building DIY sensors so much easier for the average tinkerer previously you pretty much needed to be a software developer and an electronics engineer but this is just not the case anymore ESP microcontrol devices are inexpensive and you can connect multiple sensors to them now you can build sensors like this millimeter wave one built with ESP home with just a bit of time and effort I'm going to show you lots various VP home including adding status LEDs to your projects input readings from four sensors lambdas and a few other things as well and before you think ESP home is not for me because I don't use home assistant well ESP home can work perfectly well without home assistant you can either build Standalone devices with little displays to show sensor readings or you can send the data to an mqtt broker or web server and do what you like with the data from there I plan to do a video covering this in the near future if you want to learn ESP home to the next level then this video is for you so grab a snack and let's get started [Music] [Applause] so first off is worth mentioning that the ESP home documentation is great and has good information about nearly every setting for each component but one thing that I have found difficult to get my head around is what does a good basic yaml configuration file look like before you start adding all of your sensors switches and logic here I've got a yaml configuration template that I've created which will hopefully help you make better ESP home devices and easier I've put a link in the description to a copy of it on GitHub so check that out the first thing to mention is the API encryption if your device is going to be communicating with home assistant then you can encrypt the connection I could talk all day about the pros and cons of using it and not using it but home assistant is becoming more and more popular so I say why not make your devices and network as secure as possible if you do want to use encryption then go to the URL mentioned in the Amo file where the page will locally randomly generate an encrypt destion key for you and then you can paste that into your file otherwise you'll need to remove the password line the next bit is the password required to update the firmware remotely so I'd say definitely make sure you put a good password in here and similarly the next bit is just as important this is the password for the Wi-Fi access point that the ESP device creates if it can't connect to your Wi-Fi so generate a different random password for this and make sure it's not the same as the other one if you're not new to ESP home then perhaps you knew all of that already but in the next bit I've added some handy button components but before I go over those I just want to show you what I've added at the top of the file substitutions allow you to set constants which can then be used throughout the config this means that if you need to change a value then you only need to change it in one place so I recommend using these as a best practice and even more so for more complex projects as you can see here I've added all of the defaults at the top of the file so that you don't need to search through and find what bits you need to update now back to the button components I have added a restart and safe mode button which can be really handy if you're having problems with the device it means that you can remotely give it a kick from home assistant you can also add shutdown and factory reset buttons which might be a bit more dangerous to include but I could see them being useful as well if you plan to give ESP home device to a friend then the factory reset one might be a good one because it allows you to wipe the Wi-Fi details and allows them to add it to their network instead you can also add these as switches instead of buttons which might be a good idea for the shutdown and factory reset ones the final thing to mention for the standard config is that if you're using an esp32 device then it's a good idea to use the ESP IDF framework instead of the Ardo one that's because it's more memory efficient I believe and so can help with Device stability that's pretty much it for the standard config next we're going to connect up three LEDs to the esp8266 dev board we just connect one to each GPI openin and ground with a 330 Ohm resistor between you could add a higher value resistor if you want the LEDs to be dimmer as well in ESP home we're going to use the output component and the gpio platform defining the PIN for each LED we could then either trigger these to turn on and off based on certain states of the sensors or we could link them to a light component using the binary platform which will then allow you to have entities in home assistance so that you can control the three LEDs you can see here that I have added three light components and Link them to the gpio outputs of the LEDs above you reference the output with this ID that you have assigned to it and now you can see that toggling these switch entities in home assistant turns the LEDs on and off nice so far we can restart the device remotely and we can have some indicator LEDs that we can use but here I've got an FSR sensor which basically changes its resistance upon pressure applied these can be used for bed sensors or detecting when someone is standing on a mat or on a step and then you can trigger an Automation in theory you can use them to measure weight of objects but getting accurate readings can be a bit tricky so we're just going to use it to measure approximate ranges of force being applied I've chosen this example because it allows us to explore a few areas of ESP home we're going to look at the sensor component analog inputs filters automations and our first look into Lambda functions the wiring for this involves creating a voltage divider using resistor and pulling the GPI open to ground by default here I've used a 10K potentiometer so that you can adjust the sensitivity but using a fixed resistor is fine if you find that the readings are too sensitive or not sensitive enough then you may wish to experiment with different resistor values if using an esp8266 then it only has one analog input so you must have it connected to a z like I have it connected here if you're using an ESP 32 then you can connect it to GPO pins 32 to 39 depending on the pins you have available and the type of board you've got what all of this means is is that it allow you to get a voltage reading based on the pressure applied to this sensor depending on your board this may read between 0 and 1 VT or it may read between 0 and 3.3 volts we need to use the ADC platform which stands for analog to digital take note that for an esp32 you may need to set attenuation to Auto so that it shows the full Voltage range have a read of the documentation this link if you've got any issues the voltage will fluctuate a lot and so this is where you can explore the ESP home filters to reduce the amount of data being sent to home assistant and you can get it to do some averaging or use some of the filters as well here is the ESP home documentation which includes all of the filters that can be used and as you can see there are a lot of them once you have flashed the device with the changes you should now be able to see the voltage being reported in home system you can then create an automation to trigger Things based on the different voltage ranges for example if you used it as a bed sensor and you weigh quite differently between you and your partner then you actually might be able to detect which side of the bed someone is on and who's on that side of the bed unless of course someone has passed out on the bed diagonally if you want to experiment with different filters without flashing the ESP device each time then you can create multiple entities linking to the same sensor you can use the template patform for this and then you can link it to the actual sensor platform a good setting to know about here is the intern internal parameter setting this to True means that it won't show up as an entity and home assistant and therefore won't flood it with data if you're doing updates a lot you can set the update interval against the sensor quite low and then you can vary the interval on your template sensors you don't actually need to use filters for this example though but I'll get back to an example on this later here you can see different entities updating at different rates and I have done this based on the update interval the main sensor has got an update of 1 second and then the sense of reference in this has got an update of every 5 Seconds you could then set the 1 second one to internal so that it doesn't send the data to home assistant and this nicely leads on to Lambda Expressions they allow you to perform some logic to derive the output value off the sensor it can include calculations and things such as if statements you just saw one in the template sensor example which simply gets the state of the FSR sensor and returns it to the sensor you could perhaps Define a sensor that displays which person is lying on the bed rather than doing the logic in home assistant if we look at the air quality sensor config which also got connected to this device then you can see that lambdas are used in a couple of places the air quality value is calculated based on the gas resistance and the humidity values and then another Lambda is used to convert the value into a user friendly text such as excellent the advantage of doing it like this is that all of the logic is on the ESP device itself and so you can simplify your automations in home assistant the downside is is that you need to change things and upload new firmware each time that you make a change you can do pretty much anything with lambas and so I'm not going to go into much more detail but check out the documentation if you want to learn more another powerful part of ESP home is automations these are great for building DIY sensors which perform specific functions or operate Standalone because these automations run on the ESP device itself and so don't need to be connected to home assistant to work an example might be where you're building a smart watering device which reads the soil moisture from One sensor and turns on a relay connected to another GPI openin and then it starts watering the plant here I have added an automation to the bed sensor it takes the voltage value of the sensor and turns the LEDs on based on the amount of force applied you can see that if I press this harder or softer then it will light up different LEDs here it's only updating every 1 second you can see the LEDs change quite slowly and that's because I've got the interval set to 1 second but you could change this to milliseconds instead and this would be really responsive in this example an automation is fired automatically based on a value from the sensor but you can also have an automation trigger based on a key press instead you might use this for creating a DIY doorbell whereby the button is pressed and an LED indicator turns on so that the visitor knows that they've press the button and this is exactly what I've done here if I press this button you can see that the blue LED turns on if you use a gpio pin with a pull-up resistor then you simply need to connect the button to the gpio pin and to ground and copy my configuration this is what I've done here I set the automation to directly turn on the LED output if you actually creating a doorbell then you'd probably want it to update a binary sensor so that you can trigger an Automation in home assistant instead based on the Press of a doorbell and you can of course also use lambdas within automations if you're feeling brave great so we now have the LED indicators which can be triggered by a press of a button by pressing the bed sensor and different pressures applied turn on different LEDs or you can use the entities in home system to turn on the different LEDs as well this shamal file isn't really very large but if it was really complex then to tidy up things a little you could use the ESP home script functionality if you know what home assistant scripts are then you can think of them in a very similar way it has the same modes as it does in home system as well so you've got single restart cued and parallel if you have a complex automation or an automation that is used multiple times within the same script then you can put the commands against the sensor itself or you can put them in scripts and then you just reference that script from the sensor all you just need to use is script. execute to call that script I have a sonoff TX ultimate light switch which I really like running ESP home and if you look into the yaml for the great project that I'm using then you will see that they have created various different scripts to keep things tidy you can see that all you need to do is call script. execute as I mentioned before and it will run your automation you can also Define parameters and then pass in these arguments when calling the script now before we wrap up this video there is one final thing I wanted to mention when you're making a lot of changes to your config file and adding new components to your existing ESP home device you can sometimes get compilation errors some of these will be that you've just made mistake but these should get highlighted as you're typing the AML sometimes it's worth just trying again and it's fine but if that doesn't work then go to the three dots next to the device and press clean build files this will rebuild your firmware file from scratch and should sort out any of those annoying failures I had to do it many times during the process of building this device for this video I'm sure that what I've mentioned in this video won't give you every piece of information you need to build your next ESP home sensor but hope hopefully it will give you enough understanding of how to piece things together along with help from the documentation of course I have an ESP home playlist which you can check out and there'll be more ESP Home Videos coming this year so subscribe if you haven't already like the video If you enjoyed it and thanks until next [Music] [Applause] time
Info
Channel: Let's Automate
Views: 10,609
Rating: undefined out of 5
Keywords: ESPHome, HomeAssistant, Home Assistant, FSR Sensor, FSR Pressure Sensor, ESP8266, ESP32, Microcontroller, DIY Sensor
Id: XIY1xOzM3fs
Channel Id: undefined
Length: 13min 36sec (816 seconds)
Published: Sat Jan 13 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.