New custom component: Sonoff LAN Mode (local, with stock firmware)

If this is a problem with working in DIY mode, I suggest you ask it on the Itead repo I pointed to earlier.

If you are struggling to find the API key when in eWeLink mode, please refer to my link to that I pointed to earlier. If you have an issue with that, please raise an issue on my repo.

Finally I have managed to get the API KEY from first Sonof Basic switch - FW:3.3.0.
I have used this method:
with my wifes IphoneX and my Macbook as laptop.
I have enter the pairing procedure and when my Sonoff paired (again) i could see in Charles my apikey:

Then i have put this in configuration.yaml and my switch is now available in Home assistant and I can control it from there.
Edit: after few minutes Sonoff device get unresponsive:

and can’t control it from Home Assistant, strange…

Please raise issue on my repo.

I have:

I have success to get Sonoff APIKEY which is not so complicated:

  1. PC/ Laptop (both Win or MAC are just fine, even Linux machine - because main debugging proxy application that is used - Charles is available for all this OS.

  2. Mobile phone (Android / iOS) with eWeLink application installed and configured (registered)

  3. Configure Charles on PC/Mac/Linux as described here, steps 1- 6

  4. If your mobile device is iOS then follow steps from above link from step 7 - step 19

  5. If your mobile device is Android you only need to add manual proxy to WIFI network where your mobile phone is connected. Proxy host is the IP address of your computer where Charles is running and the port ist 8888. In my example, it was

  6. On your computer, again go to the Proxy menu, choose SSL Proxy Settings… and check to box to enable or respective of your geographic location and the click OK

  7. Start eWeLink application on your mobile phone.

  8. On your computer, you should see or respectively, appear in the column on the left of the Charles application.

  9. Set the Sonoff device to pairing mode (press manual switch on the device for more then 7sec) - the green LED will start to blink

  10. On your mobile device in eWeLink go to + to add Device and choose Quick Pairing. Place mobile phone and Sonoff device as close to the router as possible

  11. When pairing is done you will see on the left column (window) in Charles new device appears with some IP address that fits your network (in my case it was Click on it to expand child cards beneath and find device card.

  12. On the right side of Charles select Contents and you will se something like in this picture:

  13. Copy deviceid and apikey to your configuration.yaml file to use with Sonoff LAN Mode custom component.

This is just my small contribution how to use method described in above link with Android phone…


Thanks, I’ve added these instructions to my page too.

I’ve made a new screenshot just to be more clear how to get api key. I’m glad I can contribute to such great community…

What if you are not in eu or us?

No metter which server you use (need) you could try with one of two mentioned (us / eu). Then in Charles when eWeLink is started you will se on left side all the available connection. So maybe your sever will be displayed and then you can enter this URL to PROXY configuration if needed. I think that even this isn’t mandatory to get the apikey but I can’t try myself.

1 Like

You could just use the script available at to get your apikey and all registered deviceIDs.

1 Like

Nice script… but for this custom component you need api key which is unique to each device. With this from your script (global) this custom component won’t work and all your devices will be unavailable. I have just tried…

I modified script to print device API keys -

1 Like

The modified script works well. It’s much easier to use that, compared to any other way described before.

1 Like

Hi. My component get all apikey automatically and also work in LAN Mode:

Does SONOFF L1 work with this?

So, I have this working with a US S31 and can turn it on and off just fine, but I am having trouble getting voltage and current data.

I have created the following sensors:

- platform: template
      friendly_name: Voltage
      device_class: voltage
      value_template: "{{ state_attr('switch.sonoff_10003cc38d', 'voltage') }}"
      friendly_name: Current
      device_class: current
      value_template: "{{ state_attr('switch.sonoff_10003cc38d', 'current') }}"

I expected to end up with a sensor.current_s31-3 and I did not. If I paste this into the template tester:

      friendly_name: Voltage
      device_class: voltage
      value_template: "{{ state_attr('switch.sonoff_10003cc38d', 'voltage') }}"

It results in this output:

      friendly_name: Voltage
      device_class: voltage
      value_template: "122.32"

But, I do not have a sensor.voltage_s31-3 listed in my developer tools/states. How do I see the raw output from the device to see what data points are available?

What am I doing wrong?

Hey @mattsaxon - thanks for your great work here!

I got my API keys, etc, but am having trouble connecting to the device (it’s a Sonoff SV).

Debug log is saying:

2020-03-26 17:29:19 DEBUG (MainThread) [custom_components.sonoff_lan_mode_r3.switch] HassSonoffSwitch returning _available: False

Any tips/pointers on how to debug?

Please post an issue in the GitHub repo and we can work on this there. However that is not a full debig log. Please also post a snippet of your config file

will do thanks!

Hi all,

I’ve installed the Sonoff integration in Hassio and have obtained all the device ID’s and inputted them into the configuration.yaml. But when I removed a device from eWelink, it’s no longer available in Hassio. What gives? I thought it should not longer be dependent on the cloud.