Shelly native MQTT support, Tasmota on the Shelly2, & Setting Up a 3-Way switch

Today on the hookup we’re going to take a look at the shelly2, a wifi smart relay module that installs behind your existing switch that can control two circuits and monitor power consumption either locally via MQTT or by using the shelly cloud, all for under $20.

A few weeks ago I reviewed the shelly 1 relay module and determined that it was overall a great value.  The shelly 1 was especially great for DIY smart home hobbyists like myself because of how easily the firmware could be changed, but the shelly2 doesn’t have the same exposed programming headers as the shelly1, so it’s quite a bit more difficult to install custom firmware.

In this video I’m going to show you how I easily flashed tasmota on my shelly 2 without the need for a soldering iron, but first, I’m going to show you why you might not even want to mess with the firmware now that shelly has released an update for their factory firmware that allows for local MQTT control and monitoring of their entire shelly relay lineup including the shelly1, shelly2, and the shelly4pro.  This video is going to focus specifically on the shelly2, but the instructions can be applied to any of these devices.

Before we start, here’s a quick review of the shelly2 hardware.  Inside the case there are two 10 amp relays that can be controlled remotely or triggered via the switch inputs on the shelly 2.  To install the shelly 2 you’ll need to provide an unswitched hot wire to and a neutral wire, this is not a neutral free installation unfortunately.  Each circuit has an output that sends the mains voltage on to the output this means that unlike the shelly 1, the relays in the shelly2 are not isolated from the mains voltage and cannot be used to switch low voltage.  The shelly2 also includes a single power monitoring chip which means it measures the combined power consumption of both circuits.

To access the latest firmware including MQTT support you can access your shelly device through the phone app or by navigating to the IP address of your shelly to access the web console.  Click on the update firmware button and it will download and install on it’s own.  After your shelly device reboots it will now have a tab under internet and security called “advanced developer settings” that has an option to enable action execution via MQTT.  Once you’ve checked this box you can enter your username, password, MQTT server and port.  I’d also recommend ticking the boxes for retain, and clean session, and then hit save.

At this point the Shelly2 will start to send out information about power consumption on it’s specific MQTT topics.  The topics are shellies front slash shellyswitch, dash, and then a unique identifier for the switch that turns out to be the last 6 digits of the MAC address of the shelly, front slash relay front slash, and then either power or energy depending on which value you are interested in.

The easiest way to make sure you have the correct topic is to use an MQTT client like node-red, mqtt-lens, or the new MQTT client hassio addon to subscribe to the wildcard topic shellies front slash pound sign, or hash tag, or cross hatch, or whatever you call this symbol where you happen to live.  This will subscribe to every channel that starts with “shellies”, so if you have a lot of shellies in your house, this may result in a lot of messages received.

Next you need to set up a few entities in home assistant, or your home automation platform of choice to control them.  These are the entries I use to control my switch and I have two sensors set up, one for power and one for energy.  The power is measured in watts, and energy is measured in kilowatt hours.  Unfortunately, the kilowatt hours measurement is lost if your shelly loses power, and the wattage appears to be off by almost exactly 17% for me in the US, which is most likely due to a difference in calculation between 50hz and 60hz power.  Both of these are strictly software issues and I’m told they will be addressed shortly via another over the air firmware update.

For 99% of people I would recommend using this factory firmware for your shelly2 now that is has local MQTT control and doesn’t rely at all on cloud services. If you require more advanced features, or you’re a total nut about network security like I am, then you may want to be able to install a custom firmware on your shelly2 device.  As of a few weeks ago the developer branch of the tasmota now supports both the shelly1 and shelly2 module types and has working power monitoring for the shelly2.

Before I show you how easy it is to flash the shelly2, please note that once you overwrite the shelly firmware there isn’t an easy way to reflash the original firmware.  There is a method to copy the original firmware that people have had success with when it comes to the sonoff firmware, but I’ve never used it myself and I’ve never tried it on the shelly.  I’ve put the link to the instructions in the description, if you end up trying it, let us know how it worked down in the comments.

On to the flashing… The shelly2 doesn’t have standard spacing for each gpio test hole, so you can’t solder in a header like you would on the sonoff basic, but the holes happen to be the exact right size for a standard jumper wire to be pressed into them.  The pinout for the connections looks like this from the bottom of the shelly.  Remember that you’ll also need to connect GPIO0 to ground during the boot process in order to put the ESP8266 based chip into flash mode.  After flashing tasmota you’ll need to disconnect GPIO0 from ground to get it to boot into the tasmota firmware.  At this point you can setup the shelly just like you would any other tasmota device, I’d recommend using backlog commands to get your tasmota devices set up easily if you plan on having more than a couple of them.

After flashing you’ll setup your MQTT switches in home assistant like normal using the same settings as you normally do with tasmota.  These are my favorite settings, but yours may be slightly different.  You’ll also need to set up an template sensor to pull the power information out of the tele messages sent by tasmota.  These are the specific settings I use for that.  As always, all the yaml that I mention in each video is down in the description.  For me, my power settings were auto detected and were spot on, but there is a method for calibrating your power monitoring if it’s not correct, the link for that information is down in the description as well. Overall tasmota is more accurate and more powerful than the shelly firmware, but obviously requires more initial setup, either option works well.

As a bit of a bonus, some folks have also been asking about how a shelly works with a 3-way switch configuration.  And the answer to that is, as always, that it really depends on your specific wiring setup because every country seems to do things differently, but in certain cases the shelly1 and shelly2 are perfect drop in solutions for a 3-way switch setup.

The switch terminals use a hot wire coming from your wall switch to trigger a manual toggling of the circuit, and because these terminals are expecting mains voltage they can be added very easily into a pre-existing 3 way switch circuit.  A very common way for these circuits to be installed in the US is using 2 traveler wires that carry mains voltage to a second switch that then outputs the voltage from one of those traveler wires to the circuit drain, which is usually a light.  In order to use a shelly 2 in this configuration you will install the module in the electrical box that connects directly to the light.  You’ll need to have an unswitched hot wire in this box, usually for a different light, and I’m not sure if it’s due to some electrical code, but all of my 3 way switches happen to be located in boxes that have a hot wire for another switch.  All you need to do to add the shelly to the circuit is cut the output of the 3 way switch and connect the switch side to the S1 or S2 terminal, and the light side to the O1 or O2 terminal, configure your switch as an edge switch and you’re all done.  There are of course many other ways that 3 way switches are configured, and a shelly device can probably integrate into many of them.  This is just the most common way that they are wired in the US.

Once you have it in the circuit you’ll also need to set up the switch type in the shelly firmware. This manual toggle can be set up in a few different ways.  Toggle matches the state of the switch to the status of the light meaning that if the light is off and the switch is up you’ll need to toggle the switch down and then back up to turn the light on, this is not what you want for a 3 way switch. Configuring the switch as an edge switch essentially mimics the functionality of a 2 way or 3 way switch by always changing the state of the relay, no matter which direction the switch is toggled.

I’m told that the shelly1 and shelly2 have fresh shipments at AmazonUS and are also available via the shelly website.  They are currently in the process of getting UL certified, and I’ll be sure to report to you when that happens.  Just to put it out there one more time, I don’t work for shelly, and I’m not paid to make these reviews, I just think they are good products that fill a need in the smart home community.

On that note, thank you to all of you who do support this channel through patreon and through my amazon affiliate links.  I spend a not insignificant amount of time making videos each week and while I certainly enjoy it sharing my enthusiasm for this hobby with you, your support makes it much easier to justify all of my purchases and time spent to my wife.  If you’re new to the channel and you enjoyed this video, please consider subscribing, and as always, thanks for watching the hookup.

Shelly1 AmazonUS: https://amzn.to/2PPGHbj

Shelly2 AmazonUS: https://amzn.to/2PqtE0i

 (Still listed as unavailable, shelly tells me the shipment is en route, check back soon.  I'll tweet it out once they are back in stock).

Shelly4Pro AmazonUS: https://amzn.to/2Ra8x2f

Jumper Wires that that fit the Shelly2: https://amzn.to/2PMksDc

Shelly Website: https://shelly.cloud/

Shelly2 Factory Firmware YAML: https://github.com/thehookup/shelly1tasmota/blob/master/ShellyFirmwareYaml.yaml

Shelly2 Tasmota Firmware YAML: https://github.com/thehookup/shelly1tasmota/blob/master/TasmotaShellyYaml.yaml

Firmware backup method: https://steve.fi/Hardware/backup-and-restore/?fbclid=IwAR1stkXKpwLW6h4d7n0Zq68iQhKhy23AxnnrJ33hvdLAQlHdQ1z58vjPiNs

Tasmota power calibration: https://github.com/arendst/Sonoff-Tasmota/wiki/Shelly-1-and-2

Support my channel:

Patreon: https://www.patreon.com/thehookup

US Amazon: https://amzn.to/2tphvyr

UK Amazon: https://amzn.to/2IytdMD

visit my website: http://www.TheSmartHomeHookUp.com

Follow me on Twitter: @TheHookUp1

Music by www.BenSound.com

Leave a Reply

Your email address will not be published. Required fields are marked *