Home Assistant Custom Component for control eWeLink (Sonoff) devices over Local Network (LAN).
Support only devices with firmware v3+. LAN should support Multicast traffic.
Supporting firmware v2 in development (read more). Unfortunately I do not have such devices.
Pros:
- work with original eWeLink/Sonoff firmware, no need to flash devices
- work over local network (LAN), no Cloud Server dependency
- work with devices without DIY-mode
- work with devices in DIY-mode
- support single and multi-channel devices
- support TH and POW device attributes
- support Sonoff RF Bridge 433 for receive and send commands
- instant device state update with Multicast
- (optional) load devices list from eWeLink Servers (with names, apikey/devicekey and device_class) and save it locally
- (optional) change device type (switch, light or fan)
- (optional) set multi-channel device as one light with brightness control
Component review from DrZzs (HOWTO about HACS)
There is another great component by @peterbuga, that works with cloud servers.
Thanks to these people @beveradb, @mattsaxon for researching the local Sonoff protocol.
- Sonoff Basic fw 3.0.1
- Sonoff Mini (no need use DIY-mode) fw 3.3.0
- Sonoff TH (show temperature and humidity) fw 3.4.0
- Sonoff 4CH Pro R2 fw 3.3.0
- Sonoff Pow R2 (show power consumption)
- Sonoff Micro fw 3.4.0
- Sonoff RF Bridge 433 (receive and send commands) fw 3.3.0, 3.4.0
- Sonoff D1 (dimmer with brightness control) fw 3.4.0, 3.5.0
- Sonoff Dual
- Sonoff iFan02 (light and fan with speed control) fw 3.3.0
- Sonoff iFan03 (light and fan with speed control) fw 3.4.0
- Sonoff S20
- Sonoff S26
- Sonoff S31 (show power consumption)
- Sonoff S55
- Sonoff SV fw 3.0.1
- Sonoff T4EU1C
- Sonoff 5V DIY
- MiniTiger Wall Switch (I have 8 without zero-line) fw 3.3.0
Minimum config:
sonoff:
username: [email protected]
password: mypassword
or
sonoff:
username: +910123456789 # important to use country code
password: mypassword
Advanced config:
sonoff:
username: [email protected]
password: mypassword
reload: always # update device list every time HA starts
default_class: light # changes the default class of all devices from switch to light
devices:
1000abcdefg:
device_class: light # changes the default class of the device from switch to light
Devices can be set manually, without connecting to Cloud Servers. But in this case, you need to know the devicekey
for each device.
sonoff:
devices:
1000abcdefg:
devicekey: f9765c85-463a-4623-9cbe-8d59266cb2e4
Examples of using device_class
:
sonoff:
username: [email protected]
password: mypassword
reload: once
devices:
1000abcde0: # corridor light
device_class: light
1000abcde1: # children's light (double switch, one light entity)
device_class:
- light: [1, 2]
1000abcde2: # toilet light and fan (double switch)
device_class: [light, fan]
1000abcde3: # bedroom light and backlight (double switch)
device_class: [light, light]
1000abcde4: # hall three light zones Sonoff 4CH
device_class:
- light # zone 1 (channel 1)
- light # zone 2 (channel 2)
- light: [3, 4] # zone 3 (channels 3 and 4)
Minimum config for devices only in DIY mode:
sonoff:
Video HOWTO from @KPeyanski
Install from HACS, automation and event trigger:
Component will create only one entity per RF Bridge - remote.sonoff_1000abcdefg
. Entity RF Buttons or RF Sensors are not created!
You can receive signals from RF Buttons and RF Sensors through an event sonoff.remote
. And send signals using the service remote.send_command
.
Although the component supports training, it is recommended to train RF Buttons through the eWeLink application.
When a command is received, the event sonoff.remote
is generated with a button number and response time (in UTC, sends the device).
command
- number of the button in the eWeLink application.
Example for receive RF signal via Automation:
automation:
- alias: Receive RF Button1
trigger:
platform: event
event_type: sonoff.remote
event_data:
name: Button1 # button/sensor name in eWeLink application
action:
service: homeassistant.toggle
entity_id: switch.sonoff_1000abcdefg
Example for send RF signal via Script:
script:
send_button1:
alias: Send RF Button1
sequence:
- service: remote.send_command
data:
entity_id: remote.sonoff_1000abcdefg
command: Button1 # button name in eWeLink application
Temperature, humidity and other parameters of the devices are stored in their attributes. They can be displayed through Template-sensor.
sensor:
- platform: template
sensors:
temperature_purifier:
friendly_name: Temperature
device_class: temperature
value_template: "{{ state_attr('switch.sonoff_1000abcdefg', 'temperature') }}"
humidity_purifier:
friendly_name: Humidity
device_class: humidity
value_template: "{{ state_attr('switch.sonoff_1000abcdefg', 'humidity') }}"
- reload - optional
always
- load device list every time HA starts
once
- (default) download device list once - default_class - optional, default
switch
, overrides default device type of all devices - device_class - optional, overrides device type (default all sonoff devices are displayed as
default_class
). May be a string or an array of strings (for multi-channel switches). Supports types:light
,fan
,switch
,remote
(only for Sonoff RF Bridge 433).
With username
and password
in the config (optional) - component loads list of devices from eWeLink Servers and save it in the file /config/.sonoff.json
(hidden file).
The component does not make other requests to servers.
The list will be loaded only once. At the next start, the list will be loaded from the local file. When you have new eWeLink devices - manually delete the file and reboot the HA.
With reload: always
in the config - the list will be loaded from servers at each start.
The list will be loaded from the local file even if you remove username
and password
from the settings.
- Put the device in setup mode
- Connect to the Wi-Fi network
ITEAD-10000
, password12345678
- Open in browser
http://10.10.7.1/device
- Copy
deviceid
andapikey
(this isdevicekey
) - Connect to your Wi-Fi network and setup Sonoff via the eWeLink app
Sonoff 4CH Pro R2, configured as a single light source with brightness control.
Devices are not displayed
- Currently only supported devices with firmware v3+
- Common problems with Multicast:
- two routers
- docker with port forwarding
- virtual machine with port forwarding
- virtualbox
- linux firewall
- linux network driver
Add to your configuration.yaml
:
logger:
default: info
logs:
custom_components.sonoff: debug
Only devices with firmware 3 and higher are supported.
All unknown devices with command switch
support will be added as switch
.
All other unknown devices will be added as binary_sensor
(always off
). The full state of the device is displayed in its attributes.
The component adds the service sonoff.send_command
to send low-level commands.
Example service params to single switch:
device: 1000123456
command: switch
switch: 'on'
Example service params to multi-channel switch:
device: 1000123456
command: switches
switches: [{outlet: 0, switch: 'off'}]
Example service params to dimmer:
device: 1000123456
command: dimmable
switch: 'on'
brightness: 50
mode: 0
- https://github.com/peterbuga/HASS-sonoff-ewelink
- https://github.com/beveradb/sonoff-lan-mode-homeassistant
- https://github.com/mattsaxon/sonoff-lan-mode-homeassistant
- https://blog.ipsumdomus.com/sonoff-switch-complete-hack-without-firmware-upgrade-1b2d6632c01
- https://github.com/itead/Sonoff_Devices_DIY_Tools/blob/master/SONOFF%20DIY%20MODE%20Protocol%20Doc%20v1.4.md