Control Sonoff devices with home-assistant — no custom firmware required
By: Sagi Rotmensh
Tags: Smart Home, Home Automation, Automation, Sonoff, Home Assistant

Sonoff are really simple devices and pretty capable even with their stock firmware. They work with Alexa and Goolge Assistant. They also work with IFTTT, which provides them with integration to many other services.

However, they don’t support home-assistant out of the box. To make Sonoff devices work with home-assistant you needed to flash the Sonoff device with custom firmware. To flash a custom firmware on a Sonoff device you need to dismantle it and connect some sort of a flashing board to it. Now I know that the Sonoff basic R3 has some sort of a DIY mode that should allow us to flash it with custom firmware. But… What if you like the stock firmware? You already use it with the eWelink app and with your favorite voice assistant. What if you already have it plugged in somewhere hard to reach?

In this case, this guide is for you.

I have flashed sonoff devices like the Sonoff RF Bridge and the Sonoff TH 10 with Tasmota in the past. It’s pretty easy to do. However, I have had some old Sonoff basic devices that were already plugged in and I didn’t want to pull them out and flash some custom firmware on them. This is why I wrote this guide.

How to control Sonoff devices without flashing custom firmware on them?

I used this method with the Sononff RF and Sonoff Basic R2, but it should work with any Sonoff device on any stock firmware version. I know there are some custom components for connecting Sonoff devices to home-assistant without flashing Tasmota on them, but AFAIK, they don’t support all Sonoff models and firmware versions. We will use IFTTT to control the Sonoff device through home-assistant and some basic script to set its state. I am going to assume you have already configured your Sonoff device through the eWelink app and that it’s already connected to your network.

Get your IFTTT API key and add the IFTTT component to home-assistant

Go to IFTTT and login to your account, or signup if you don’t have one yet. Then go to My Applets > Webhooks > Settings The API key will be the last part of the Webhooks applet

4. Add the following to your home-assistant configuration.yaml file:

# Example configuration.yaml entry

ifttt:

key: YOUR_API_KEY

Connect eWeLink app to home-assistant with IFTTT

Go back to IFTTT and find the eWeLink applet and navigate to eWeLink settings Login to your eWeLink account

After you login, it’s time to create the on and off actions

3. Click on your avatar at the top right and choose Create

4. Select the + sign next to the word this

5. Search for Webhooks

6. In the Webhooks applet select “Recieve a web request”

7. Give it an event name, for example, kitchen_light_on and click Create trigger

8. Select the + sign next to the word that

9. Search for eWelink

10. Select the one the is relevant for your device type. Since I used the Sonoff basic RF I selected: 1-Channel Switch

11. Select the switch you want to turn on, select on and click Create action

12. repeat steps 3-11 with an event for off (kitchen_light_off) and select the off action on step 11.

That’s it now you can call ifttt.trigger with the relevant event data and control your Sonoff device with home-assistant:

service: ifttt.trigger

data:

event: kitchen_light_on

I wanted to know if the Sonoff device is on or off and wanted the state to change when I use the home-assistant UI and my favorite voice assistant.

For this, I needed to do something extra.

Sonoff device state

Since we are using IFTTT to turn the Sonoff device on or off, home-assistant doesn’t know the device’s state. This would also have been the case if we would have used Tasmota and MQTT. So how can we track the Sonoff device’s state and know if it’s on/off?

We use input booleans.

Creating input booleans

To create an input boolean add the following to your configuration.yaml:

# Example configuration.yaml entry

input_boolean:

Kitchen light:

name: Kitchen light

initial: off

Create a script in home-assistant

Now that you have the IFTTT configured it’s time to create the automation that will trigger the IFTTT applet and will change the state of the input boolean accordingly.

Edit your scripts.yaml or create it Add the following entries in your scripts.yaml:

# Example scripts.yaml entry turn_off_kitchen_light:

sequence:

— service: input_boolean.turn_off

entity_id: input_boolean.kitchen_light

— service: ifttt.trigger

data:

event: kitchen_light_off turn_on_kitchen_light:

sequence:

— service: input_boolean.turn_on

entity_id: input_boolean.kitchen_light

— service: ifttt.trigger

data:

event: kitchen_light_on

These are actually two scripts: one turns off the light and changes the input boolean state to off and the other turns the light on and changes the input boolean state to on.

That’s it! this script can be called by automation in home-assistant or as a scene from Alexa. It’s also possible to set a routine in Alexa with an easier phrase. The same can be configured with Google Assistant.

To get yourself a Sonoff Basic you may use one of these affiliate links:

Sonoff R3:

https://www.amazon.com/dp/B07S46XLTR/ref=as_sl_pc_tf_til?tag=sagirot-20&linkCode=w00&linkId=bd36d7a3fc502d6b6411e297eb8a6344&creativeASIN=B07S46XLTR

Sonoff basic:

https://www.amazon.com/dp/B07KP8THFG/ref=as_sl_pc_tf_til?tag=sagirot-20&linkCode=w00&linkId=1653e127d369e6a2398b3ba8e378b6be&creativeASIN=B07KP8THFG

Now you can control your Sonoff devices from home-assistant — no custom firmware flashing required!