Programming

There are two main programming methods supported and tested with the Smart Lights X1:

  • ESPHome

  • Arduino

_images/Serial_port.jpg

In both scenarios, you will first need to enter the board into flashing mode. For that, press and hold the Flash pushbutton while you reset the board (pressing once the Reset pushbutton).

Important

For flashing new firmwares, if the OTA support is not available, you will need an external UST-to-TTL module (like this) connected to the Serial port in a way that the 3V3 are delivered directly to the microcontroller, as in the figure.

ESPHome

ESPHome is a well known platform for programming ESP-based devices with a very little effort. It is configured via YAML files and supports a wide range of functionalities and sensors.

Important

For using ESPHome, and all its funcionalities, you need to have a Home Assistant instance running in the same network as your Smart Lights X1.

_images/captive_portal-ui.png

The Smart Lights X1 already comes with an embeded version of ESPHome, that would only require an OTA update to get it ready to work in your network:

  1. Power the board, and let it run for 1-2 minutes. When the board cannot connect to a WiFi network, it will create a fallback hotspot.

  2. Use a smartphone or tablet and go to the WiFi settings, connect to the recently created Smart-Lights-X1 hotspot with the password smartlights.

  3. Access to the captive portal and open the browser if doesn’t pop up automatically.

  4. Enter your network setttings and press Save.

Now, your ESPHome device is ready to be found by Home Assistant in your network. Add it from the ESPHome section to add and edit a customized configuration file.

As an example of such configuration file (and the one flashed on the factory settings of the Smart Lights X1) with all the I/O:

 1substitutions:
 2  device_name: "smart-lights-x1"
 3  friendly_name: "Smart Lights X1"
 4  project_name: "smart.lights_x1"
 5  project_version: "1.0"
 6  ap_ssid: "Smart-Lights-X1"
 7  ap_pwd: "smartlights"
 8
 9esphome:
10  name: "${device_name}"
11  name_add_mac_suffix: true
12  project:
13    name: "${project_name}"
14    version: "${project_version}"
15
16esp32:
17  board: esp32dev
18  framework:
19    type: arduino
20
21# Enable logging
22logger:
23
24# Enable Home Assistant API
25api:
26
27# Enable Over The Air updates
28ota:
29
30#Public location of this yaml file
31dashboard_import:
32  package_import_url: github://JGAguado/Smart_Lights/docs/source/files/configuration.yaml@X1
33  import_full_config: false
34
35# Enable fallback hotspot (captive portal) in case wifi connection fails
36captive_portal:
37
38esp32_improv:
39  authorizer: none
40
41improv_serial:
42
43wifi:
44  ap:
45    ssid: "${ap_ssid}"
46    password: "${ap_pwd}"
47
48    
49light:
50  - platform: monochromatic
51    name: "Light 1"
52    id: light_1
53    output: l1
54
55output:
56  - platform: ledc
57    id: l1
58    pin: GPIO23
59    
60binary_sensor:
61  - platform: gpio
62    name: "PB1"
63    pin:
64      number: GPIO32
65    on_press:
66      then:
67        - light.toggle: light_1

Arduino

If you are still interested in programming directly with the Arduino IDE, the procedure is no different than with any other ESP32 devices:

  1. Open the Arduino IDE and go to File -> Preferences option.

  2. Add to the Additional Boards Manager URSLs the url:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
  1. Close the preferences and open in the menu Tools -> Board -> Boards Manager.

  2. Search for esp32 and install it. This might take some time.

  3. Now you can select the board ESP32 Dev Module as the target board. Leave the rest of parameters by default.

  4. Select the correct port and remember to enter the board into flashing mode before uploading the sketch.