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

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?

And chips[1] please.

[1] fries, frites whatever…

Hey folks, thanks for the positive feedback! Glad to hear it’s already of value to some folks :slight_smile:

I just wanted to briefly address a couple of comments:

I don’t understand why this has not been made a default component carlgarton

I support making this official component Chinedu_Abia

I appreciate the sentiment, but the quality bar for code added to the main Home Assistant project is deliberately set quite high - see the Quality Scale aimed at helping developers build decent components.
Protecting this quality bar is important to ensure Home Assistant remains doesn’t become a hodge-podge of badly written code which doesn’t work very well!

While this custom component works, sometimes, it doesn’t even satisfy all of the minimal requirements for a component to be added with no score yet - never mind be given a “Silver” rating or above.

As such, I haven’t submitted a Pull Request to the main HA project as I’m confident it would be rejected at this point due to not meeting those requirements.

Once work has been done in both the pysonofflan project (underlying Python library to control Sonoff devices in LAN mode) and the sonoff-lan-mode-homeassistant to resolve various issues and improve the code quality sufficiently as per the above guidelines, I’ll submit a PR to get it added to Home Assistant properly.

As always; any contribution to the development of this component would be appreciated!
I currently have very little spare time to work on hobby projects due to work/family.

if there is a wifi drop out or power down to the switch […] hassio stops them working

Yeah, this is one of the known issues with the current implementation, and it’s a pretty serious issue!
@mattsaxon has been working on it (thanks!), you can track progress in the Github issue.

firmware version 3.0 uses LAN mode as default Bluhme

Oh wow, really? I haven’t upgraded the firmware on my test Sonoff device (and I’m wary to do so, may need to buy another device to be able to test on multiple versions) so can’t

Do you have any source for this (e.g. Itead changelog, perhaps)? I did a quick search but couldn’t find anything other than forum threads from folks having issues after upgrading to firmware 3.0.0.

with some good steaks

:cut_of_meat: :shallow_pan_of_food: :plate_with_cutlery: ?

I love this, one question for anybody who might know.

I send the sonoff Switch to HomeKit. And usually it works great, but unfortunately it seems like every other day my switch doesn’t work. Usually restarting HA fixes the problem. Another issue is sometimes if I turn a switch off in HomeKit nothing happens if I flip it back on then off it works. Is there something I can do to make this more reliable? I’m gathering a good collection of sonoff switches and have 2 th16 devices with temperature probes coming to me I’m hopeful this will work in my setup.

I’m grateful for the work put in on this!

I agree steaks are a fine payment!! Lol

Thanks! You’re welcome :smile:

If you’re a programmer (or willing to become one), sure - come over and help out in the pysonofflan project :wink:

Otherwise, I’m afraid not - there are known issues with the currently released version of pysonofflan which mean it is very unreliable right now, so you’ll have to wait for developer(s) to fix it.

On the bright side, Matt has been doing some great work over the last couple of weeks and as of last night, has confirmed his changes seem to be stable and reliable over longer-term usage!

As such, you probably don’t have long to wait now - I’ll be tagging and releasing a new version once I’ve reviewed and merged his changes and tested them myself.

If you subscribe to this topic I’ll give folks a heads up once the new version is released, or you can subscribe to release notifications in the sonoff-lan-mode-homeassistant Github repository!

Maybe one day! As of now I’m not smart enough to program. Without all you wonderful people I would be lost…

Hopefully one day, I’ll get a better grasp on it all

@beveradb has released v0.3.0 of PySonoffLan here which is much more stable to failures. It still only works with V2 firmware however, but I do have a development branch which works with V3 firmware now if anyone is interested to get involved with testing.


Can you tell me if it now supports more than one switch per sonoff?

Sorry, it does not

I have a forked version of @beveradb’s code which has been tested to work with v3.0.0, v3.0.1 and v3.1.0 (the latter being the firmware version supporting Sonoff DIY mode). You can take and look and perhaps try this here

At present time, myself and @beveradb don’t have the capacity to merge these changes into a single component that supports both older and newer firmware. The newer firmware has an entirely different API, protocol and flow. However the new component can be run side by side with @beveradb’s component to support older and newer devices at the same time. The details are on the GitHub page.

We’d both like feedback as to if this is a relevant use case in the longer term as I have now all but abandoned earlier firmware as I find the newer code and firmware more stable.

As we have limited time, this might be better utilised instead by adding additional features such as support for multi-channel devices.

Am I mistaken or do the devices do this already via the eWelink app?