Giter VIP home page Giter VIP logo

sonofflan's Introduction

Sonoff LAN control from Home Assistant

hacs_badge Donate Donate

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)

Component review from DrZzs

There is another great component by @peterbuga, that works with cloud servers.

Thanks to these people @beveradb, @mattsaxon for researching the local Sonoff protocol.

Tested Devices

Config Examples

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:

Sonoff RF Bridge 433

Video HOWTO from @KPeyanski

Install from HACS, automation and event trigger:

Component review from DrZzs

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

Sonoff TH и Pow

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') }}"

Parameters:

  • 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).

Work with Cloud Servers

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.

Getting devicekey manually

  1. Put the device in setup mode
  2. Connect to the Wi-Fi network ITEAD-10000, password 12345678
  3. Open in browser http://10.10.7.1/device
  4. Copy deviceid and apikey (this is devicekey)
  5. Connect to your Wi-Fi network and setup Sonoff via the eWeLink app

Demo

Sonoff 4CH Pro R2, configured as a single light source with brightness control.

Control Sonoff Devices with eWeLink firmware over LAN from Home Assistant

Change Name or Entity ID of any device:

Install with HACS

Common problems

Devices are not displayed

  1. Currently only supported devices with firmware v3+
  2. Common problems with Multicast:
    • two routers
    • docker with port forwarding
    • virtual machine with port forwarding
    • virtualbox
    • linux firewall
    • linux network driver

Devices unavailable after reboot

All devices unavailable after each Home Assistant restart. It does not depend on reload setting. Devices are automatically detected in the local network after each restart. Sometimes devices appear quickly. Sometimes after a few minutes. If this does not happen, there are some problems with the multicast / router.

Component Debugging

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

Useful Links

sonofflan's People

Contributors

alexxit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.