Sonoff /eWeLink component for original firmware

@peterbuga i found solution for now:
The version i’m running is 3.3.0, S20.

this is the setup:

sonoff:
  username: ************
  password: ***********
  scan_interval: 60 
  grace_period: 99999999999
  api_region: 'eu'

Thank you. It works for me too. Change ‘cn’ to ‘as’.

Thank you sir

it works for a while and then not working. why?

2019-10-01 19:00:20 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for sonoff which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-10-01 19:00:24 DEBUG (MainThread) [custom_components.sonoff] Create the main object
2019-10-01 19:00:26 WARNING (MainThread) [custom_components.sonoff] Grace period activated!
2019-10-01 19:00:26 INFO (MainThread) [custom_components.sonoff] Found websocket address: as-pconnect1.coolkit.cc
2019-10-01 19:00:26 DEBUG (Thread-2) [custom_components.sonoff] (re)init websocket
2019-10-01 19:00:27 DEBUG (Thread-2) [custom_components.sonoff] websocket msg: {“error”:0,“apikey”:“729877e0-146d-4ece-b78b-016582da0e2a”,“config”:{“hb”:1,“hbInterval”:145},“sequence”:“15699276270111225”}
2019-10-01 19:00:34 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform sonoff
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 148, in _async_setup_platform
task = async_create_setup_task()
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 104, in async_create_setup_task
platform.setup_platform,
AttributeError: module ‘custom_components.sonoff.sensor’ has no attribute ‘setup_platform’
2019-10-01 19:00:35 INFO (MainThread) [custom_components.sonoff] Grace period active

sir

Need your help…please

2019-10-01 19:00:20 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for sonoff which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-10-01 19:00:24 DEBUG (MainThread) [custom_components.sonoff] Create the main object
2019-10-01 19:00:26 WARNING (MainThread) [custom_components.sonoff] Grace period activated!
2019-10-01 19:00:26 INFO (MainThread) [custom_components.sonoff] Found websocket address: as-pconnect1.coolkit.cc
2019-10-01 19:00:26 DEBUG (Thread-2) [custom_components.sonoff] (re)init websocket
2019-10-01 19:00:27 DEBUG (Thread-2) [custom_components.sonoff] websocket msg: {“error”:0,“apikey”:“729877e0-146d-4ece-b78b-016582da0e2a”,“config”:{“hb”:1,“hbInterval”:145},“sequence”:“15699276270111225”}
2019-10-01 19:00:34 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform sonoff
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 148, in _async_setup_platform
task = async_create_setup_task()
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 104, in async_create_setup_task
platform.setup_platform,
AttributeError: module ‘custom_components.sonoff.sensor’ has no attribute ‘setup_platform’
2019-10-01 19:00:35 INFO (MainThread) [custom_components.sonoff] Grace period active

after restart each time, i cant connect to my sonoff device. but after change the api_region to ‘cn’, restart it works again. then when restart again, it does not work. i then change the api_region to ‘as’ and it works. when restart it does not work again…I’ve to change the api_region to get it works.

Please please help…

thank sir

same problem after updating HA :frowning:

i wouldn’t call it a solution, the grace period is there for a reason (of course i could remove it but lazy people who won’t read the documentation will complain they constantly get logged out of the mobile app)

the component automatically picks the region itead servers is sending you to, you could easily remove this config line and internally you’ll be redirected to cn or as … in theory at least (for CN market, which i cannot test it, the redirection behaves slightly different and i think that’s why you encounter this problem)
are you having some kind of dynamic IP? or using proxies maybe?

Didn’t any get any issues, running without any issues for two days, i’ll update.

Thank you very much sir Peter for responding.
I’m a newbie. I followed you, read and copy all of your file required and paste.

Now, I’ve tried to update HA to 0.99.3 and the system works well. all my device are now show in HA. I did restart several times and it works superb.

Now a minute ago, i restart and it does not work…Argh…
I’ve tried your recommendation and so far so good now…Hope it will stayed as im moving to add broadlink device.

VEry sorry for myself… it still doesn’t work. when restart its not working. when I restart for another time, then it works. better than before. hehehe but still having the issue.

I’m using google wifi as my home internet service and do not know what ip I am now. maybe it is on dynamic ip. i do not know how to change to static ip via google wifi.
BUT i dont see any changes of ip after managing the ip address under DHCP ip reservation. is there a way?

Thank you sir. Thank you. thank you

I have the same problem with you
sometimes it’s crowded, sometimes not.
I think it’s due to the HA version 0,99.3

Thanks Vipk31
I’m having this problem since HA 0.99.2. My device will show for a while and then unavailable. when restart no device found. and when restart again then it shows the device back. wierd!
I’ve been trying for a month now. Very frustrating!

Thanks mate!

I am using the following solution instead.
You use google translate to read it . kkkkkkkk

1 Like

Thanks vipk31.

It works.

The only problem is to connect all device manually on id and apikey.

thank you

lan mode can’t be use with sonoff t1 3 gangs

Dear Peterbuga,

Before anything let me thank you for the awesome work! Have been using this component for 6 months and it has been working very well until now.

I´m writing this message because for the last weeks I have been having a lot of problems:

The issue I´m facing is when I restart home assistant it will not set up the component properly and my devices are unavailable. I need to reboot hassio a bunch of times to get them back online and only in 1 out of 10 reboots it works properly. Also many reboots I can see power measurement but the switch entity is unavailable.

The devices I have are 10 sonoff pow R2 with firmware 2.8.0 and 1 with firmware 3.3.1.

I have tried a bunch of things:

Restore old backup snapshots that i know where working flawlessly.
Donwgrading to different hassio versions.
Fresh install on a new SD card with only sonoff component.

Nothing seems to fix the problem. Any ideas about what can be going on?

This is what I have on the homeassistant log:

2019-10-03 23:22:54 ERROR (SyncWorker_1) [homeassistant.loader] Error parsing manifest.json file at /config/custom_components/variable/manifest.json: Expecting value: line 7 column 1 (char 6)
2019-10-03 23:22:56 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for sonoff which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-10-03 23:23:05 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:06 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:07 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:08 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:11 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:12 WARNING (MainThread) [homeassistant.setup] Setup of influxdb is taking over 10 seconds.
2019-10-03 23:23:12 WARNING (MainThread) [homeassistant.setup] Setup of person is taking over 10 seconds.
2019-10-03 23:23:12 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:13 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:14 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:15 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:15 WARNING (MainThread) [homeassistant.setup] Setup of group is taking over 10 seconds.
2019-10-03 23:23:16 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:17 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:19 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:19 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform sonoff
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/sonoff/switch.py", line 14, in async_setup_platform
    for device in hass.data[SONOFF_DOMAIN].get_devices(force_update = True):
  File "/config/custom_components/sonoff/__init__.py", line 373, in get_devices
    return self.update_devices()
  File "/config/custom_components/sonoff/__init__.py", line 355, in update_devices
    if self.is_grace_period():
  File "/config/custom_components/sonoff/__init__.py", line 322, in is_grace_period
    grace_time_elapsed = self._skipped_login * int(SCAN_INTERVAL.total_seconds())
NameError: name 'SCAN_INTERVAL' is not defined
2019-10-03 23:23:20 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:21 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:22 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'
2019-10-03 23:23:23 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x720bdd90>>: 'NoneType' object has no attribute 'attributes'

The current state of the system when this log was recorded is I can see the power and voltage but the switch entity is not available.

Thanks very much in advance!

try current master branch code. for what it’s worth the SCAN_INTERVAL variable it’s not there anymore meaning the reported error might disappear but you might end up with the ones reported above in this thread…

This is the log after a reboot and the component not being able to be loaded:

2019-10-04 10:58:43 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for sonoff which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-10-04 10:58:49 ERROR (MainThread) [homeassistant.setup] Error during setup of component sonoff
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 168, in _async_setup_component
    hass, processed_config
  File "/config/custom_components/sonoff/__init__.py", line 53, in async_setup
    hass.data[DOMAIN] = Sonoff(hass, config)
  File "/config/custom_components/sonoff/__init__.py", line 108, in __init__
    self.do_login()
  File "/config/custom_components/sonoff/__init__.py", line 192, in do_login
    self.update_devices() # to write the devices list
  File "/config/custom_components/sonoff/__init__.py", line 355, in update_devices
    if self.is_grace_period():
  File "/config/custom_components/sonoff/__init__.py", line 322, in is_grace_period
    grace_time_elapsed = self._skipped_login * int(SCAN_INTERVAL.total_seconds())
NameError: name 'SCAN_INTERVAL' is not defined

This is with the master branch:

(Devices still unavailable)

2019-10-04 11:04:05 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for sonoff which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-10-04 11:04:11 WARNING (MainThread) [custom_components.sonoff] Grace period activated!

I have rebooted 7 times, devices unavailable on every reboot, on the 7th reboot they all show up except 2. No errors in the log file.

I really don´t know what is going on but its very frustrating.

As I mentioned this happens all the time, master branch, old snapshot that worked before, fresh install of hassio with only sonoff component, etc…

Its like something changed on the outside??

Delete the cache file where the sonoff component located, after restart ha

` https://github.com/peterbuga/HASS-sonoff-ewelink/issues/154#issuecomment-538563469

also, i slightly believe itead might try to restrict the logins of this component … to be seen…

small update: i’ve tested the component in HA venv latest version + latest beta and also Hassio VM and the component works just fine!
until someone can point me how to duplicate the not-working-sonoff-bug i’m not going to address this problem anymore. i suspect that another component/package is wreaking havoc among you that i cannot seem to pin-point.

1 Like