Blog 2Smart (EN)

ESPHome-based LED strip controller: a smart device without programming

ESPHome-based LED strip controller: a smart device without programming
In the previous article, we described how to make an addressable LED strip controller and write firmware based on the 2Smart Cloud SDK. This article will show you how to write a fully compatible firmware for the same controller, but based on ESPHome.

Why another article on creating a controller?


Details on how to make a LED strip controller and write a firmware for it are here. The first article describes how to create firmware using the platform SDK, a powerful tool that we recommend to most vendors.

However, in many cases, ESPHome is a fairly functional tool. Its main advantage is simplicity. Using ESPHome, it will be easier for you to modify the firmware and add new functionality — for example, connect additional sensors and create a smart multitool.

You can use the firmware configuration provided in this article as part of the code configuration for a more complex device. You can also use the LED strip controller to compare two firmware creation tools for the ESP32 microcontroller: SDK and ESPHome.

What you need to get started


  • Controller. You can find a list of components and a description of the assembly of the device in the previous article.
  • Address LED strip.
  • Power supply.
  • USB-micro-USB cable for flashing.

Creating an ESPHome based controller firmware


1. Log in to the vendor account – https://cloud.2smart.com/.

2. On the “Products” page, click “Create Product” (the same button on the main screen launches a step-by-step assistant – the sequence of steps in the instructions below may vary slightly).

Products screen of the 2Smart Cloud vendor cabinet

3. Select the microcontroller – ESP32.

Choosing a microcontroller to create a device

4. Add the device name and icon – they will be displayed in the 2SmartCloud mobile app.

Device name and icon

5. Click "Add Firmware" and select the ESPHome base.

Choosing the firmware base

6. Paste the controller firmware code into a new window. Documentation and ready-made examples for ESP Home will help you write the code. We used such sources:


After selecting the appropriate lines of code, we added controller effects and included support for the Reset button and Wi-Fi signal sensor in the firmware.

Full code from our example:

light:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: 18
    num_leds: 300
    rgb_order: GRB
    name: FastLED WS2812 Light
    id: light_rgb
    effects:
      - random: null
      - pulse:
          name: "Fast Pulse"
          transition_length: 0.5s
          update_interval: 0.5s
      - strobe: null
      - addressable_scan:
          move_interval: 50ms
          scan_width: 4
      - addressable_random_twinkle:
          twinkle_probability: 20%
          progress_interval: 100ms
      - addressable_color_wipe: null
      - addressable_rainbow: null
      - addressable_fireworks:
          name: Fireworks Effect With Custom Values
          update_interval: 32ms
          spark_probability: 10%
          use_random_color: false
          fade_out_rate: 120
binary_sensor:
  - platform: gpio
    id: led_switch
    pin:
      number: GPIO5
      mode: INPUT_PULLUP
      inverted: true
    name: Led switch
    on_click:
      then:
        - light.toggle: light_rgb
  - platform: gpio
    id: change_effect
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: true
    name: Change effect
    on_click:
      then:
        - lambda: !<!lambda> |-
            uint32_t total = id(light_rgb)->get_effects().size();
            uint32_t curr_idx = 0;
            uint32_t i = 0;
            std::string curr_effect = id(light_rgb)->get_effect_name();
            auto call = id(light_rgb)->turn_on();

            // set first effect in list
            if (strcasecmp(curr_effect.c_str(), "none") == 0) {
              call.set_effect(1);
              call.perform();

              return;
            }

            for (auto *effect : id(light_rgb)->get_effects()) {
              i++;
              if (strcasecmp(effect->get_name().c_str(), curr_effect.c_str()) == 0)
                curr_idx = i;
            }

            if (curr_idx == total) {
              call.set_effect(0);
            } else {
              call.set_effect(curr_idx + 1);
            }

            call.perform();
  - platform: reset_sensor
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: true
    name: Reset button
    filters:
      - delayed_on: 1s
sensor:
  - platform: wifi_signal
    name: WiFi1 Signal
    update_interval: 30s
    id: wifi_config

Firmware code

7. Save the firmware code. On the product screen, click "Build Firmware” for the test device. Enter the credentials of your Wi-Fi network – they will be transmitted to the device in the test firmware code for a quick Internet connection.

Wi-Fi settings for building the test device firmware

8. Wait until the firmware building is completed. Click "Download".

Building the test device firmware

Link to download the archive with the firmware

9. Connect the controller to the computer using a USB cable.

Attention! Disconnect the LED strip from the controller before proceeding with the flashing!

10. Unpack the downloaded archive, enter the folder with the received files and read the instructions for the flashing in the readme.md file.

You can flash the device using Mac OS, Linux, and Windows devices; we used Mac OS.

Contents of the firmware folder

11. Clear microcontroller memory – for Mac OS, this is the following command
./2smart.sh erase_flash -d /dev/tty.SLAB_USBtoUART.

Clearing microcontroller memory

12. Wait for the cleanup and run the firmware installation command ./2smart.sh write -d /dev/tty.SLAB_USBtoUART

Installing firmware on the microcontroller

13. After completing the firmware installation process, return to the platform – the device will connect to it automatically. The successful connection is indicated by a green indicator and the Ready status in the "Device Status" field.

Successful connection of the test device to the platform

14. Click "Preview State" and you will see the data of all device sensors.

Device sensor data

15. Click "Add Layout" to open the mobile application emulator.

Configuring the mobile app interface

16. Appropriate widgets are automatically created for all sensors on your device. You can customize the appearance of the application as you like, including choosing other types of widgets than the default ones. You can also set a convenient order of widgets on the screen.

Selecting a widget to control device functions

17. Please note – you can already control the device from the computer screen at this stage. After completing the interface configuration, click "Save".

Mobile app emulator

18. Launch the 2Smart Cloud mobile application on your smartphone; you have probably already used it to connect and control a virtual lamp. Log in with the same username and password that you used to register in the developer's account.

19. Your new device is already displayed in the app. Please test the functionality of all widgets.

List of connected devices

Device management interface

Example of a widget in the 2Smart Cloud mobile application interface

20. Return to the platform and click "Build Firmware" for the production device. The final version of the firmware will be built, which does not contain the parameters of your Wi-Fi network and other specific lines of code that are necessary for testing the prototype. Download the archive.

Build Production Firmware

21. Click "Publish" – and the product will be available to users for pairing with a mobile device.

The device has been successfully published and is available to users

22. Flash the device with production firmware similar to the test firmware. Do not forget to clear the memory of the microcontroller beforehand.

Attention! Disconnect the LED strip from the controller before proceeding with the flashing!

Use the following commands:

./2smart.sh erase_flash -d /dev/tty.SLAB_USBtoUART
./2smart.sh write -d /dev/tty.SLAB_USBtoUART

Cleaning the memory of the microcontroller and installing the firmware of the device

23. Return to the mobile application, log in with any parameters as a regular user.

24. Click the "Add Device" button on the "Devices" screen – the pairing procedure will start.

Pairing the device with the 2Smart Cloud mobile app

25. Select "Others" from the list of devices available for pairing. Then click "Continue".

Pairing the device with the 2Smart Cloud mobile app

Pairing the device with the 2Smart Cloud mobile app

26. Enter the credentials of your Wi-Fi network to transfer it to the device for connecting with the Internet.

Wi-Fi network credentials for connecting the device

27. After flashing the production firmware, the microcontroller opens a Wi-Fi hotspot with a name that matches the name of your device on the platform. Connect to this network in the next step.

Mobile device Wi-Fi settings button

Mobile device Wi-Fi settings

28. Wait for the pairing to complete.

Pairing the device with the 2Smart Cloud mobile app

Pairing the device with the 2Smart Cloud mobile app

29. Now your LED strip controller is displayed on the Devices screen. Make sure you can control it from your smartphone screen.

List of connected devices

That's it! We have created a LED strip controller without programming and using assembler programs. The firmware code for ESPHome was written according to the documentation for this base. In fact, we just took ready-made examples and used them on our device.

Simplicity is the main advantage of ESPHome. Therefore, even if you plan to use firmware based on our SDK on production devices, we recommend testing the product using simpler tools. This reduces the time to create an IoT device.
Made on
Tilda