---
# System prepended metadata

title: Robonomics 1 gang switch with ESPHome
tags: [R devices]

---

# Robonomics 1 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 1 gang switch pinout will be next:
![image](https://hackmd.io/_uploads/r1WiMwLt6.png)


We will use GPIO 22, 26, 35.

## 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: robonomics1_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: "Robonomics1 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: robonomics1_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: "Robonomics1 Switch"
    password: "pPJ27cuI48pD"

captive_portal:


switch:
  - platform: gpio
    pin: 22
    name: "Robonomics Switch"
    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

light:
  - platform: binary
    id: light_left
    output: led_left
    internal: true
    restore_mode: RESTORE_DEFAULT_ON

output:
  - id: led_left
    platform: gpio
    pin: GPIO26

binary_sensor:
  - platform: gpio
    name: "left button"
    pin: 35
    internal: true
    on_press:
      then:
        switch.toggle: left_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/Hku2Y13ta).
- To connect to openHAB read [this article](https://hackmd.io/@nakata5321/H1quklpKa).
