SuperHouse #31: Sonoff Tasmota installation and configuration

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi i'm jonathan oxa and this is super house i think the second most common question i ever get at super house is how to install tasmota firmware onto a sonoff and then how to configure it i'm going to show you a really easy way to do it what i've got here is a sonoff basic this is just factory as it comes it's running the original firmware and the only thing i've done is soldered this little four pin header onto it we need to make a connection using a usb serial adapter now i did an entire episode about this super house number 30 how to reflash any sonoff even if you don't know the pin out so i'm not going to go into the hardware now what i'm going to do is use this which is a usb to serial adapter it's a version that runs at 3.3 volts i've got it in 3.3 mode with this little switch here and this little adapter board that i designed it takes the standard six pin ftdi header converts it to a four pin header so that you can just plug it straight into a sonoff and re-flash it now you can do this of course with your own cable and if you go and look at that other video it goes into all of the hardware aspects of this so i'm going to skip over that now and assume that you already know what the connections are and that you just want to be able to get the software onto this so for the purposes of setup what i'll do is just take the usb to serial adapter with its little adapter here i'll press in the button which applies gpio0 holds hold to low and plug this in and let go so now we have a sonoff which is being powered by the usb to serial connector and it's just sitting there in bootloader mode waiting for us to send it some new software so i'm just going to leave it sitting right here on the bench and then the rest of this pretty much we're going to do from the computer first step is to download the latest version of the tasmota firmware you can get that at github.com are rensed slash sonoff dash tasmota i'll put that link in of course you don't have to type all of that out yourself once you get there you'll see that there is all of the source code for tasmota and there's a readme lots and lots of information this is an incredibly well documented project so pretty much any question you have the answer is probably there it's just a matter of finding it but to actually install it what we'll do is go to one of the releases if you look at the top here it says 69 releases that's how many releases there have been so far there is also a link down in the readme so click on that and we get to the release page the current version right now the christmas present we got from theo was sonoff tasmota version 6.4.1 but this is a point where a lot of people get really confused so let's look at what the options are here now it says assets and there are many different files to download sonoff ar sonoff basic sonoff bg and it goes on and on so which one do you download there's sign off minimal sonoff sensors hey sensors are good maybe we want that one it's not really that easy to figure it out so let's have a look just down here oh and firstly we can see supported modules these are all the different hardware devices that has motor supports starting with the sonoff basic of course the one that um kicked all of this off and there are many many more modules we can scroll down through the list and see all the different things that it supports and down here there is an explanation of the binary downloads so what we're doing here is downloading pre-compiled binaries we don't need to compile it ourselves so we don't need a development environment we're just going to take something that's already been provided and install it directly we'll get to source code later but for now we're just going to use these pre-compiled binaries because they are really super convenient but which one the explanation here tells us that there are several different classes of binary to download now in most cases the one that you will want is simply sonoff.bin dot bin is for binary so there is a minimal version there's a classic version and then there are also language specific versions if you scroll back up to this list of binaries up here you can see that there's sonoff gr h-e-h-u-i-t so if you wanted an italian version of the sonoff you would grab sonoff i t most of those binaries are these language specific versions of the sonoff so sonoff bin being essentially the the basic version and then the language specific versions of that apart from that there are a couple of fairly important variations there is sonoff sensors which add support for some extra sensors one of the trade-offs is that the sonoff software needs to fit within the small flash memory of the microcontroller that is running the device so you can't just have one version of the binary that supports every single possible platform there are different versions for different platforms and they have to be some features that are removed to allow it to fit into the memory of some boards now to help clarify which of these we want because it's still kind of confusing you can have a look down here and see what features are provided by each of these builds the minimum or minimal basic classic the sonoff build knx and sensors and there are some explanations on here as well and you can look down and see okay so the language as english great britain is supported across all of them but you can see use wps for example is only available on classic and so if you scroll down you'll see that there are some things that are turned on for some versions and not for others now the vast majority of sensors are available in the sonoff if we look at this column here this is the sonoff dash bin and the language variations and we can see that it provides most of the features that you would want most of the time it provides the web server emulation discovery it does mqtt it's got timers it does most of what you would want and you can see here in sensors it allows i squared c sht htu bmp and bh 1750 here plus some others the um the three series sht temperature and humidity sensors there are really only some oddball sensors that are not supported now if you have a particular piece of hardware for example that uses an ina-219 i don't even know what that is but you can see that's not supported by anything except the sensors build most of the time the standard sonoff build and its language specific versions are going to be the ones we want so this one right here sonoff bin that is the one that we want for pretty much anything the others are exceptions so what we do is just click on sonoff bin that will download it's pulling it down off the content distribution network and you can see i've now got so i've been in downloads so i'm going to open that and now we can see in my downloads folder i've got sonoff.bin now what i normally do is rename this i'm going to rename this to 6 underscore 4 underscore 1 because that way when i come back later and i see that i've got this binary file i know what version it is if you just download the binary it'll always just be called sonoff.bin but there's no real indication of which one you downloaded now that we have the correct binary we need some way of getting it onto the sonoff because we're not actually compiling anything we're just installing a binary we don't need a development environment all we need is a tool that will allow us to push it over the serial link onto the sonoff once it's in the correct mode we've already connected it to the usb serial adapter and powered it up while holding down the button so it's in boot loader mode once again if you don't know the details of that that's all in episode 30 so go and check that out but now that we're set up with the hardware we need a tool that will take care of the upload the tool to use is called esp tool you can get that from github.com espressive esp tool it's a little python utility which is maintained by my friend angus and it takes care of dealing with the the sonoff itself and the bootloader on the esp8266 processor that's on it and does lots of really cool things so what we can do for example before we even get started is we can use this to suck off the contents of the flash at the moment now there's an example here it's showing how to use esp tool to read out of the flash now what i'm skipping over at this point is how to install esp tool itself that will depend on your computer so just follow the instructions for your specific platform which are on this page but let's have a look at how to get the existing bootloader off it now i'm in the downloads directory now on a terminal and you can see that we've got the binary ready to go but first we want to pull down the existing memory and we need to find also the serial port so if i do a list on devty.usb modem there are a couple there i'm on a mac this same sort of process works on linux on windows if you want to find the port then you can do something like open the arduino ide and then have a look in the port list and you should see the port for your usb serial adapter but basically you just need to know what the the address is so in this case we're using devty.usb modem 142101 and what i can do is use esp tool and i'll give it that port so it's dev tty dot usb modem 14 and i'm going to use the read flash command i'm going to start from address 0 and i'm going to read out one megabyte um so that's hex one and then five zeros and we'll call pull it into say sonoff original dot bin this is the file that it's going to write now i'm just going to get this to run you can see here it's connected to the adapter and right now it's identified already that the chip is an esp8266ex and it's now pulling down the current contents of flash this takes a little while you can see it's up to 13 now so you just leave this running for a minute or two and then we will have an output file so it's almost done it's just about to finish writing out the file let's see what we've got there we're done so it took 93 seconds to read out the contents of flash that's on the sonoff and you can see now we've got a one megabyte file which is the sonoff dash origin dot bin now in theory what we could do is if we load something else onto the sonoff we could come back and load that file back onto it and then return it to factory original state i haven't actually ever bothered trying to do that but in theory we should be able to do it so what we're going to do now is use esp tool and load the sonoff 6.4.1 binary which is the tasmota firmware and then we'll get all the new features so we're going to blow away what's already on the sonoff and replace it with the tasmota firmware now i'm still in the directory where i downloaded that firmware and i'm going to call esptool again once again i'm going to give it the port of devty.usb modem 14 blah and this time instead of readflash we're going to do right flash and we're going to say we've got a one megabyte file system [Music] and flash mode we're going to set as d out we're going to start from address 0 and we're going to write using the sonoff 641 binary file now before i begin this i just need to put the sonoff back into flashing mode again so disconnected hold down the button plug it in let go of the button and now i should be able to hit enter on this command it's just found the connection and now it's writing that tesmo to binary back into the flash memory on the sonoff this is much faster than reading out the flash amazingly and so it it only takes 20 seconds or so to finish so it's getting through it now maybe 30. it doesn't take too much patience unless you're doing many many sign offs there we go 31.6 seconds well now we have the tesmoda firmware installed onto this but we need to be able to configure it how do we connect to it well there is a really clever trick built into tasmota which allows it to use captive portal technology to direct us to a setup page it's pretty cool so first thing we do is unplug it plug it back in again and this will boot up the tasmota firmware you can see that the led is blinking it's now in its setup mode and after a few seconds it will start advertising its own wi-fi network so back on my computer up here on the menu bar there's this little wi-fi icon i'm going to click on that and we'll see networks that are in range of my computer and we can see there is sonoff6392 that's the sonoff that we just flashed with tasmota it's now advertising its own wifi network so if i click on that my laptop will try to associate with the sonoff and the sonoff will then use captive portal setup system to give us a little setup screen so what we can do is click scan for wi-fi networks and this tells the sonoff to look at the local networks and see what's available and we want to bind it to the super house network so it pre-configures this and just because i've done this before my browser has auto-completed but normally what you would do is type the wi-fi password in there and my browser has auto-completed that as well now before you go any further pay close attention to the name see up here it says sonoff dash 6392 remember that because we're going to need it that is generated from the last few digits of the mac address so it'll be different for each sonoff that you set up now we come down here and click save and it's now saving that wi-fi configuration into the sonoff so now the sonoff can go off and look for my home network and then log into it it doesn't need to provide its own network anymore and on my computer it's just dropped off the network you can see the wi-fi has gone away because the sonoff rebooted and now my computer has joined my local network again okay so now this sonoff should have joined my local wi-fi but i need to find it now remember a moment ago i said that it had the name sonoff dash well what we can do is come into a browser and i'll add a new tab and i'll type in sonoff6392.low you can see that i've already done this before so my browser has remembered it but basically just take that host name that the sonoff was reporting add.local on the end hit enter this web interface that's coming off the sonoff now allows us both to control it by clicking the toggle button and also to configure it to suit the particular hardware and our home automation setup so the first thing you can do is if you just click the toggle this is actually turning the output of the sonoff on and off but first let's go down to information this is where we get a whole lot of information about this particular sonoff device itself we can see the version of the software 641 which is what we expect to have just installed and a whole lot of other information including what access point it's connected to and the signal strength we can see the host name so this is what we've connected to just up here it's reporting it down here we can also see what ip address that's been given what gateway it's received this was all configured using dhcp and the dns server in this case it's a pi hole running on my local network and very importantly we can see the mac address now the mac address is really useful because what we can do is use that to set up a static lease in the dhcp server for the network if you ever want to be able to do things like set your sonoffs to an address and make sure that they're always given that ip address when they start up if you add a static lease using this mac address then each time the sonoff starts up the dhcp server will give it the same address i don't normally worry about that because i access them through mqtt and we'll see more of that in just a second but there is one really useful thing that i do here and that is i normally make up a little sticker which includes this information because later when we want to get to this on off we may not have easy access to this so i've just copied the mac address there and i'm going to switch over to a label program this is a standard little label and this one is what was it six nine i've gotta look back at the interface now six three nine two so i'll put in six three nine two and we also need an address to go in here so let's see what we've got back down here we've got mqtt information and this fallback topic i'm going to explain all of this in just a moment but for now i'm simply going to copy this go back to my label program stick this in here and i'll give this a consistent font size and then print myself a little label all right so now i've got a sticky label with the hostname on it and the mac address and also the fallback address so i just stick that onto the case that's going to be the cover from when i reassemble the sonoff and later on if i pick that song off up i can see exactly what it is and i can find it on the network if i need to because i've got its mac address so now we'll switch back to the browser and have a look at some more of these headings we've got the flash size and some other information there but for now we'll just go back to the main menu let's go into configuration really the very first thing you do with a new module is going to configure module and this is where you can select what hardware platform you're on it comes up with sonoff basic by default now that just happens to be what i've got but maybe you've got some other device so if you've got for example a sonoff power r2 you come down here select sonoff power hit save and that will make sure that tasmota is set up with all of the correct pin mappings and things to be able to control and get the data from whatever device it is that you're using i'm just going to leave that on basic and i'm not going to hit save i'll go back to configuration but what we can also do down here is configure things like mqtt now i'm going to put in the ip address of my whoops the mqtt broker on my local network and there are a couple of things here that you really need to pay attention to first thing is that there is a client id you can see this percent06x that is a placeholder which takes the last six hexadecimal digits from the end of the mac address and it uses it to generate a unique client id that's very important because if you have multiple devices connecting to an mqtt broker they each have to have a unique client id otherwise you get really weird things happening you'll have devices that go deaf and they can't talk to the broker or you'll have things that are published and then a device doesn't hear it so you need to make sure that there is a unique id if you leave that setting exactly as it is there will be an id generated based on the mac address and then you'll be good so that's fine now you can also set an mqtt username and password on my particular broker right now that i'm testing with this doesn't have a username and password so i can just leave this as it is and down here we have topic this is really interesting and really important by default the topic is simply sonoff now this is used with a couple of other elements to build up a full topic and that you can see down here so there's a prefix and then topic so the value that goes in here is substituted with the value that's up here and what we're going to end up with is a full topic which is going to be the prefix whatever that is that will be either cmnd or teller or whatever and we'll look at that in just a second then in here it will say sonoff and then afterwards it will have the parameter whatever it is that you're wanting to control and for most things you can just leave this as it is now the idea with this topic string is that you can configure it to suit whatever you like you can give each of your song offs a unique name essentially so that you can easily send commands to them and get information back from them and what i did with my first few sign offs was i made the topic for the first one sign off one then for the next one was sonoff 2 etc and i had to keep track of what number i was up to and it was really annoying so you can customize that topic if you like if you wanted to have some human readable purpose for example but my preference these days is to customize things as little as possible so what i do is leave that topic untouched i just leave it as on off now yes what that means is that i'm going to have multiple sign offs all subscribed to the same topic and if i send a command to say cmnd slash sonoff power on then all the sign offs will turn on but in reality what i do is i totally ignore that topic and instead i use a fallback topic and that means that i don't have to mess around with configuration or remembering what the particular things are on each sonoff so i'm just going to hit save on this this may all sound very confusing right now hopefully it'll make sense very soon now that i've saved it it's restarting and in a moment the sign off will come back up and we will be able to get to it on the main menu so it's restarted already only takes a couple of seconds and if we go back into configuration and configure mqtt we can now see that it has the host set so this will have now connected to my local mqtt broker and announced that it's live but what we can do is go back to back out of here to main menu and back to information and now this is where we see something interesting in relation to mqtt we can see that it has the host defined and the username and password we don't care about but here we see there is a topic of sonoff this is what could have been customized but i've left it unchanged and we can see there's a group topic of sonoffs and that can be modified as well but just not through this web interface and then there is the full topic which is cmnd sonoff so if we send a command to cmnd slash sonoff slash power then we can turn the output on or off but what we see here is the fallback topic now this is really useful the fallback topic is intended to be some way that you can always communicate with the sonoff if you lose track of any other method and it's derived from the mac address so as you can see it's got 4f98f8 on this and the topic is cmnd and then dves underscore mac address underscore fb for fallback now that will stay the same no matter what else you change on the sonoff you can change the normal topic you can change the group topic that's fine this fallback topic will remain unchanged and what i found is most useful in my application at least is simply using the fallback topic to communicate with it i don't worry about the configurable topic or the group topic the idea with the group topic is that you can put multiple sonoffs into the same group for example if you had a few sonoffs controlling lights in one part of your house and then you could send a command to the group topic and that whole group would turn on or off but i found that it's easier to move that sort of macro level configuration into the home automation system don't worry about doing it within the sign offs just treat those as if they are devices in isolation and then in your configuration for your home automation system you can do things like turn on all the lights in one part of the house by sending commands to the individual sonoffs so the way i personally use it is i ignore the normal topic i ignore the group topic and i use the fallback topic to address each song off individually and then i just configure that within openhab now if we jump out of here and back into the main menu we can see that there is some other interesting stuff here there is the firmware upgrade and what this means is that you can now do an over-the-air upgrade and put a new version of tasmota onto it either by pointing it at a url like a release binary and then the test motor will download it and apply it itself or if you have a file locally you can just click on choose file go into downloads or whatever and start upgrade so you don't need to connect the usb to serial adapter to the sonoff once you've installed tes motor once it's on there you can then push out over the air updates which is fantastic and we can also go into the console and what this provides is a list of all of the events that the sonoff has recorded it's like a log we can see here for example that it's been set up and connected to wi-fi dns is initialized it's been given an ip address we can see it's attempted connection to mqtt it's got a successful connection and then it's published some information and it's attempted a reconnection so we can see the history of what's happened here but most of the time you won't care about that now back into configuration and there are some other options here that we haven't really looked at jumping down towards the end we can reset to the test mode of defaults we can also download a backup of the configuration once we're happy with it or we can restore configuration so if you've spent a bit of time into configuring your test motor system you can just download the backup of the configuration and you can restore later if necessary that can be really useful if you are doing say an updated version of motor if you're doing a major version release then the settings may not be retained as you upgrade the software on the sonoff and you don't want to go through and reconfigure it so you can upload the configuration and set it back the way it was now we can also go into configure other and we can set up a web admin password there's not actually anything in here at the moment but very interestingly and this is very useful we can set an emulation mode what i can do is change this to belkan wemo single device and save this is going to restart the sonoff but what it will be doing now is pretending to be a balcon wemo device and because that particular device is very well supported by home automation systems it means that we can take advantage of things like auto discovery if you are running openhab or home assistant or some other home automation system that supports the belkan wemo power control devices it will now see the sonoff just as if it was a balcon device and it will be able to auto discover it that's really handy to make it easy for setup also in configuration we can have a look at things like configuring timers but once again i never bother with this sort of thing directly within the sonoff because things like timers are better handled in an overall home automation system if you wanted to do something like set up a sonoff in a very simple stand-alone system so that security lights for example you might want to have it so that it'll turn lights on in the evening turn them off at midnight and so that they're just operating during evening hours and you don't want to have that interacting with a home automation system you can set the timers in here and then the sonoff will just do exactly what it's meant to at the right time and if you use a demotics home automation system you can set some compatibility options in there as well i don't use demotic so i don't even know what those are but if you use demotics go for it so as you've seen the sonoff is extremely configurable when you have the tize motor firmware installed on it all sorts of options you can turn on but for me the most important thing is mqtt support so that i can run them on my local network and it talks to my local mqtt broker and it doesn't connect out to any cloud service that way i can use my own mqtt broker to send commands and check status and i don't rely on anything external if my internet connection goes down it doesn't matter all of my sonoffs will keep working just fine well now that we've configured tasmota on the sonoff we can talk to it through mqtt this is where it gets really useful integrating it with a home automation system so let's check that out i'll exit out of this configuration back to the main menu and i'm just going to drag this off to the side a bit so that we can see our terminal at the same time as the web interface and what we'll do is go down here into information because what i want to do is look at the mqtt settings we can see in here for example the fallback topic we'll need that in just a moment so on my local machine i'm going to subscribe to the um the appropriate topics on the mqtt broker and my host is that and i'm going to subscribe to a topic that might look a little bit strange to start with i'm going to start with a plus then i'm going to copy this part of the configuration paste that in put a slash and then a plus on the end so what we're doing here is looking at an mqtt topic or a set of topics that have wild cards at the start and the end so the topic can start with anything it can finish with anything but it must have this string in the middle that means that we can now subscribe to a whole lot of different topics at the same time and these are all the topics that are related to this particular sonoff with this particular id so i'll just hit enter on that and we now subscribe to those topics now we don't actually have to do that i'm just doing this for demonstration purposes because what we can do now that we are subscribed to those topics is we can see all of the messages that pass backwards and forwards so we can see the commands that we're about to send to the sonoff and what happens all right so we're going to go back to the main menu just so that we can see what's happening with the sonoff and then i'm just going to open a new terminal i'll zoom it in a little bit so you can read it easily and then i'll stick it down towards the bottom of the screen so that we can see the other things all at the same time i want to be able to see the topics we've subscribed to up here on the right we can see the sonoff web interface in the background and now we can publish commands and have them sent to the sonoff and we'll send it to that same mqtt broker and the topic we're going to publish to is cmnd for command and then that fallback address and then power which is the particular attribute that we want to control and the message we want to send is on so when i send this command from my local machine it's going to be published to the mqtt broker we're going to see that message and the response up here and the sonoff should be able to pick it up so i'll press enter and we can see that the command was sent and back here in the web interface you can see it's actually updated with the current status and if i now send it a command of off the sonoff will turn off its output and shortly the web interface updates as well and here we can see the the command that we've sent and then we can see in the stat topic the result of actually turning off the power so now if we look at the actual sonoff itself i'll grab the physical device put it up near the camera so that you can see it i don't know if we're going to get proper focus there and i'm going to send the mqtt message of on and you can see the led turned on now i'll send the message off and the led turned off so we now have control over this sonoff using mqtt simply by sending messages to the specific topic we can turn the output on and off and if this was a a power model we'd be able to get things like the power consumption figures from the load if it had sensors on it like a temperature sensor or humidity sensor and it was the appropriate model you just set the model inside the tasmota configuration we'd be able to get that data as well so now we have a sonoff loaded with tasmota fully ready to be integrated into a home automation system now this entire video has been filmed without having mains power connected to this at any point all of this flashing and configuration has been done purely with the sonoff powered by the usb to serial converter never try to connect up and re-flash these while they have mains power applied it's really dangerous but now the time has come we can disconnect from this and connect it to mains once it's actually connected up now but because it's got tes motor and that supports over-the-air updates we can now push new updates of firmware to it over wi-fi we don't actually need to reconnect the usb to serial converter again so we can go back to the original case put this in and click the case all closed again and the hardware is totally unmodified it's just running that new firmware i can't get the button aligned let's do it this way put it in there so the button goes through the hole and clip the back cover on there we go and then if we put these on we basically have a sonoff that is back in its original condition apart from the fact that it now has that tasmota firmware on it and we can connect that up control it by mqtt or whatever we want to do we can push firmware updates to it over the year so it's taken a device that was already really useful and made it an absolutely indispensable part of a diy home automation system thank you for watching i hope you have lots of fun with the sonoff particularly with the tasmota firmware and i'd also like to say a special thank you to theo for developing that firmware it makes a um a device that was already really cool incredibly useful so thanks theo it's uh it's been a really big contribution to the diy home automation movement so have lots of fun and go out and make something cool see ya
Info
Channel: SuperHouseTV
Views: 128,227
Rating: 4.8945007 out of 5
Keywords: sonoff, tasmota, esptool, openhab, home assistant, home automation
Id: IcOFeIcLFFo
Channel Id: undefined
Length: 37min 20sec (2240 seconds)
Published: Mon Feb 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.