AlexxIT / SonoffLAN

Control Sonoff Devices with eWeLink (original) firmware over LAN and/or Cloud from Home Assistant
https://github.com/AlexxIT/Blog
MIT License
2.58k stars 403 forks source link

How to manually add a LAN-mode device by IP? LAN mode does not work over multiple VLANs. #1427

Closed dodancs closed 3 weeks ago

dodancs commented 3 weeks ago

Hello.

I recently stumbled upon this cool HACS addon. I am just very confused when it comes to the configuration. There are a lot of mentions how this supposedly works with Sonoff devices locally without the need for an internet connection or eWeLink cloud.

So how am I supposed to set up the local device? I am trying to add a Sonoff Micro. Based on the sparse information in the readme when it comes to LAN configuration, I tried adding my device to the configuration.yml file of Home assistant like mentioned in the readme:

sonoff:
  devices:
    1001846780:
      name: Sonoff Micro
      host: 192.168.1.241

I reloaded HA, also tried to fully reboot it, but on the system information page, under Sonoff I always see "Local devices online 0 / 0". So that means I have 0 configured, which is untrue.

image

So I have tried to also retrieve the secret key from my Micro, but noticed the communication is encrypted already, only returning something like:

{"data":"m7ijhmWWrotBQGLPqKqoNnBGtSdc0ejFb1sUo/eLpjwt/cuvLoWWtjFVDaEpC56s/6MV8gd92lZsHD7ae8D6vFv1lsoU+QtcZ+Xw+zFug7dyx2RIRadGu1NXfNJJv2CwBJdhrNmgv5YZFas0tpet01su9y/5OE4HYNtIRJh1JbmOh3/yHrdxMHqeSszpJuLO"}

So then I have also tried adding the Sonoff Micro to an eWeLink account, then reconfiguring the HACS addon to use my eWeLink account. It picked up that the device exists, and now I have the following info gathered from eWeLink's Cloud:

{
  "version": 1,
  "minor_version": 1,
  "key": "sonoff/some@email.com.json",
  "data": [
    {
      "name": "Micro",
      "deviceid": "1001846780",
      "apikey": "8688e3b9-eb21-4e52-b290-85cdf2c53022",
      "extra": {
        "uiid": 77,
        "description": "20220908004",
        "brandId": "3d1851b12b2f1f9c68588e24",
        "apmac": "d0:27:03:02:de:94",
        "mac": "d0:27:03:02:de:93",
        "ui": "单通道插座-多通道版",
        "modelInfo": "4b11d747c469d004f464d105",
        "model": "CKA-DM4-GL",
        "manufacturer": "深圳松诺技术有限公司",
        "staMac": "44:5D:5E:43:21:3A"
      },
      "brandName": "SONOFF",
      "brandLogo": "https://eu-ota.coolkit.cc/logo/q62PevoglDNmwUJ9oPE7kRrpt1nL1CoA.png",
      "showBrand": true,
      "productModel": "Micro",
      "tags": {
        "m_7569_doda": "on"
      },
      "devConfig": {},
      "settings": {
        "opsNotify": 0,
        "opsHistory": 1,
        "alarmNotify": 1,
        "wxAlarmNotify": 0,
        "wxOpsNotify": 0,
        "wxDoorbellNotify": 0,
        "appDoorbellNotify": 1
      },
      "devGroups": [],
      "family": {
        "familyid": "3d335b3d33e36ffd93eead6d",
        "index": 0,
        "members": [],
        "guests": [],
        "roomid": "5b59ebd08c272161558c359e"
      },
      "shareTo": [],
      "devicekey": "a0fba68a-6825-4137-bd2e-c68945210522",
      "online": false,
      "params": {
        "bindInfos": {}
      },
      "denyFeatures": [
        "loopTiming"
      ],
      "isSupportGroup": true,
      "isSupportedOnMP": true,
      "isSupportChannelSplit": false,
      "deviceFeature": {}
    }
  ]
}

So now, I have tried to add also the devicekey from the json file that was generated by the addon from eWeLink cloud and the uiid:

sonoff:
  devices:
    1001846780:
      name: Sonoff Micro
      host: 192.168.1.241
      extra: { uiid: 77 }
      devicekey: "a0fba68a-6825-4137-bd2e-c68945210522"

I then reloaded the addon and also restarted HA, but still, I get "Local devices online 0 / 0", and the logs are basically empty, so it does not seem like the addon is doing anything, and does not even pick up the configuration of the devices:

2024-06-05 00:41:33 [D] SysInfo: {'installation_type': 'Home Assistant OS', 'version': '2024.5.5', 'dev': False, 'hassio': True, 'virtualenv': False, 'python_version': '3.12.2', 'docker': True, 'arch': 'x86_64', 'timezone': 'Europe/Budapest', 'os_name': 'Linux', 'os_version': '6.6.29-haos', 'user': 'root', 'supervisor': '2024.05.1', 'host_os': 'Home Assistant OS 12.3', 'docker_version': '25.0.5', 'chassis': 'embedded', 'sonoff_version': '3.7.3 (e240aaf)'}
2024-06-05 00:41:33 [D] LOCAL mode start

Same goes for the Sonoff device info in HA:

image

I tried the addon in both auto and lan mode and it does not work in either:

image

Here is also debug info from the addon:

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2024.5.5",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.12.2",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Budapest",
    "os_name": "Linux",
    "os_version": "6.6.29-haos",
    "supervisor": "2024.05.1",
    "host_os": "Home Assistant OS 12.3",
    "docker_version": "25.0.5",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "sonoff": {
      "documentation": "https://github.com/AlexxIT/SonoffLAN",
      "version": "3.7.3",
      "requirements": [
        "pycryptodome>=3.6.6"
      ]
    },
    "hacs": {
      "documentation": "https://hacs.xyz/docs/configuration/start",
      "version": "1.34.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "bambu_lab": {
      "documentation": "https://github.com/greghesp/ha-bambulab",
      "version": "2.0.21",
      "requirements": []
    }
  },
  "integration_manifest": {
    "domain": "sonoff",
    "name": "Sonoff",
    "codeowners": [
      "@AlexxIT"
    ],
    "config_flow": true,
    "dependencies": [
      "http",
      "zeroconf"
    ],
    "documentation": "https://github.com/AlexxIT/SonoffLAN",
    "iot_class": "local_push",
    "issue_tracker": "/api/sonoff/68a83f6c-0ce2-4e9d-af34-26b89e227559",
    "requirements": [
      "pycryptodome>=3.6.6"
    ],
    "version": "3.7.3",
    "is_built_in": false
  },
  "data": {
    "version": "e240aaf",
    "cloud_auth": false,
    "config": {
      "devices": {
        "1001846780": {
          "name": "Sonoff Micro",
          "host": "192.168.1.241",
          "devicekey": "***",
          "extra": {
            "uiid": 77
          }
        }
      }
    },
    "options": {
      "mode": "local",
      "debug": true
    },
    "errors": [],
    "devices": {}
  }
}

The reason I need LAN-only mode is that I have a separate LAN where devices do not have access to the internet, only HA. So that means that the eWeLink app is useless to me since it uses the eWeLink cloud, therefore requires an internet connection and also it does not see my Micro as online after I successfully added it, probably because they are on different LANs. So I wanted to manually tell the addon how exactly to reach my Micro and it does not want to.

BTW: The Micro is definitely reachable from HA, so there is not a network connection issue. I can ping it no problems. If you have any other things I should test, let me know, as the standard URL of /device does not respond after being configured via the eWeLink app. I tried whether I am able to set up some kind of packet forwarding in between the VLANs to make it seem like a bing multicast group, but with no luck, so mDNS will definitely not work for me. That is why I wanted to use the direct IP address in the configuration for the communication, but it seems like the addon ignores it.

ALSO: Tried to downgrade the addon to 3.6.0 as some people in other issues reported that in a new version of the addon, their devices stopped receiving updated, but to no avail. The same behavior happens with 3.6.0.

Help please? I am lost, and have no idea how to configure this properly since the documentation is lacking a lot.

PS: Secrets are randomly generated with uuidgen -r and openssl rand -hex 12 for this issue.

dodancs commented 3 weeks ago

Maybe related to: https://github.com/AlexxIT/SonoffLAN/issues/1423 , https://github.com/AlexxIT/SonoffLAN/issues/1408

dodancs commented 3 weeks ago

Further debugging seems to suggest that mDNS does not work in my setup, because I have multiple VLANs and I am not able to set up any kind of packet forwarding between them to essentially turn them into one big multicast group. So, that is why I wanted to use the IP address directly for communication, but it seems like the addon completely ignores it and the rest of the configuration.

AlexxIT commented 3 weeks ago

You have options:

dodancs commented 3 weeks ago

@AlexxIT Is it not possible to just use the configuration? Why is it necessary to use mDNS when I already have the IP address and the devicekey in my disposal? Shouldn't that be everything that is needed to establish communication with the device?

AlexxIT commented 3 weeks ago

mDNS uses as communication protocol in case of default ewelink firmware. Not only as discovery protocol.