SonoffLAN

repository·master·Indexed 25 days ago

https://github.com/alexxit/sonofflan

A Home Assistant custom component for controlling Sonoff devices using original eWeLink firmware via Local Area Network (LAN) and Cloud connections. It supports custom device classes, energy reporting for Pow devices, climate functionality for TH thermostats, and RF Bridge 433 sensor configuration.

Tokens
2.5K
Snippets
8
Records
16
Agent score
35%

What's inside SonoffLAN

  1. Use Sonoff TH Thermostat (Climate) functionality

    master

    Sonoff TH devices support an optional Climate entity.

    Modes:

    • heat: Lower temp enables switch, higher temp disables switch.
    • cool: Lower temp disables switch, higher temp enables switch.
    • dry: Controls humidity using the same low/high switch settings (Note: UI displays temperature units due to Home Assistant limitations).

    Connection Requirements:

    • Thermostat control requires a Cloud connection.
    • Main switch and TH sensors support both LAN and Cloud connections.
    • Note: For THR316D/THR320D models, temperature and humidity updates require a local connection.
  2. Install SonoffLAN via HACS or manually

    master

    You can install the SonoffLAN integration using one of two methods:

    1. Via HACS: Search for and add the repository in the Home Assistant Community Store.
    2. Manually: Download the latest release from GitHub and copy the sonoff folder into your Home Assistant custom_components directory.
  3. Configure SonoffLAN via UI

    master

    The integration is primarily configured through the Home Assistant User Interface.

    1. Go to Settings > Integrations.
    2. Click Add Integration and search for Sonoff.
    3. Follow the prompts to add your eWeLink account(s). You can set up multiple integrations if you have multiple eWeLink accounts.
  4. Enable and use the Debug page

    master

    To troubleshoot issues, you can enable a dedicated debug page via the integration configuration UI.

    1. Enable the debug page in the integration options.
    2. Reload the integrations page.
    3. Access the debug page via the Integration menu (top right dots) > Known issues, or via the direct API URL:

    http://<YOUR_HA_IP>:8123/api/sonoff/<INTEGRATION_ID>?q=<DEVICE_ID>&r=<REFRESH_RATE>

  5. Manually retrieve devicekey (deviceid and apikey)

    master

    While the component handles this automatically via eWeLink, you can manually retrieve the deviceid and apikey (devicekey) by following these steps:

    1. Put the device in setup mode.
    2. Connect your computer to the Wi-Fi network ITEAD-10000 (password: 12345678).
    3. Open http://10.10.7.1/device in a browser.
    4. Copy the deviceid and apikey.
    5. Reconnect to your Wi-Fi and set up the device via the eWeLink app.
  6. Reduce database growth for Pow devices

    master

    Sonoff Pow devices can generate high volumes of data. You can throttle the reporting frequency using the reporting configuration for power, current, and voltage.

    Configuration format: [min_seconds, max_seconds, min_delta_value]

    • min_seconds: If a new value arrives before this interval, it is delayed.
    • max_seconds: If a value arrives after this interval, it is used immediately.
    • min_delta_value: If the change in value is lower than this threshold, the update is delayed (unless max_seconds is reached).

    Example:

    sonoff:
      devices:
        1000xxxxxx:
          reporting:
            power: [30, 3600, 1]
            current: [5, 3600, 0.1]
            voltage: [60, 3600, 5]
  7. Configure Sonoff RF Bridge 433 sensors

    master

    The RF Bridge automatically creates Button entities for signals and Binary sensor entities for alarms. Binary sensors stay on for 120 seconds by default unless configured otherwise. You can use any supported device_class.

    Configuration Options:

    • device_class: Sets the sensor type (e.g., motion, door, window).
    • timeout: Seconds before the sensor auto-turns off (default 120). Set to 0 to disable.
    • name: Optional custom name for the sensor.
    • payload_off: Used for dual-state sensors (e.g., door sensors) to define the signal that triggers the 'off' state.
    # PIR Sensor Example
    sonoff:
      rfbridge:
        PIR Sensor 1:  # name in eWeLink app
          device_class: motion
          timeout: 60
    
    # Single State Sensor Example
    sonoff:
      rfbridge:
        Door Sensor 1:
          name: Door Sensor
          device_class: door
          timeout: 5
    
    # Dual State Sensor Example
    sonoff:
      rfbridge:
        Sensor1:  # name in eWeLink app (open signal)
          name: Window Sensor
          device_class: window
          timeout: 0
          payload_off: Sensor2  # name in eWeLink app (close signal)
  8. Configure custom device_class in YAML

    master

    You can override the default switch type for Sonoff devices using the device_class key in your configuration.yaml. This allows you to treat switches as lights, fans, binary sensors, or covers.

    Global default:

    sonoff:
      default_class: light

    Specific device overrides:

    sonoff:
      devices:
        1000xxxxxx:
          device_class: light
        1000yyyyyy:
          device_class: fan
        1000zzzzzz:
          device_class: window

    Multi-channel device mapping: You can map specific channels of a multi-channel device to different classes:

    sonoff:
      devices:
        1000xxxxxx:
          device_class: [light, fan]
        1000yyyyyy:
          device_class:
            - light: [1, 2, 3]
        1000zzzzzz:
          device_class:
            - switch: 1
            - light: [2, 3]
            - fan: 4
    sonoff:
      devices:
        1000xxxxxx:
          device_class: [light, fan]
  9. Customize Sonoff devices in YAML

    master

    Use the sonoff: devices: section in configuration.yaml to manually define device properties. The DeviceID is a 10-character string from the entity_id or eWeLink app.

    Available keys:

    • name: Overwrite the device name.
    • host: Force a specific IP address for the device.
    • devicekey: Manually provide the encryption key.
    • extra: Provide additional parameters like uiid for DIY mode.

    Example:

    sonoff:
      devices:
        1000xxxxxx:
          name: My Custom Switch
          host: 192.168.1.123
          devicekey: abc123def4
        1000yyyyyy:
          extra: { uiid: 136 }
    sonoff:
      devices:
        1000xxxxxx:
          name: My Custom Switch
          host: 192.168.1.123
          devicekey: abc123def4
  10. Configure energy reporting for Sonoff Pow

    master

    Sonoff Pow devices support two types of energy sensors: Regular sensors (updated in real-time via local connection, e.g., energy_day, energy_week) and Historical data (updated hourly via cloud connection, e.g., energy, energy_1).

    You can configure the update interval and history size for historical data in your YAML configuration. The history is stored in sensor attributes (max 30 days; set to 0 to disable).

    For multi-channel devices, use energy_1, energy_2, etc.

    sonoff:
      devices:
        1000xxxxxx:
          reporting:
            energy: [3600, 10]  # update interval (seconds), history size (days)
    
    template:
      - sensor:
          - name: "10 days consumpion"
            unit_of_measurement: "kWh"
            state: "{{ (state_attr('sensor.sonoff_1000xxxxxx_energy', 'history') or [])|sum }}"
  11. Configure SonoffLAN connection modes

    master

    You can choose how the integration connects to your devices via the integration configuration UI (Settings > Integrations > Sonoff > Configure):

    • auto (Recommended): Uses both local and cloud connections. If a device is reachable via LAN, the local connection is used; otherwise, it falls back to the cloud. This mode is most stable.
    • local: Uses only local network connections. Requires eWeLink credentials to access device encryption keys. Note that local protocol stability can vary.
    • cloud: Uses only the cloud server connection.

    Note: Starting in 2026, power, current, and voltage sensors will no longer be updated via cloud connections due to load restrictions on the eWeLink cloud.