# Robonomics 2 gang switch with ESPHome
The Robonomics team creates devices with a type-c port for **open-source firmware** updating. Today we will upload [ESPHome](https://esphome.io/) firmware on it and connect it to Home Assistant.
## Requirements
To write our firmware on ESPHome we need to know the pinout of the switch. Robonomics devices come with pre-installed open-source firmware Tasmota, and after connecting the device to your wi-fi network you can visit the device and find its pinout. For 2 gang switch pinout will be next:

We will use GPIO 21, 22, 25, 27, 32, 34.
## ESPHome
This article assumes that you already have ESPHome. Create a new project. The Robonomics switch uses `ESP32` and `esp32dev` as a board.
After finishing with ESPHome wizard you will get a similar yaml file:
```
esphome:
name: robonomics2_switch
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
password: ""
ota:
password: ""
wifi:
ssid: "<YOUR_WI-FI>"
password: "<YOUR_PASSWORD>"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Robonomics2 Switch"
password: "pPJ27cuI48pD"
captive_portal:
```
ESPHome gives a lot of variants of device configuration, so the provided configuration file may be only one of the variants. The full configuration file will be next:
```
esphome:
name: robonomics2_switch
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
password: ""
ota:
password: ""
wifi:
ssid: "<YOUR_WI-FI>"
password: "<YOUR_PASSWORD>"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Robonomics2 Switch"
password: "pPJ27cuI48pD"
captive_portal:
switch:
- platform: gpio
pin: 21
name: "Robonomics Room Left"
id: left_switch
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- light.turn_off:
id: light_left
on_turn_off:
- light.turn_on:
id: light_left
- platform: gpio
pin: 22
name: "Robonomics Room Right"
id: right_switch
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- light.turn_off:
id: light_right
on_turn_off:
- light.turn_on:
id: light_right
light:
- platform: binary
id: light_left
output: led_left
internal: true
restore_mode: RESTORE_DEFAULT_ON
- platform: binary
id: light_right
output: led_right
internal: true
restore_mode: RESTORE_DEFAULT_ON
output:
- id: led_left
platform: gpio
pin: GPIO25
- id: led_right
platform: gpio
pin: GPIO27
binary_sensor:
- platform: gpio
name: "left button"
pin: 34
internal: true
on_press:
then:
switch.toggle: left_switch
- platform: gpio
name: "right button"
pin: 32
internal: true
on_press:
then:
switch.toggle: right_switch
```
### Switch component
First, we will add a `Switch component` to control relays in the switch. Here you can provide any name for your switch. Other information is not changed, if you are not familiar with ESPHome programming.
Advanced option - In the current configuration status LED on the switch will be on when the switch relay is off (inverted mode). If you want direct status led, swap places strings `on_turn_on:` and `on_turn_off:`.
### Light and Output components
These two components are needed to control the status led on the switch. Leave this part unchanged.
### Binary Sensor component
To control the smart switch from physical buttons, you need to connect it to ESP. For this use the "Binary Sensor" component. Again, you don't need to change anything in this part.
## Configuration
After changing all parameters in configuration file, save it and close. Connect the device to PC and upload firmware with next command - `esphome run <NAME_OF_CONFIGURATION_FILE>`. Wait until firmware will compile and choose upload over the cable.
That's all. Now you can connect the deivce to home automation operating systems.
- To connect to Home Assistant read [this article](https://hackmd.io/@nakata5321/By3wIxhK6).
- To connect to openHAB read [this article](https://hackmd.io/@nakata5321/SJcA1Z2Ya).