This component is no longer being maintained, instead use https://github.com/AlexxIT/SonoffLAN, which is more functional and stable. Any future contributions I make will be to this repo.
Home Assistant platform to control Sonoff switches running the V2 Itead firmware (tested on V1.8.0 - V2.6.1), locally (LAN mode).
This will not work for Sonoff devices running V3+ of the stock (Itead / eWeLink) firmware. For users of V3+, please see the code in this repository https://github.com/mattsaxon/sonoff-lan-mode-homeassistant
This is a simple platform to control switch devices which can normally only be controlled using the Itead cloud app (eWeLink). It may be useful to you if you've bought a Sonoff device and want to control it locally, but cannot flash firmware such as Tasmota for whatever reason (e.g. lack of tools or confidence soldering).
* I currently only own a Sonoff Basic so haven't actually tested with these devices. However, I am very confident that if your device works with the eWeLink app in LAN Mode, we can get it working with this component - we might need a bit of joint investigation (e.g. tcpdump
of communication from app) first to get it working!
** Some Sonoff devices seem to not boot directly into LAN mode despite internet access being blocked; there is an ongoing issue open to investigate this and attempt to automate the process of forcing a Sonoff into LAN mode. Until this is implemented / resolved, for some devices you may need to let it first boot with internet access, then block it's connectivity to get it into LAN mode (which is quite inconvenient if your device cannot be permanently powered).
Since mid 2018, the firmware Itead have shipped with Sonoff devices has provided a feature called "LAN Mode" which allows the device to be controlled directly on the local network using a WebSocket connection on port 8081.
The feature is designed to only be used when there is no connection to the Itead cloud servers (e.g. if your internet connection is down, or their servers are down). As such, it is only enabled when the device is connected to your WiFi network, but unable to reach the Itead servers. You can find out more about the feature in the Itead FAQ page.
Here's a video demonstration of a Sonoff Basic being controlled in LAN mode: https://www.youtube.com/watch?v=sxtt2cNm8g8
Before you can use this platform to control your Sonoff from Home Assistant, you should perform the following setup steps:
Congrats, you can now uninstall the eWeLink app - you'll won't need it again as your Sonoff can now be controlled directly via WebSocket messages on port 8081!
To use this platform, copy switch.py and manifest.json to the "
switch:
- platform: sonoff_lan_mode
name: // Switch Name
host: // Local IP address of device
icon: // [Optional] Custom icon for device
Example:
switch:
- platform: sonoff_lan_mode
name: Kitchen Ceiling
host: 192.168.0.72
icon: mdi:lightbulb
I'm aware this platform is very primitive at the moment, with no error handling, caching or even status checking implemented yet. I'll probably try and improve it a bit myself, but I'm new to Home Assistant so contributions are very much welcome!
For anyone else who is interested in debugging / reverse engineering the Sonoff "LAN mode" protocol, here's a packet capture I made showing the whole interaction between my internet-access-blocked Sonoff and the eWeLink app, enabling LAN mode, finding the Sonoff and switching it on/off a couple of times: https://www.dropbox.com/s/qwmkcjnvkdf8a8u/30-12-2018-12.10-filtered-sonoff.pcap?dl=0