ESP8266EX Fun With Relay Module, Home Assistant & MQTT

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

What do you need to watch out for? The video is 18 minutes long.

πŸ‘οΈŽ︎ 4 πŸ‘€οΈŽ︎ u/smilespray πŸ“…οΈŽ︎ Jun 09 2020 πŸ—«︎ replies

If you want an esp8266 controlled relay, get a Sonoff Basic. Probably less expensive than buying the esp8266 board and the relay board, and you get a nice case. Easy to install your favorite open source firmware or write your own.

https://www.amazon.com/Wireless-Household-Appliances-Compatible-Assistant/dp/B07PWX8689/

πŸ‘οΈŽ︎ 4 πŸ‘€οΈŽ︎ u/[deleted] πŸ“…οΈŽ︎ Jun 09 2020 πŸ—«︎ replies

Sorry, I am not watching a 20 minutes movie for something I can read in 30 seconds.

I wish people stopped using YouTube for programming tutorials. It’s not searchable, it takes a lot longer to watch, it’s sequential access - it’s stupid across the board.

πŸ‘οΈŽ︎ 4 πŸ‘€οΈŽ︎ u/verylittlefinger πŸ“…οΈŽ︎ Jun 09 2020 πŸ—«︎ replies
Captions
[Music] connection established welcome few months ago I found sheep esp8266 with rely and ordered it without thinking his price was six US dollars I thought that process of setup will be almost like plug-and-play I was going to write single program uploaded to esp8266 plug esp8266 to realign and things gonna work but was it like that no let's start from the beginning first of all I just want to warn you that working with high voltage is dangerous so please be careful and if you have never worked with it ask someone who did to help you let me tell some specs for this esp8266 later on I'm going to call esp8266 just ESB so no it's the same datasheet more information and all other links can be found in video description maker of this esp8266 e^x system-on-chip or also known by name ESP zero one is expressive systems from China few years ago there was hard to find any data for expressive products but now I must say nice job to expressive systems for making nicely organized information about their products on their website esp8266 e^x is integrated with a 32-bit 10 silica el 106 RISC processor which achieves extra low power consumption and reaches a maximum clock speed of 160 megahertz the real-time operating system LD us and Wi-Fi stack allow about 80% of the processing power to be available for user application programming and development that's what they are claiming board sports 802 11 BGN that is 2.4 gigahertz Wi-Fi esp8266 px uses external SPI flash to store user programs and supports up to 16 megabytes memory capacity theoretically it comes with easy accessible bins that you can see on this picture it's application can be found in home automation smart plugs and lights IP cameras Wi-Fi location-aware devices and many more today my goal is to write simple C++ program upload it to ESB and be able to switch on and off relay from home assistant beside ESB I'll use USB to TTL CP 2102 module breadboard and some wires links for all items are in description so let's start with driver for USB to TTL module am using Windows 10 here if windows automatically doesn't recognize your USB to TTL module download drivers from syllabus website and install it like I did the link is in description [Music] [Music] next let's connect USB and USB module with the help of breadboard accordingly to this sketch that way we will be able to upload program or flash ESP this will be a little bit messy with wires and may be hard accessible but once we do it we have ESP ready for use now to programming ID am using is 8m with the platform IO in few of my previous videos you can see how to install item and write a simple program I will add links to those videos in top right corner and below in video description ok open item and find platform ILO home screen then open device's tab and there you should see comm port for USB to TTL serial communication let's go to projects tab and create a new project I will call it esp8266 relay you can choose your own select port I picked a SP two six six ESB 12 t by choosing an esp8266 should be fun and I will leave already no framework and finish after that is done let's fast check platform i/o in it should look like this so place a check now open main.cpp here I'll add code for ASP to control relay over Wi-Fi with home assistant and MQTT protocol let me open old main.cpp from my previous project that is also available on youtube and basically just copy and paste code that we need from their link the code will be in description below video so you can just copy and paste it let me first explain the program first I paste esp8266 Wi-Fi the library for controlling USB Wi-Fi connection next I will add a real life pin that will be later sent to 0 then next lines are for mqtt server or against a broker IP with the help of mqtt protocol will subscribe to topic which we will add in this code later and by doing that we will be able to tell ESP from home assistant to turn a light on and off under that mqtt IP is defined Wi-Fi client with which we will connect ESP to 2w plan and later on to mkdd server next part I pasted is callback function that will take message or we can say order data right from home assistant and which is in our case 0 which will turn relay off and 1 which will turn very light on instead of function let's set a real IP as output pin because we are giving orders in this case let's add lines for serial communication so we can see what's going on over serial monitor after that I'll paste part from Wi-Fi connection information add yours Wi-Fi SSID name and password and have enabled DHCP on your router ESP should get some IP and connect to MQTT broker but I forgotten pops-up client library without that previous is not going to work so let's edit and this sensor dot begin is aligned we don't need and let's change it relay from five to zero as we said before that's because pin five doesn't exist on this board and we will use pin G PI zero for switching relay on and off okay nice press built to check for errors no errors that is lovely to see check that you have connected everything accordingly to sketch and if you load it didn't block USB module PC and let's upload program to SP will it work from the first it looks like it won't two errors arrived after a minute I simply unplug two USB to TTL module from PC and plugged it back that should resolve the errors I forgot to add few lines of code in program I'll add them now let's quickly save these and try build an upload program to ASP again [Music] this time upload is successful interesting thing I saw when Cole was uploading to SP is that flash size is only one megabyte and this program took around 250 kilobytes nice program is now on ESP before you disconnect USB let's remove wire from being GPI 0 and pull out wire for pre-world pin and push it back in this way we will pass from flashing mode in which we were all this time to regular you can see normally speak working mode let's see how the ESP is working from serial monitor I will open platform il serial monitor inside atom strange lately it is not showing anything plugging USB module out and in doesn't help so I have another tool to test this it's Hercules serial monitor so let me try with it pic port in my case that's come 3 and choose 1152 double-o bout rate and open can we see messages when pressing button home assistant yes we can nice let me plug out and plug in three volt wire to power off and on ESP and here you can see messages that is piece connecting and is now connected to Wi-Fi with IP that has last eight bits showing number 208 okay that's great another way to see if your ESP is connected to Wi-Fi is really using angry IP scanner or similar tool if we unplug USB to TTL module and plug it again to BC after five to ten seconds as we saw in Hercules module should connect your router I have opened angry IP scanner let me edit my network range and start scanning here we can see that ESP is connected to router over Wi-Fi and got again this IP address with last eight bits showing number 208 ESP is now ready to be used in my video about home automation with home assistant and MQTT that I already mentioned a few times you can see how to set up home assistant so I want to go through that again our start home assistant server from the previous project it's version is 0.98 point 3 and it is located on Windows 10 we will need to edit two things first is configuration after you install home assistant on Windows 10 go to start and write percentage app data percentage there you will find dot home assisted folder open it and inside you will find configuration let's edit configuration for our project I removed all config except light within light topic and Broker where no IP is needed if you run home assistant on PC that has IP we added in C++ a program in our case that is 192.168.1.1 this line with broker and IP was causing me an error so I removed it if you are writing configuration be careful on every line in space because of configuration is extra sensitive and it can throw errors easily now let's stop home assistant and start it again to apply configuration changes second thing to do is configure home assistant user interface open your home assistant dashboard open it in web browser and write your home assistant IP and add port 8 1 2 3 & 2 username and password and we are in press three dots in top right corner configure you I press again three dots and click bro config editor there you can paste configuration which can be found in video description when you see that configuration you should see lightbulb button like this one home assistant is now prepared for giving orders to ESP all that left is just to connect ESP to relay module and test this this should be easy just plug ESP inside connect 5 volts and ground from USB module that is connected to relay module and nothing happens ok ESP red LED is lit that is good signal let's give he s P some 10 seconds maybe it just needs more time to connect and let's test it over home assistant nope still not working let's plug and unplug USB module no not helping this is where the real problem appeared it came to this point and now realize kidding I spent quite some time searching for what the problem could be I assumed that problem is in pins wiring of relay but I couldn't fight any data and schemes for this relay module to see how pins are actually wired I was getting angry and gave up for that day few days later I checked if someone maybe posted something about that on YouTube and that's where I found this gem I'll add a video link in the description I'm checking YouTube channel which I'm very thankful to is explained that CHP deep in on this cheap module is not connected to 3 volt pin and one more thing one of resistors should be removed that means soldiering and plug-and-play won't happen in this case so first I took small piece of wire and solder CHP deep in with three world pin now harder part remove this tiny resistors and solder one of them again I removed both of them and replaced tenkill on error one resistor with two kalam f2 resistor okay really will you please work out pluckiest be yellow socket compadre light and power wires and relay module I will add these blue wire to five volts and green to ground and look at that something starts clicking that's a great sign I will open home assistant to the drive switching is working yes it's finally working [Music] okay for the end let's connect lightbulb to relay and test it please take care if working with higher voltage awesome it is working as it should be you can also open home assistant on your smartphone by simply typing IP and port eight one two three in browser I spent more time for this project that I'm client and almost gave up when saw that this relay is joking with me so much but now seeing this working I feel great and we'll be looking to implement this real life for everyday usage in the future and that's it I hope you learned something new and found useful information in this video if you enjoyed it don't forget to like it and if you want to see more content like this subscribe good luck [Music]
Info
Channel: 1BarConnection
Views: 40,532
Rating: undefined out of 5
Keywords: esp8266, esp8266ex, relay, cheap, Home, Assistant, IoT, Fun, USB, Module, MQTT, LAN, PC, router, wifi, ethernet, remote, remotely, platformio, cpp, flash, program, 1bc, 1bar
Id: L6HiulJPzgE
Channel Id: undefined
Length: 17min 43sec (1063 seconds)
Published: Sun Jun 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.