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 405 forks source link

Sonoff does not load entities without internet #234

Closed mishoco closed 2 years ago

mishoco commented 3 years ago

Hello dear, I have HA running on windows 10 hyperv. I bought Sonoff products as these are the only ones available in the market here. I got one Sonoff RF Bridge and one Mini Switch and one Camera GK-200

Using the below code in configuration.yaml, HA is loading all of the three entities together with the RF sensors:

sonoff:
  username: xxx
  password: xxx
  rfbridge:
    Door Sensor:  # sensor name in eWeLink application
      name: Door Sensor # optional, you can change sensor name
      device_class: door  # e.g. door, window
      timeout: 60
    Motion Sensor:  # sensor name in eWeLink application
      name: Motion Sensor # optional, you can change sensor name
      device_class: motion
      timeout: 60  # optional (default 120), timeout in seconds for auto turn off

I disconnected the DSL plug from the router to test loading entities locally, the above three entities were not loaded. I added the below code to the configuration file but with no avail:

mode: local
reload: always

Can you please advise what is wrong or missing here as i tried all possible ways I know.

Thank you. Michel

wishie commented 3 years ago

Can you please post your config again, using the 'insert code' tag, so its formatted properly?

reload: always forces the code to check the cloud on each startup. This should only been needed if you need to check the cloud every single time.

mode: local forces only local (LAN) mode. This should not be needed either, as by default the code will use cloud and local automatically as is needed. You would only need to force 'local' only if you really really don't want the devices potentially talking to the internet.

mishoco commented 3 years ago

Hey wishie, Here is the code i used:

sonoff: username: xxx password: xxx rfbridge: Door Sensor: # sensor name in eWeLink application name: Door Sensor # optional, you can change sensor name device_class: door # e.g. door, window timeout: 60 Motion Sensor: # sensor name in eWeLink application name: Motion Sensor # optional, you can change sensor name device_class: motion timeout: 60 # optional (default 120), timeout in seconds for auto turn off

Here is the debug log when there is an internet connection: 2020-09-14 06:47:21 DEBUG main SysInfo: {'version': '0.114.4', 'dev': False, 'hassio': True, 'virtualenv': False, 'python_version': '3.8.3', 'docker': True, 'arch': 'x86_64', 'os_name': 'Linux', 'os_version': '5.4.63', 'supervisor': '243', 'host_os': 'HassOS 4.13', 'chassis': 'vm', 'docker_version': '19.03.11'} 2020-09-14 06:47:21 DEBUG main AUTO mode start 2020-09-14 06:47:23 DEBUG sonoff_cloud Redirect to region: as 2020-09-14 06:47:27 DEBUG sonoff_cloud 3 devices loaded from the Cloud Server 2020-09-14 06:47:27 DEBUG main 1000c4909b == Init | {'uiid': 1, 'extra': {'manufacturer': 'SONOFF', 'model': 'MINI', 'sw_version': 'PSF-BD1-GL v3.6.0'}, 'params': {'version': 8, 'sledOnline': 'on', 'switch': 'off', 'fwVersion': '3.6.0', 'rssi': -73, 'staMac': '...', 'startup': 'stay', 'init': 1, 'pulse': 'off', 'pulseWidth': 60000, 'swMode': 2, 'bindInfos': {'scene': 2}, 'swCtrlReverse': 'off', 'cloud': 'online'}} 2020-09-14 06:47:27 DEBUG main a640002ac8 == Init | {'uiid': 87, 'extra': {'manufacturer': 'coolkit', 'model': 'GK-200MP2B', 'sw_version': 'GK-200MP2B'}, 'params': {'romVersion': '24520191030', 'version': 7, 'cloud': 'offline'}} 2020-09-14 06:47:27 DEBUG main 1000bd4c9a == Init | {'uiid': 28, 'extra': {'manufacturer': 'SONOFF', 'model': 'RFBridge', 'sw_version': 'PSF-BRA-GL v3.5.0'}, 'params': {'version': 8, 'sledOnline': 'on', 'ssid': 'blink921', 'bssid': 'c4:6e:1f:58:8f:a0', 'init': 1, 'fwVersion': '3.5.0', 'rssi': -53, 'staMac': '...', 'setState': 'arm', 'rfList': [{'rfChl': 0, 'rfVal': '2698015E03F2C9CE0E'}, {'rfChl': 1, 'rfVal': '262A01680406AA4329'}], 'cmd': 'trigger', 'rfChl': 1, 'rfTrig1': '2020-09-13T18:07:47.000Z', 'rfTrig0': '2020-09-13T18:07:23.000Z', 'cloud': 'offline'}} 2020-09-14 06:47:29 DEBUG sonoff_cloud Cloud init: {'error': 0, 'apikey': '...', 'config': {'hb': 1, 'hbInterval': 145}, 'sequence': '1600055249043'}

and this one without internet connection: 2020-09-14 06:51:13 DEBUG main SysInfo: {'version': '0.114.4', 'dev': False, 'hassio': True, 'virtualenv': False, 'python_version': '3.8.3', 'docker': True, 'arch': 'x86_64', 'os_name': 'Linux', 'os_version': '5.4.63', 'supervisor': '243', 'host_os': 'HassOS 4.13', 'chassis': 'vm', 'docker_version': '19.03.11'} 2020-09-14 06:51:13 DEBUG main AUTO mode start 2020-09-14 06:51:18 ERROR sonoff_cloud Coolkit API error: Cannot connect to host eu-api.coolkit.cc:8080 ssl:default [Try again]

wishie commented 3 years ago

Remove the reload: always and how me the logs please.

You should have a file called .sonoff.json in your config directory.. can you confirm it is there please

AlexxIT commented 3 years ago

@mishoco read readme "common problems in only LAN mode" section

mishoco commented 3 years ago

@wishie I confirm that .sonoff.json file is there. Here is the log with mode: local and without the reload: always 2020-09-14 16:02:54 DEBUG main SysInfo: {'version': '0.114.4', 'dev': False, 'hassio': True, 'virtualenv': False, 'python_version': '3.8.3', 'docker': True, 'arch': 'x86_64', 'os_name': 'Linux', 'os_version': '5.4.63', 'supervisor': '243', 'host_os': 'HassOS 4.13', 'chassis': 'vm', 'docker_version': '19.03.11'} 2020-09-14 16:02:54 DEBUG main LOCAL mode start

mishoco commented 3 years ago

@AlexxIT I checked the readme and i have the below: Devices are not displayed

Only supported devices with firmware v3+: i have firmware 3.5 Common problems with Multicast: two routers: I have only one router virtual machine with port forwarding. you must use bridge virtual network mode (not NAT mode): i am using HyperV External Network Bridge mode

AlexxIT commented 3 years ago

@mishoco maybe your HA and devices in different VLAN. Or you have block traffic between LAN devices. Or HyperV has problems with Multicast like VirtualBox.

mishoco commented 3 years ago

I can confirm that they are on the same LAN subnet. Alex is there a way to troubleshoot Multicast?

AlexxIT commented 3 years ago

You can try to enable zeroconf logs...

logger:
  default: warning
  logs:
    zeroconf: debug
mishoco commented 3 years ago

Thank you Alex for the feedback. I got one related error to sonoff from the log when i restarted HA with no internet as below:

Log Details (ERROR) Logger: homeassistant.setup Source: custom_components/sonoff/sonoff_cloud.py:282 First occurred: 9:28:36 PM (1 occurrences) Last logged: 9:28:36 PM

Error during setup of component sonoff Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/setup.py", line 191, in _async_setup_component result = await task File "/config/custom_components/sonoff/init.py", line 102, in async_setup if await registry.cloud_login(config[CONF_USERNAME], File "/config/custom_components/sonoff/sonoff_main.py", line 110, in cloud_login return await self.cloud.login(username, password) File "/config/custom_components/sonoff/sonoff_cloud.py", line 282, in login if resp.get('error') == 406: AttributeError: 'NoneType' object has no attribute 'get'

mishoco commented 3 years ago

I also have this detailed log when mode: local is used DetailedLog.txt

AlexxIT commented 2 years ago

Probably fixed in latest master-version