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.64k stars 412 forks source link

MINIR4 State is not known when local #1318

Open Mister-A opened 8 months ago

Mister-A commented 8 months ago

I've reviewed #1184 but don't see this particular issue discussed there.

I have a MINIR4 wifi relay.

Works fine in cloud mode, state updates when triggered remotely or via external switch.

But in local mode the device state is always seen as off.

I can implicitly set it with switch.turn_on and switch.turn_off services and the relay will respond, but as the state is always seen as off I'm unable to use it with switch.toggle (and therefore with a lovelace button card) as the state of the device is not apparantly read back so HA always assumes the device is off, so next time you toggle it tries to turn it back on, though it's already on.

When I change to cloud mode the device state does update and toggles start working again.

Am I missing something or is this a known limitation with this device?

AlexxIT commented 8 months ago

https://github.com/AlexxIT/SonoffLAN#common-problems-in-only-lan-mode

Mister-A commented 8 months ago

config_entry-sonoff-54fecd2028009820e78b145f2f4ed19f.json.txt Many thanks for the response.

Just to be sure I've been clear. Device discovers fine. Commands send to device fine. But the device state is never updated in HA when relay is triggered.

Do you expect LAN to work on this device? Can you be specific about what might cause ability to control but not get state?

Symptoms manifest the same as #1311 toggles don't work.

AlexxIT commented 7 months ago

I can see that your device works in local mode. You should collect debug logs for it.

majster-pl commented 6 months ago

@Mister-A did you manage to get it working locally? I'm having exactly the same issue.

Mister-A commented 6 months ago

No, I haven't had time to go back to it yet - I left it in cloud mode and allowed it through my firewall for now until I get a chance to debug it.

lennartwoermer commented 5 months ago

Has anyone managed to achieve this yet or are people working on it? I have also bought the MINIR4M but faced this issue.

majster-pl commented 4 months ago

@lennartwoermer I was using it with online connection for few weeks then switched to Zigbee device instead. Not sure if anyone is working on this issue.

wrcaston84 commented 3 months ago

This is my issue too

AlexxIT commented 6 days ago

I'm definitely not working on it. I don't have the device or debug information.

Mister-A commented 6 days ago

Hi Alex. I have some time to gather debug now. Not sure what you need, but for starters I toggled config to cloud, turned on debug and tried to toggle the relay a couple of times (as previously described the relay did trigger, but HA didn't know it had triggered so shows it as off.

But all it captured was the following so assuming that's not useful please can you point me to instructions on gathering the debug data you do need?

2024-09-02 10:12:46.065 WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom integration 'sonoff' accesses hass.helpers.system_info. This is deprecated and will stop working in Home Assistant 2024.11, it should be updated to import functions used from system_info directly at custom_components/sonoff/system_health.py, line 61: info = await hass.helpers.system_info.async_get_system_info(), please create a bug report at https://github.com/AlexxIT/SonoffLAN/issues
2024-09-02 10:12:46.081 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to walk with args ('/config/custom_components/sonoff',) inside the event loop by custom integration 'sonoff' at custom_components/sonoff/core/xutils.py, line 14: for root, dirs, files in os.walk(path): (offender: /config/custom_components/sonoff/core/xutils.py, line 14: for root, dirs, files in os.walk(path):), please create a bug report at https://github.com/AlexxIT/SonoffLAN/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#walk
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 456, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 285, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 366, in async_configure
    result = await self._async_configure(flow_id, user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 413, in _async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 571, in _async_handle_step
    result = await self.async_finish_flow(flow, result.copy())
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2677, in async_finish_flow
    self.hass.config_entries.async_update_entry(entry, options=result["data"])
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2049, in async_update_entry
    self.hass.async_create_task(
  File "/usr/src/homeassistant/homeassistant/core.py", line 808, in async_create_task
    return self.async_create_task_internal(target, name, eager_start)
  File "/usr/src/homeassistant/homeassistant/core.py", line 830, in async_create_task_internal
    task = create_eager_task(target, name=name, loop=self.loop)
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 37, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/config/custom_components/sonoff/__init__.py", line 257, in async_update_options
    await hass.config_entries.async_reload(entry.entry_id)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1939, in async_reload
    return await self.async_setup(entry_id, _lock=False)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1863, in async_setup
    await entry.async_setup(self.hass)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/sonoff/__init__.py", line 170, in async_setup_entry
    await system_health.setup_debug(hass, _LOGGER)
  File "/config/custom_components/sonoff/system_health.py", line 62, in setup_debug
    info[DOMAIN + "_version"] = f"{integration.version} ({xutils.source_hash()})"
  File "/config/custom_components/sonoff/core/xutils.py", line 14, in source_hash
    for root, dirs, files in os.walk(path):

2024-09-02 10:12:46.087 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to scandir with args ('/config/custom_components/sonoff',) inside the event loop by custom integration 'sonoff' at custom_components/sonoff/core/xutils.py, line 14: for root, dirs, files in os.walk(path): (offender: <frozen os>, line 366: ?), please create a bug report at https://github.com/AlexxIT/SonoffLAN/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#scandir
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 456, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 285, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 366, in async_configure
    result = await self._async_configure(flow_id, user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 413, in _async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 571, in _async_handle_step
    result = await self.async_finish_flow(flow, result.copy())
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2677, in async_finish_flow
    self.hass.config_entries.async_update_entry(entry, options=result["data"])
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2049, in async_update_entry
    self.hass.async_create_task(
  File "/usr/src/homeassistant/homeassistant/core.py", line 808, in async_create_task
    return self.async_create_task_internal(target, name, eager_start)
  File "/usr/src/homeassistant/homeassistant/core.py", line 830, in async_create_task_internal
    task = create_eager_task(target, name=name, loop=self.loop)
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 37, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/config/custom_components/sonoff/__init__.py", line 257, in async_update_options
    await hass.config_entries.async_reload(entry.entry_id)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1939, in async_reload
    return await self.async_setup(entry_id, _lock=False)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1863, in async_setup
    await entry.async_setup(self.hass)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/sonoff/__init__.py", line 170, in async_setup_entry
    await system_health.setup_debug(hass, _LOGGER)
  File "/config/custom_components/sonoff/system_health.py", line 62, in setup_debug
    info[DOMAIN + "_version"] = f"{integration.version} ({xutils.source_hash()})"
  File "/config/custom_components/sonoff/core/xutils.py", line 14, in source_hash
    for root, dirs, files in os.walk(path):

2024-09-02 10:12:46.095 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/config/custom_components/sonoff/__init__.py', 'rb') inside the event loop by custom integration 'sonoff' at custom_components/sonoff/core/xutils.py, line 20: with open(path, "rb") as f: (offender: /config/custom_components/sonoff/core/xutils.py, line 20: with open(path, "rb") as f:), please create a bug report at https://github.com/AlexxIT/SonoffLAN/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 456, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 285, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 366, in async_configure
    result = await self._async_configure(flow_id, user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 413, in _async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 571, in _async_handle_step
    result = await self.async_finish_flow(flow, result.copy())
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2677, in async_finish_flow
    self.hass.config_entries.async_update_entry(entry, options=result["data"])
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2049, in async_update_entry
    self.hass.async_create_task(
  File "/usr/src/homeassistant/homeassistant/core.py", line 808, in async_create_task
    return self.async_create_task_internal(target, name, eager_start)
  File "/usr/src/homeassistant/homeassistant/core.py", line 830, in async_create_task_internal
    task = create_eager_task(target, name=name, loop=self.loop)
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 37, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/config/custom_components/sonoff/__init__.py", line 257, in async_update_options
    await hass.config_entries.async_reload(entry.entry_id)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1939, in async_reload
    return await self.async_setup(entry_id, _lock=False)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1863, in async_setup
    await entry.async_setup(self.hass)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/sonoff/__init__.py", line 170, in async_setup_entry
    await system_health.setup_debug(hass, _LOGGER)
  File "/config/custom_components/sonoff/system_health.py", line 62, in setup_debug
    info[DOMAIN + "_version"] = f"{integration.version} ({xutils.source_hash()})"
  File "/config/custom_components/sonoff/core/xutils.py", line 20, in source_hash
    with open(path, "rb") as f:
AlexxIT commented 6 days ago

Maybe debug more broken in latest Hass version. I don't know. Error from this logs will be fixed in next release.

Mister-A commented 6 days ago

OK you want me to wait and try debug again on next release? If you have a pre-release you'd like tested please let me know.

FYI here's my general data inc HA versions ...

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2024.8.0",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.12.4",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/London",
    "os_name": "Linux",
    "os_version": "6.6.33-haos",
    "supervisor": "2024.08.0",
    "host_os": "Home Assistant OS 12.4",
    "docker_version": "26.1.4",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "presence_simulation": {
      "documentation": "https://github.com/slashback100/presence_simulation",
      "version": "4.9",
      "requirements": []
    },
    "watchman": {
      "documentation": "https://github.com/dummylabs/thewatchman",
      "version": "0.5.1",
      "requirements": [
        "prettytable==3.0.0"
      ]
    },
    "localtuya": {
      "documentation": "https://github.com/rospogrigio/localtuya/",
      "version": "5.2.1",
      "requirements": []
    },
    "frigate": {
      "documentation": "https://github.com/blakeblackshear/frigate",
      "version": "5.2.0",
      "requirements": [
        "pytz"
      ]
    },
    "tapo": {
      "documentation": "https://github.com/petretiandrea/home-assistant-tapo-p100",
      "version": "3.1.2",
      "requirements": [
        "plugp100==5.1.3"
      ]
    },
    "sonoff": {
      "documentation": "https://github.com/AlexxIT/SonoffLAN",
      "version": "3.7.3",
      "requirements": [
        "pycryptodome>=3.6.6"
      ]
    },
    "bestway": {
      "documentation": "https://github.com/cdpuk/ha-bestway",
      "version": "0.0.1",
      "requirements": []
    },
    "hacs": {
      "documentation": "https://hacs.xyz/docs/configuration/start",
      "version": "1.34.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    }
  },
  "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/f15d22b2-29f6-4dd9-9328-ca0c71902110",
    "requirements": [
      "pycryptodome>=3.6.6"
    ],
    "version": "3.7.3",
    "is_built_in": false
  },
  "setup_times": {
    "null": {
      "setup": 0.0001721238950267434
    },
    "54fecd2028009820e78b145f2f4ed19f": {
      "wait_import_platforms": -0.0003149040276184678,
      "config_entry_setup": 3.940281949006021
    }
  },
  "data": {
    "version": "e240aaf",
    "cloud_auth": true,
    "config": null,
    "options": {
      "mode": "local",
      "debug": true
    },
    "errors": [
      {
        "name": "custom_components.sonoff.core.ewelink.cloud",
        "message": [
          "Cloud processing error"
        ],
        "level": "WARNING",
        "source": [
          "custom_components/sonoff/core/ewelink/cloud.py",
          539
        ],
        "timestamp": 1725235249.221247,
        "exception": "Traceback (most recent call last):\n  File \"/config/custom_components/sonoff/core/ewelink/cloud.py\", line 539, in run_forever\n    resp = json.loads(msg.data)\n           ^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.12/json/__init__.py\", line 339, in loads\n    raise TypeError(f'the JSON object must be str, bytes or bytearray, '\nTypeError: the JSON object must be str, bytes or bytearray, not ServerTimeoutError",
        "count": 13,
        "first_occurred": 1724544053.2219403
      },
      {
        "name": "custom_components.sonoff.core.ewelink.cloud",
        "message": [
          "Cloud WS Connection error: Cannot connect to host eu-dispa.coolkit.cc:443 ssl:default [None]"
        ],
        "level": "WARNING",
        "source": [
          "custom_components/sonoff/core/ewelink/cloud.py",
          588
        ],
        "timestamp": 1725235312.248828,
        "exception": "",
        "count": 4,
        "first_occurred": 1725062502.2322583
      }
    ],
    "devices": {
      "100206ee73": {
        "uiid": 138,
        "params": {
          "bindInfos": "***",
          "version": 8,
          "init": 1,
          "rst_reason": 1,
          "rst_cnt": 1,
          "fwVersion": "1.0.1",
          "ssid": "***",
          "bssid": "***",
          "rssi": -66,
          "sledOnline": "on",
          "swMode": 1,
          "swCtrlReverse": "off",
          "relaySeparation": 1,
          "switches": [
            {
              "outlet": 0,
              "switch": "off"
            },
            {
              "outlet": 1,
              "switch": "off"
            },
            {
              "outlet": 2,
              "switch": "off"
            },
            {
              "outlet": 3,
              "switch": "off"
            }
          ],
          "configure": [
            {
              "outlet": 0,
              "startup": "off",
              "enableDelay": 0,
              "width": 26000
            }
          ],
          "pulses": [
            {
              "outlet": 0,
              "pulse": "off",
              "switch": "off",
              "width": 500
            }
          ],
          "key": 0
        },
        "model": "MINIR4",
        "online": true,
        "local": true,
        "localtype": "plug",
        "host": "192.168.1.77:8081"
      }
    }
  }
}
AlexxIT commented 6 days ago

Well. Your mini works locally. If state is wrong - you need to collect debug logs. Also you can enable debug logs for component via default Hass settings. From GUI or via YAML for logs integration.

Mister-A commented 6 days ago

Alex, I'd love to help - but I already sent you the only entries I got when I enabled debugging in the integration UI, there was no debugging information about the device, only those errors about blocking calls.

I tried adding

"loggers”: [“custom_components.sonoff”]

to the manifest, but then the integration failed to load.

If you have any specific instructions on how to collect the logs you need I'd be glad to have them.

AlexxIT commented 5 days ago

Hass config yaml. Not integration manifest https://www.home-assistant.io/integrations/logger/

Mister-A commented 5 days ago

Thank you.

I can't quite believe this and you'll no doubt find it very frustrating but I now can't recreate the problem. Yesterday I could.

When I broken the manifest in the integration yesterday I reinstalled it - even though it's the same version as before (3.7.3, files dated 31 May 2024) if I toggle to local mode it now knows the state of the relay toggle, it works as it should. I changed nothing else.

However I now find I am unable to toggle the Detach function off, it always turns itself back on. I've included debug for that below, this is similar behaviour to the original problem. In the below sequence I attempt to turn OFF Detach and I turn ON and then later OFF the relay itself:

2024-09-03 10:30:01.926 DEBUG (MainThread) [custom_components.sonoff.core.ewelink.local] 100206ee73 => Local4 | 192.168.1.77:8081 | None !! Can't read JSON 0, message='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('http://192.168.1.77:8081/zeroconf/getState')
2024-09-03 10:30:13.215 DEBUG (MainThread) [custom_components.sonoff.core.ewelink.local] 100206ee73 => Local4 | 192.168.1.77:8081 | {'switches': [{'outlet': 0, 'switch': 'on'}]} <= {'error': 0, 'sequence': '1725355813130', 'deviceid': '100206ee73', 'encrypt': True}
2024-09-03 10:30:13.550 DEBUG (MainThread) [custom_components.sonoff.core.ewelink] 100206ee73 <= Local3 | 192.168.1.77:8081 | {'fwVersion': '1.0.1', 'ssid': 'TheAldridges', 'bssid': '24:2f:d0:1a:4b:ea:', 'rssi': -56, 'sledOnline': 'on', 'swMode': 1, 'swCtrlReverse': 'off', 'relaySeparation': 1, 'switches': [{'outlet': 0, 'switch': 'on'}], 'configure': [{'outlet': 0, 'startup': 'off', 'enableDelay': 0, 'width': 26000}], 'pulses': [{'outlet': 0, 'pulse': 'off', 'switch': 'off', 'width': 500}]} | 24
2024-09-03 10:30:13.551 DEBUG (MainThread) [custom_components.sonoff.core.ewelink] 100206ee73 <= Local3 | 192.168.1.77:8081 | {'fwVersion': '1.0.1', 'ssid': 'TheAldridges', 'bssid': '24:2f:d0:1a:4b:ea:', 'rssi': -56, 'sledOnline': 'on', 'swMode': 1, 'swCtrlReverse': 'off', 'relaySeparation': 1, 'switches': [{'outlet': 0, 'switch': 'on'}], 'configure': [{'outlet': 0, 'startup': 'off', 'enableDelay': 0, 'width': 26000}], 'pulses': [{'outlet': 0, 'pulse': 'off', 'switch': 'off', 'width': 500}]} | 24
2024-09-03 10:30:21.159 DEBUG (MainThread) [custom_components.sonoff.core.ewelink] 100206ee73 <= Local3 | 192.168.1.77:8081 | {'fwVersion': '1.0.1', 'ssid': 'TheAldridges', 'bssid': '24:2f:d0:1a:4b:ea:', 'rssi': -59, 'sledOnline': 'on', 'swMode': 1, 'swCtrlReverse': 'off', 'relaySeparation': 1, 'switches': [{'outlet': 0, 'switch': 'off'}], 'configure': [{'outlet': 0, 'startup': 'off', 'enableDelay': 0, 'width': 26000}], 'pulses': [{'outlet': 0, 'pulse': 'off', 'switch': 'off', 'width': 500}]} | 25
2024-09-03 10:30:21.186 DEBUG (MainThread) [custom_components.sonoff.core.ewelink.local] 100206ee73 => Local4 | 192.168.1.77:8081 | {'switches': [{'outlet': 0, 'switch': 'off'}]} <= {'error': 0, 'sequence': '1725355821006', 'deviceid': '100206ee73', 'encrypt': True}

NOTE: attempting to open http://192.168.1.77:8081/zeroconf/getState in a browser results in Header fields are too long for server to interpret

Now I know how to obtain useful information I will continue to try and recreate the issue and get the logs, clearly from this thread I'm not the only one experiancing it so I'll try to help find the cause.

AlexxIT commented 5 days ago

Well. If local mode works for you. But sometimes it doesn't. This means possible problems in the network hardware. Router, server, or something else. Usually on good hardware mDNS works stably.

Mister-A commented 5 days ago

Just to be clear Alex - it always "worked" in that HA could always turn it on - it just never seemed (until today) to tell HA it's state so HA/your integration always assumed it was off so since it's defined as a Toggle it was impossible to use.

I'm on a single Draytek router with a Proxmox hosted HAOS installation on intel i5 MacMini hardware - nothing cheap or unusual.

Out of interest, is the following message expected?

2024-09-03 10:30:01.926 DEBUG (MainThread) [custom_components.sonoff.core.ewelink.local] 100206ee73 => Local4 | 192.168.1.77:8081 | None !! Can't read JSON 0, message='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('http://192.168.1.77:8081/zeroconf/getState')

Also are you able to comment on the Detach toggle not working - should it? Do you want me to open a new issue for that?

AlexxIT commented 5 days ago
  1. I've never heard of the brand name of your router.
  2. Proxmox could in theory be a problem for stable mDNS operation.
  3. Error message is OK. The ewelink devices do not have a normal API specification. This API may work on other devices or firmwares. And on your device it just crashes. Nothing out of the ordinary.
  4. I have no idea why detach doesn't work. Or if it should work at all. I don't have this device. And I can't check or test this function. Perhaps there are other similar issues already.
wrcaston84 commented 5 days ago

Mine always worked and I’ve had no hardware changes so that’s unlikely. My local mode works for a while but then stops which is cured after a reboot so something during use is stopping it.

On Tue, 3 Sep 2024 at 13:47, Alex X @.***> wrote:

Well. If local mode works for you. But sometimes it doesn't. This means possible problems in the network hardware. Router, server, or something else. Usually on good hardware mDNS works stably.

— Reply to this email directly, view it on GitHub https://github.com/AlexxIT/SonoffLAN/issues/1318#issuecomment-2326438277, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEQDN3CFHXTCYC4KDBMQGQLZUWVXZAVCNFSM6AAAAABBW36DTCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRWGQZTQMRXG4 . You are receiving this because you commented.Message ID: @.***>