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

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 https://github.com/beveradb/pysonofflan/releases/tag/v0.3.0 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.

2 Likes

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 https://github.com/mattsaxon/sonoff-lan-mode-homeassistant.

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?
https://help.ewelink.cc/hc/en-us/articles/360007134171-LAN-Mode-Tutorial

Sorry do what? Yes, LAN mode does work via eWeLink. However this component is to enable the switches to be controlled from within Home Assistant. There are a number of ways to achieve this currently, notably 1) Custom Firmware (e.g. Tasmota), 2) control via Itead cloud using @peterbuga’s component 3) Control locally using stock firmware (which is this components approach)

It seems the itead github allows you to load any firmware OTA now - you can put the device in DIY mode by fitting a jumper - only select models no doubt but good for them. It looks pretty slick from the youtube video.

Yep, you need a ‘DIY’ branded device as far as I can tell for this jumper to be present.

Mattsaxton… I was trying to determine if LanMode = Tasmoda firmware upgrade…

No they are not the same, “LAN mode” is an Itead stock firmware feature. However both LAN Mode and Tasmota do (usually) communicate locally over the LAN.

mattsaxon. Tried your component and everything worked just fine. Use a S26 as test. After putting the S26 in AP mode I used wget to get the api_ID. A bit complicated but… In that process the S26 naturally lost connection to EweLink, so I had to pair again and make sure that the firmware and the LAN Mode is ok. Will I still need to run EweLink and have the Sonoffs paired to use your component?
What if I change the conf. yaml to use local IP instead of ID. Would that make any difference. Your Readme is a bit confusing on that point.

I wouldnt have expected it to need to be paired to eWeLink, but I haven’t tested that configuration. All my devices are paired as I felt it useful to have a backup. I’d be interested in your feedback to if it works or not.

I’m terms of IP in the configuration.yaml, I don’t think it should make a difference. However if you wish to use IP it would be under the host: key, not device_id. Although the component should work that way, I haven’t tested it for a while to be honest. I can’t actually see any specific reason to run it in that mode.

However if you think it has a use case and doesn’t work as expected. I can take a look when I get a chance. Feel free to raise an issue on the GitHub for anything that you think should be improved.

Mattsaxon. You are right. Device_id: or host: doesn’t make any difference.
But how will the Sonoff device be assigned an SSID and an IP address if it isn’t paired to EWeLink. Perhaps through wget?

Yes, I’m DIY mode, ie with the jumper set, you can assign WiFi credentials via the REST API. I haven’t tried it, but that is what the itead docs says. I’m not sure if the same API can be used in Standard mode, but it may be worth a try.

What setup are you looking to achieve?

My main purpose is to get rid of loggin into EweLink through HA. I have several times experienced that my Sonoff devices aren’t accessible after reboot with the stock firmware and the component from PeterBugga. I have also tried Tasmota and there are no problems whatsoever. But it would be easier to use stock firmware.

UPDATE. And this is exactly what I can do with this fantastic component. No problem setting things up with the help of EweLink. The important part is that HA doesn’t need to login anymore.
Go on developing Mattsaxon!!

1 Like