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

Hi folks,

My first Sonoff arrived today and I was excited to get it flashed and set up to be controlled locally by Home Assistant!
Sadly, I quickly realised the latest Itead firmware (2.6.0 in my case) can no longer able to be flashed remotely with Tasmota by SonOTA, as they’ve hard-coded certificate validation into the firmware.

As I don’t have a soldering iron or the other elements needed to do a hardware flash right now, I began investigating options for controlling it locally using the stock firmware.

It turns out that there’s actually a feature built into the firmware now for exactly this, called “LAN mode”.

You have to do a few basic setup steps first (basically, initialise the Sonoff with eWeLink first, then block it from accessing the internet ever again from your router), but once set up it works great!

Full instructions and code here: https://github.com/beveradb/sonoff-lan-mode-homeassistant

I also made a short demo video (this is helpful to show what the LEDs do when it’s in LAN Mode): https://www.youtube.com/watch?v=sxtt2cNm8g8.

Give me a heads up if this is of interest to anyone, or feel free to raise issues on Github if anything isn’t quite right. I’m aware my implementation is very primitive at the moment, with no error handling, caching or even status checking implemented yet, but hope to improve it a bit more over the next few weeks.

Cheers,
Andrew

12 Likes

Just put the jumper leads into the holes only problem u need 3 hands one hold sonoff one press the button and to plug into computer i flash 3 of then yesterday now hard put a switch on to it that’s the next job

And happy new year well it is here in new Zealand

1 Like

I’m not sure what you mean, sorry? If you’re talking about flashing a Sonoff with new firmware by dismantling it and accessing the serial interface from my computer, I can’t do this as I can’t afford to buy one of the FTDI boards, and don’t want to wait for the shipping time.

With this component, i’ve got complete local control of my Sonoff from Home Assistant without even needing to flash it with new firmware, so I’m not really sure what the benefit would be either!

Happy new year anyway :slight_smile:

Well, there are several benefits of the tasmota firmware, but great appreciation on the component mate, surely very helpful if you want to just use the basic relay functionality

1 Like

It’s doable with only two hands, but it takes some practice :smiley:

1 Like

Lol After 10 of them getting it under control

Once u have it tasmota u can do HEAPS to I have 3 in the master bedroom if I do a long press on the by the door roof light and side lamp come on wait on for some bed sensor. then my new logic will if one person is in bed only the side lamp of the empty side will come on well the the logic hope I can do it

Excellent to see. Down with the cloud.

1 Like

I have a 2 channel sonoff type device that is an inching/momentary type that controls my two garage doors and works in lan mode, but I cannot get this component to work with it. The sonoff has firmware version 2.7.1

I have my router blocking the sonoff’s internet access. It is blinking two rapid blinks. When I use the ewelink app, I have to choose lan mode. When I do, it says connected to one device. I have two buttons in the ewelink app. One button for each door. These buttons work to open doors without issue while the sonoff is blinking as long as I choose Enable Lan in the app.

I have the following in configuration.yaml:
switches:

switch:
  - platform: sonoff_lan_mode
    name: Garage
    host: 192.168.1.3
    icon: mdi:garage

After reboot, i get one switch instead of two, and it doesn’t work for either door. It doesn’t give an error, but it doesn’t trigger the sonoff.

Suggestions or thoughts?

Thanks for trying the component @PlayedIn, sorry it isn’t working for you!

Unfortunately I don’t own that device so haven’t tested with it myself, but I’ve replied to your GitHub issue with instructions for gathering a tcpdump of the eWeLink app communicating with your device, which should be all we need to be able to get the component working for you :slight_smile:

Thank you very much! I will respond to the github issue once I have the data.

hi @beveradb
awesome work here (that personally i’ve been to lazy to do it this way, mostly because LAN Mode never worked for me, I’m the developer of the other sonoff component laying around here based on the cloud api)

i’m interested about a specific aspect of how this works: does the LAN Mode endpoint is available also while connected (normally) to the internet OR it only activates once the servers are out of reach?
as much as I like the idea, i hate the part where it needs to connect to internet and then manually cut the connection somehow (makes a bit harder to setup / debug and also to instruct people how to do it themselves :sweat:)

My device doesn’t need to connect to the internet first and then remove it. If the internet is blocked via firewall or ip filter, it goes straight into lan mode after a power off. My firmware is 2.7.1.

Dam, this is so close to what I need!
Everything works perfectly, until the point of checking the device state, as my main intention with this is to be able to hit the sonoff button to trigger lights (like a regular switch), so I dont have to enforce an “only cellphone control” at home…the way i see it, if home automation dont add functionality over existing one, its inconvenient rather than convenient.

I dont have the flashing device yet to put a tasmota in, and I tried the @peterbuga solution, that worked to an extent, except it takes too long and unsyncs too much with the devices.

Is there a way to pool the state of the device and update it in HA? I can try to help coding it, but ive never did a single line of python…if this were c++ tho…

Any plans on implementing this?

1 Like

@peterbuga for what I just set up here, the lan access only goes online once the sonoffs try to reach ewelink and cant.
The setup isnt that hard, just creating some internet access rules on the router to prevent their reserved ips to get any data from outside the LAN.

The only think you gotta do with the app is the initial setup, which you have to do anyways for your cloud method.

Ive been following you and ur work (btw, amazing work) for some time, trying to setup a simple wall switch while I cant get my hands on a FTDI to properly flash them.

The more I strugle with this, the more obvious it is that I need tasmota =[

If we are able to get the state of the device from this lan based solution, im guessing that we would be pretty close to what tasmota offers…

Wanna help getting this done? :smiley:

@Ariel_Marcelo_Madril from the debug dumps posted on this github project looks like with it might be possible to query (or receive via the websocket) the state of the device, but this is just a theory i’m really not planning to work on this right now (and duplicate the work of @beveradb).
as weird as it might sound i have 0 access to the router at the place i’m renting right now, meaning i have to switch the sonoff devices back and forward between router and some local laptop AP, therefore this makes developing quite tedious in my case :sweat:

i’m thinking that in the future i could have a hybrid mode and make some of best worlds: cloud access (like it’s currently right now) that’ll will have support for more devices and also will automatically setup devices (by pulling the last known devices IPs) for lan mode (as fallback)… then again, just an idea, but this definitely brings new light to the “sonoff original firmware” approach

1 Like

Bravo! Great idea and a proper way to go, especially for users that have already integrated (connected) their Sonoffs throughout apartment in hard-to-reach places.

Great, works as expected. For those who do not want to or have the ability to flash with tasmota, certainly with the latest firmware which does not allow for over the air. I dont understand why this has not been made a default component as its probably the most used switch. Setting to LAN mode takes seconds by blocking internet. The only issue there is for me, is that if there is a wifi drop out or power down to the switch it seems that the status message send back to hassio stops them working “Unexpected error in on_disconnect callbacks”. A restart of Hassio does not work so i have to carry out a complete restart - Using hassio through virtualbox. Excellent work. (Note: Unless you have updated since, i do not understand why people have recently said it would be great if the status was returned. It is, and works flawlessly) As said it should be made an official component.

I support making this official component with some good steaks

1 Like

As far as I inderstand firmware version 3.0 uses LAN mode as default. So there will be no nede to block internet access any more?