Sonoff /eWeLink component for original firmware

I have had many months of great service from this component but just recently (last 3-4 days) it has started to misbehave. I am finding that the switches are becoming unavailable after a few minutes after boot up of HASSIO.

Looking at the log I see


2019-11-21 08:41:54 WARNING (MainThread) [custom_components.sonoff] Grace period activated!
2019-11-21 08:43:41 ERROR (Thread-3) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x722f46b0>>: string indices must be integers
2019-11-21 08:43:41 ERROR (Thread-9) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x722f46b0>>: string indices must be integers
2019-11-21 08:45:50 ERROR (Thread-9) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x722f46b0>>: string indices must be integers
2019-11-21 08:45:50 ERROR (Thread-3) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x722f46b0>>: string indices must be integers
2019-11-21 08:45:52 ERROR (Thread-3) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x722f46b0>>: string indices must be integers
2019-11-21 08:53:04 WARNING (MainThread) [custom_components.sonoff] Grace period activated!
2019-11-21 09:03:14 WARNING (MainThread) [custom_components.sonoff] Grace period activated!

I know grace period suggests that I have logged in to the Ewelink service twice but the thing is that I haven’t as far as I know! Whenever I use the Ewelink app, I remove the Sonoff component config from HASSIO (And restart) so it doesn’t interfere, then I restore it and restart HASSIO afterwards.

I am still running the Websocket release from January 2019 because it has been working fine for me this whole time. I don’t think I have updated HASSIO since then either.

Any pointers would be much appreciated! And apologies in advance if this has already been covered above. I looked but I couldn’t find anything reporting this particular issue.

@Michaelrch have you tried to update to the latest version of the component? you could also try this dev branch too, it has a patch to a recent API change that was throwing the grace period off

Thanks Peter. That didn’t go so great. I seem to have broken things.

I replaced the files in custom_components/Sonoff with the new ones from the Dev branch. When I restarted, all my switches were not available.

I was running HASSIO 0.91 so wondered if the new code only worked with a newer version. I updated. I still couldn’t see my switches.

I switched to the master branch and copied in those files (removing fan.py etc). After restarting the switches are still unavailable.

It looks my my configuration.yaml should still work.

The only mention of Sonoff in the log looks like this

2019-11-21 13:47:42 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.

So I am a bit stuck and not sure what to check next… Any suggestions would be much appreciated!
Thanks again

you must copy all the files as they are present in the project’s folder, this component is not so advanced to have autodiscovery properties :blush:, also it wouldn’t hurt to use the format custom_components/sonoff (notice the small ‘s’)

another option would be enable HA debug for sonoff component, this should throw more error messages

Thanks! I am making progress. I am running with logger in debug and I a seeing all the devices being setup.
I notice that they all have the device ID preceded by sonoff_. Is that something I can remove as all my config is in the format that expects just switch.1000xxxx? I can of course update my config if needed - I’m just being lazy as I have quite a few switches :wink:
Also, when I look in the Entities list, the Sonoff devices don’t show up, which was confusing me a bit. Not sure why that is. But I can add devices to the gui so that’s a win.
Thanks again

edit: doh! entity_prefix!

always read the docs :wink:

“entity_prefix this option removes the sonoff_ prefix from entities name (it’s more or a less a compatibility mode between previous master vs websocket branch implementations)”

Thanks very much, I just spotted this. Sorry!

All fixed! Thanks very much. And yes.
I must always read the manual. X100 :wink:
And no more grace periods :+1:

Hey there,

I was using the sonoff-bulb on 0.99 version as i have a bulb i need to control.

A couple of days ago i lost connection to all the devices so i updated to the latest master branch and everything came back to normal, except my one bulb device.

I’m right now in the process of updating to 0.102.

Is there any way currently available to add the bulb functionality?

Hello. I followed your @peterbuga tutorial exactly as you instructed but the code that I added to the configuration.yaml file is causing my HA not to boot if I restart my RBP.

I kept the configuration file quite simple to troubleshoot the problem but still, I have the same issue. I checked my syntax 20 times in the config file and everything looks okay. When I remove the sonoff code from my configuration file, HA works gain.

Here is my config file:


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Sonoff Sensors configuration
sonoff:
  username: !secret sonoff_username
  password: !secret sonoff_password
  scan_interval: 60 (optional, lower values than 60 won't work anymore!)
  grace_period: 600 (optional)
  api_region: 'eu' (optional)
  entity_prefix: True (optional)
  debug: False (optional)

I always get the following error in the log file:

2019-11-23 20:26:11 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] while parsing a block mapping
  in "/config/configuration.yaml", line 20, column 3
expected <block end>, but found '<scalar>'
  in "/config/configuration.yaml", line 24, column 20
2019-11-23 20:26:11 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while parsing a block mapping
  in "/config/configuration.yaml", line 20, column 3
expected <block end>, but found '<scalar>'
  in "/config/configuration.yaml", line 24, column 20

PS. the files are also exactly in the folder location as you instructed.

Any suggestions?

Might be wrong here, but…try taking out the text in brackets in your config file…either comment them or delete.

The log errors are down to the structure of the config not this component :+1:t2:

1 Like

Hi @Gav_in. Thanks for the suggestion! I solved the problem by removing everything in the brackets :smiley:

1 Like

Hi,
I downloaded 3 init.py sensor.py switch.py files to homeassistant/custom_components/sonoff.
Added

sonoff:
  username: [email protected]
  password: pass
  scan_interval: 60 ##(optional, lower values than 60 won't work anymore!)
  grace_period: 600 ##(optional)
  ##api_region: 'eu' ##(optional)
  entity_prefix: True ##(optional)
  debug: True ##(optional)

to configuration.yaml
When going to Configuration validation, I am getting:
Configuration invalidCHECK CONFIG
Component error: sonoff - Integration ‘sonoff’ not found.
I set 755 permission for sonoff folder
What I did wrong?

Did you try restarting HA before adding the config entries but after downloading the component? The config check will fail when the component isn’t loaded (which it isn’t until you restart after d/l the files)

Thanks for this, I have tried a few times to try share 2 devices to the 2nd eWeLink app, but no luck.
When I click share, it shows the screen sharing box. Press OK
Sending share invitation message, please wait. [OK] or [Cancel]
if you push OK, it tells you “can’t send more than 1 invitation within 3mins”
pressing cancel or back, logging out of 1st EL account, into 2nd account, there is no invitation message.
If I do it immediately, after 1 min, no change. Nothing I do gets the devices into 2nd account.

If I wait (approx 3 mins) it just refreshes the page to share devices.

I will try at home when I have another phone to use and see how it goes.

Edit: needed to use 2 phones. Invite showed up immediately on other phone, accepted and done.
Now need to update the component I guess. I am not updating firmware of my sonoff devices to 3.3 as it seems to ruin update frequency on Pow R2 according to many

Thank you for attention!
Following your recommendation, I commented sonoff entries in config file and rebooted RPi. Uncommented lines and checked HA config:

Configuration invalid
Component error: sonoff - Integration ‘sonoff’ not found.
It’s driving me crazy!!!

Update: It turns out that there was an existing issue caused by a change in the eWeLink server back before October, and for some reason the problem wasn’t triggered for me until yesterday. There was already an experimental fix posted under the sonoff component on Github, and it did fix this problem for me.

Original:
My internet service went down briefly today (about 30 min), and when things cames back up I rebooted the router and restarted Home Assistant to get everything back in sync. Everything came back except my one Sonoff eWeLink switch, which shows stubbornly “Unavailable”. I also get a notification saying that the sonoff component cannot be set up. I’ve unplugged and replugged the switch, verified that eWeLink, Google, and Alexa can all control it, restarted Home Assistant several times, rebooted the HA server, removed the Sonoff integration from configuration.yaml, restarted, then put it back. I even tried creating a new eWeLink account and sharing the device to it as suggested. Nothing works.

I see this in the log:

Error during setup of component sonoff

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/setup.py", line 153, in _async_setup_component
    hass, processed_config)
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/__init__.py", line 53, in async_setup
    hass.data[DOMAIN] = Sonoff(hass, config)
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/__init__.py", line 108, in __init__
    self.do_login()
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/__init__.py", line 192, in do_login
    self.update_devices() # to write the devices list
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/__init__.py", line 357, in update_devices
    if self.is_grace_period():
  File "/home/homeassistant/.homeassistant/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

Is this a timeout logging in to eWeLink? Why now?

Any ideas? Any other diagnostics to suggest? Obviously there is nothing wrong with the device connection to the network, or the eWeLink account, or the eWeLink api that both Google and Alexa are still using successfully. The problem seems to be that Home Assistant can no longer connect to eWeLink or to the device for some reason,

I had a similar hour-long internet interruption last week, and this problem did not occur. Why now?

Hi.
So Sonoff L1 will be supported soon?
Thanks.

Wow man!! I’m really very excited to see this.

Thanks. :sparkling_heart:

Same problem here, I’ll try to solve it.