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