ESP 01 remote to toggle a sonoff switch

Hello fellow domoticians (is that what we’re called)

I discovered home assistant a few weeks back and I’m loving it. I managed to set a few Led lightstrips (with the help of Bruh automation) and a few sonoff’s switches ( thanks to DR. ZZZZ). All is running fine and on different schedule with the mqtt broker.

I would like to build a small bedside remote to toggle one of the sonoff’s switches I built.

I’ve seen many tutorial with the DASH button from amazon and that’s pretty much what I want to do but I don’t want to use IFTTT if possible. The little box I want to build should be on my son’s night stand so he can toggle the light from his bed. His bed room is wired weirdly; it doesn’t have a ceiling light nor switch.

I have a bunch of ESP01 and ESP12 to use.

Has anyone seen a good tutorial for this? and maybe one that would have one or multiple button?

Thanks a lot everyone for all the knowledge!


P.S. I started with arduinos last summer so I’m a hell of a newb in electronics!

Are the sonoff switches equipped with RF? Sonoff provides battery powered remotes:

Hi, you may have a look at existing firmwares for ESP8266 like Tasmota or esphomeyaml.

If you want to dig deep into the interesting stuff you may have a look e.g. at my project.

It’s a thermostat but I also have a button attached to one GPIO, realized debouncing and use MQTT including HA discovery.


I’ll look into it! The thermostat add on is a nice feature too.


My sonoffs basics don’t have RF embedded in them.

It was hard enough to get them to work, I’m a bit reluctant to touch them again.


Forgot to mention that the sonoffs already have the tasmota firmware in them already. If that makes a difference.


Maybe one additional thing, some people would not want to place a continuously powered wifi device next to their childrens bed. In this case you could look for devices that do only transmit radio waves when you actually push the button.

For this purpose I use the RPi RF HassIO Addon with a 433 MHz Remote and a 433 MHz receiver attached to my RPi hosting HA.
The received codes then trigger automations to control devices attached to HA.

Some info here:

My HA config is also uploaded to GitHub if you want to have a look.

1 Like

I did not think about that! that makes sense!

Thanks for your insight.


i just added a IR receiver to a sonoff running tasmota, then in automation i tell it what to do on wich ir code and use a old obsolete tv remote. i can control several lights, mpd, fan, whatever wich just one remote.

1 Like

7 Months later and you probably found you solution. So did make something that works for you? Else, I could share my setup. I have made a little remote control with a ESP-01 but only because, why not. Not using it daily or something, just wanted to see if it worked.

Please let me know.

It is always good to share :slight_smile:

I have been using ESPHome since a couple of months and this is what I came up with.

Attached a tactile push button to GPIO 02 paste the code in the YAML of your ESP-01 and thats about it. You can check this section on the ESPHome website

Unfortunatly I didn’t spend more time with it to enable deep sleep and just “stand-by” and wait for a button press. I just hooked it up to a slider switch, so in my case I have to power the switch on, and then I can press the button.

  name: esp_portable
  platform: ESP8266
  board: esp01_1m

  ssid: !secret wifi_ssid
  password: !secret wifi_pass

# Enable logging

# Enable Home Assistant API


  - platform: gpio
      number: GPIO02
      mode: INPUT_PULLUP
      inverted: True
    name: "ESP Portable"
      - homeassistant.service:
          service: light.toggle
            entity_id: light.light.desk
      - delayed_on: 10ms

  - platform: homeassistant
    id: homeassistant_time

Yeah esphome is great.

Is there a reason you are using the time component? It seems unnecessary in this usage, unless it is needed for the delayed_on:

It’s not needed, I just copied and paste most of my configs and I just left it there haha. I have some time based stuff