Shelly Dimmer Wall Switch With Rotary Knob and Home Assistant Intergration

11,295

12

12

Introduction: Shelly Dimmer Wall Switch With Rotary Knob and Home Assistant Intergration

In this tutorial I will show a way to control light brightness with Shelly Dimmer by making a wall switch from rotary encoder. This approach allows you to control the light even when your Wi-Fi connection is down which adds convenience for your smart home. As soon as this functionality is not available in the default firmware I needed to create a custom implementation for that purpose. For now the firmware supports light control though rotary encoder and MQTT messages from Home Assistant.

Note: You cannot use potentiometer from old wall dimmer as it works completely different compared to rotary encoder even when it looks the same.

Message to ALLTERCO (company behind Shelly products): You can pick up the idea and integrate it in the original firmware as a first step and as a second step release a hardware addon (as you previously did for other devices) that can be sold as a separate module and be connected to the dimmer. This will allow people with less maker skills to get the same functionality out of your product that I am going to describe below.

Disclaimer: Disconnect the dimmer from AC network before flashing it with custom firmware. I am not taking any liability for your actions.

Supplies

  • Shelly Dimmer
  • Rotary Encoder
  • USB to UART module
  • Wires
  • Dupont Connector
  • Cable Tie
  • Glue (super glue or hot glue)
  • Soldering equipment
  • 3D Printer (optional, you can get knob together with encoder or re-purpose old wall dimmer housing)

Skills:

  • Solder wires
  • Flash firmware to ESP8266
  • 3D print (optional)

Step 1: Prepare the Dimmer

Connect the dimmer to your lamp and AC power and do the following:

  1. Connect dimmer to your Wi-Fi network
  2. Update to the latest firmware
  3. Configure and calibrate it to work with your lamp

After this step is done disconnect it from the AC power line.

Step 2: Make the Cables

You need to make two cables.

Flash cable

It has all 6 wires to upload the firmware. Use metal leads from the resistor as it has proper diameter and can be easily soldered to the wires. Use super glue together with baking soda to put the leads at the proper distance between each other. You may also try to use hot glue to do that instead of super glue. Solder dupont connector to the other side of the cable.

Rotary encoder cable

It requires only four wires - GND and GPIO0 for small connector and other two go to L1 and L2 screw terminals. From other side solder wires directly to the rotary encoder according to the scheme and fix it with cable tie.

Step 3: Flash the Firmware

Once the cables is ready it is possible to begin with flashing the dimmer with custom firmware that supports rotary encoder.

Take the following steps to upload firmware:

  • Install esptool
  • Download custom firmware.bin
  • Connect dimmer to your computer with USB to UART module, before power on it is required to short GPIO0 pin to GND for ESP8266 controller to enter into flash mode
  • Flash with the following command:
    esptool.py write_flash 0 firmware.bin

If there is not enough power from the USB to UART module the flashing may fail. Just try to flash several times or connect to 3.3 volts power supply that can give 350 mA or more current.

Step 4: Assemble the Wall Switch

For this step you will need 3D printed parts or you can reuse the housing from any other wall dimmer. Install the rotary encoder and connect all the wires according to the scheme. When the dimmer is powered on you should be able to connect to the Wi-Fi network named esp8266-XXXXXX where XXXXXX number is different between devices, also write down this number as it is used as a topic name for MQTT messages from Home Assistant. Once you connect you will see the screen to enter your Wi-Fi and MQTT server credentials. Syslog fields can be left intact as it is used only for debugging. Type any long password into OTA Token field. At this point rotary encoder should work.

Step 5: Configure Home Assistant

The last thing left is to configure the Home Assistant to interact with the dimmer. It can be done by adding the following config to the Home Assistant.

light:
  - platform: mqtt
    name: Living Room
    schema: json
    state_topic: esp8266/XXXXXX
    command_topic: esp8266/XXXXXX/set
    brightness: true
    qos: 1

Where XXXXXX is the string copied from the previous step.

That's it, if you want to add more functionality to the firmware you can check the code on GitHub, pull requests is welcome.

First Time Author Contest

Participated in the
First Time Author Contest

Be the First to Share

    Recommendations

    • Metal Contest

      Metal Contest
    • Fruit and Veggies Speed Challenge

      Fruit and Veggies Speed Challenge
    • DIY Summer Camp Contest

      DIY Summer Camp Contest

    12 Comments

    0
    IanIrishGuy
    IanIrishGuy

    Question 2 months ago

    Hey, this is a great little set of instructions so thanks! I've got it working as described but want to change the sensitivity. Had a look at the code and seems a simple change just modifying the following in main.cpp in onRotate

    Old: position *= 5;
    New: position *= 20;

    Just wondering how do I compile this again to get a new binary after I've updated? Not much of a C++ guy

    0
    happycrappy
    happycrappy

    9 months ago

    Is this actually safe to do? I’ve read in a number of places that gpios on the Shelly should not be used when it’s connected to ac

    0
    BSoft
    BSoft

    Reply 7 months ago

    In reality what coud not happen is the connection of an external ground/source because Shelly AC-DC is non isolated from the grid and will shortcircuit your powered external devices. There are ways to circumvent this but it's out of topic. In this case, we are just adding a rotary encoder that will work at the Shelly same potencial so there is no problem. Even then and for the same reasons we should never toutch the conductive parts of the encoder. A metal enclosure is advisable, it has to be Earthed, and a non conductive Knob should be used.

    0
    craigueh
    craigueh

    9 months ago

    Hi. Does this firmware work on the Shelly dimmer 2?

    0
    condemil
    condemil

    Reply 8 months ago

    I don't have dimmer 2 to test it out, but based on the information from other users it has different logic and will require changing the firmware code.

    0
    condemil
    condemil

    Reply 9 months ago

    I don't have Shelly dimmer 2 to try it out. You can backup your original firmware and if it is not working always revert back to the original firmware.

    0
    Lucas RangitM
    Lucas RangitM

    11 months ago

    This is a general question, but this project got me thinking. Is it possible to connect the switch inputs (L1, L2) to a DC push-button/toggle switch connected to 3.3V header output? Instead AC live/neutral. I'm out of space and looking for a way to add a switch without adding another gang box.

    0
    condemil
    condemil

    Reply 8 months ago

    I haven't tried that

    0
    palloquin
    palloquin

    Question 8 months ago

    Hi!
    I have 2 questions:
    1) the latest official firmware has a 'rotary switch' option. Does that mean they listened to you and added the option. Can we just follow your guide but use stock firmware?
    2) what type of rotary encoder did you use?
    Thanks!!! great work!

    0
    condemil
    condemil

    Answer 8 months ago

    1. The reply from Shelly support for one of the users was "it can not be used with any rotary switch. We are working on this integration. Do not use it for now."
    2. EC11 with 3 contacts for encoder and 2 contacts for push button. Not sure that the ones I have is original from Alps, but those works without issues in my case.

    0
    DavidS1168
    DavidS1168

    1 year ago

    I saved the PDF. With any luck, tomorrow my 1.27 spaced headers will arrive so I can build the programming cable and try it. Thanks a lot !

    0
    Elaina M
    Elaina M

    1 year ago

    Thanks for posting your first instructable - I hope you enjoyed the process of documenting and sharing your work !