Sonoff /eWeLink component for original firmware

Hi,
I have some trouble trying to install the component. This is the error I get:

Blockquote
INFO:homeassistant.util.package:Attempting install of colorlog==4.0.2
Testing configuration at /config
ERROR:homeassistant.scripts.check_config:BURB
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py”, line 207, in check
res[‘components’] = check_ha_config_file(hass)
File “/usr/local/lib/python3.6/site-packages/homeassistant/scripts/check_config.py”, line 335, in check_ha_config_file
component = loader.get_component(hass, domain)
File “/usr/local/lib/python3.6/site-packages/homeassistant/loader.py”, line 92, in get_component
module = importlib.import_module(path)
File “/usr/local/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 674, in exec_module
File “”, line 781, in get_code
File “”, line 741, in source_to_code
File “”, line 219, in _call_with_frames_removed
File “/config/custom_components/sonoff.py”, line 7

^
SyntaxError: invalid syntax
Fatal error while loading config: invalid syntax (sonoff.py, line 7)
Failed config
General Errors:
- invalid syntax (sonoff.py, line 7)
Successful config (partial)
< Blockquote

What am I doing wrong?

Yes proof of concept, but couldn’t get it to work with my 2 channel device.

first of all you have pending install packages from adding/enabling other components as stated here
INFO:homeassistant.util.package:Attempting install of colorlog==4.0.2

moving forward there’s a slight possibility that you didn’t copy-paste properly the sonoff files (might be the reason you get the synstax error problem), remove everything related to sonoff component and start from scratch, watch closely the install instructions!

WOW! just wow! this is another cool idea.

Unfortunately seems like everyone ignores the elephantS in the room regarding this implementation: i might be wrong but the devices might first need properly to connect to internet before dropping into LAN Mode and the fact the list of supported devices (better said only 1-switch devices) are supported :frowning: this is a real let down from ewelink coders :-1:

I’m definitely keeping an eye on this project and maybe i’ll add an offline fallback but as mentioned above creates an overall confusion of what/how the devices will work with this component.

Thank you for your reply. I noticed the error about colorlog, but I thought it was not an error and it had finally managed to install. I am not very familiar with hassio on the Raspberry PI and I don’t quite know how to install colorlog. I tried to look it up but I couldn’t find anything clear. I am still learning, sorry.
As for the sonoff.py files, what I did was download each file (respecting the folder order) and then upload them to my HA installation in the configuration folder. I will try the copy and paste option. Thanks!

Yes! It works! The problem seems to be the way I was installing the sonoff.py files. I assumed I could download each PY file to my computer and upload it to the HA server, but it doesn’t work like this!
So, I’ve got one Sonoff S20, a Sonoff basic and a wifi socket from Coolkit which also works through the ewelink server. Everything working right now!

Guys, i have two questions on the Sonoff basic and Sonoff Bridge

  1. I keep noticing that my eWelink keeps logging out and have to log back into the eWelink app ? What do I need to do to solve this ?

  2. Is there a solution to Sonoff bridge in Home Assistant ? Is there anyway to get it integrated.

Thanks for all your time and help

@Vaughanza

  1. take 2minutes and carefully read the project’s README (aka the main page)
  2. it’s a pending issue work-in-progress. i’m quite confident that i might be able to integrate it buuut there’s always the possibility that might not work as intended
1 Like

Seems like great progress has been made! Kudos to our amazing man @peterbuga

I haven’t updated my files since before holidays (Dec 2018). Added Sonoff POW R2 to my collection.

Planning to upgrade files, will be using Websockets branch, as it works insanely fast!

Currently my devices are named switch.deviceid_outlet (have entity_name: False in my config), I would prefer to keep it this way. Do the new files change this? What should I do to get this working?

Thanks a lot for the amazing work!

Love the component.

1 Like

Thanks you!!
It works well on my sonoff basic

The current websocket branch works with this naming model (but it has been reported to be broken … oops) all others have the legacy switch.sonoff_deviceid_outlet even so, i think a quick global find and replace could bring everything in place.

i’ve been a bit busy lately so the updates are showing up a bit slower (not to mention that my SD card that was holding the HA installation decided to bravely give up and kinda killed my mood to push new stuff for now :frowning: )

So that means new files have the switch.deviceid_outlet naming model right?
You’re not using the switch.devicename or something in the latest version right?

Thanks.

Hi, I’m having problem with HASSIO running on docker Raspberry Pi.

I got this error:
2019-01-22 13:58:15 WARNING (MainThread) [homeassistant.loader] You are using a custom component 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-01-22 13:59:18 ERROR (SyncWorker_3) [homeassistant.util.package] Unable to install package uuid: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x75a3fe50>: Failed to establish a new connection: [Errno -3] Try again’,)’: /packages/ce/63/f42f5aa951ebf2c8dac81f77a8edcc1c218640a2a35a03b9ff2d4aa64c3d/uuid-1.30.tar.gz
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x75a0f550>: Failed to establish a new connection: [Errno -3] Try again’,)’: /packages/ce/63/f42f5aa951ebf2c8dac81f77a8edcc1c218640a2a35a03b9ff2d4aa64c3d/uuid-1.30.tar.gz
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x75a0f730>: Failed to establish a new connection: [Errno -3] Try again’,)’: /packages/ce/63/f42f5aa951ebf2c8dac81f77a8edcc1c218640a2a35a03b9ff2d4aa64c3d/uuid-1.30.tar.gz
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x75a0fe10>: Failed to establish a new connection: [Errno -3] Try again’,)’: /packages/ce/63/f42f5aa951ebf2c8dac81f77a8edcc1c218640a2a35a03b9ff2d4aa64c3d/uuid-1.30.tar.gz
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x75a0ff90>: Failed to establish a new connection: [Errno -3] Try again’,)’: /packages/ce/63/f42f5aa951ebf2c8dac81f77a8edcc1c218640a2a35a03b9ff2d4aa64c3d/uuid-1.30.tar.gz
Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Max retries exceeded with url: /packages/ce/63/f42f5aa951ebf2c8dac81f77a8edcc1c218640a2a35a03b9ff2d4aa64c3d/uuid-1.30.tar.gz (Caused by NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x75a0f750>: Failed to establish a new connection: [Errno -3] Try again’,))
2019-01-22 13:59:18 ERROR (MainThread) [homeassistant.requirements] Not initializing sonoff because could not install requirement uuid
2019-01-22 13:59:18 ERROR (MainThread) [homeassistant.setup] Setup failed for sonoff: Could not install all requirements.

Can anyone help?

@e-budianto for some reason, this is not quite a sonoff-component problem but more like your HA install / network problem. while enabling this component it tries to install automatically the needed dependencies but you are encountering a problem on this level.
try this (or google how to install pip packages under HASSIO install):

pip3 install uuid
pip3 install websocket-client

@forums2012
i just updated (hopefully fixed) the websocket branch and i can confirm the switches are under switch.deviceid_outlet format + all the other updates added recently (switch-outlets names when available, sensor data)
backup current files and give a try with the current one and let me know how (and if) it works

2 Likes

Thanks for all the Hard work and time you put into this project @peterbuga we apprecoaite it.

thanks for prompt reply @peterbuga , tried to install in docker via
sudo docker exec -it homeassistant /bin/bash
then
pip3 install uuid --proxy https://myserver.com:8080
now it installs successfully, but when restart hassio, or reboot pi, it still cannot load custom component with exactly same error.

2019-01-22 16:52:14 WARNING (MainThread) [homeassistant.loader] You are using a custom component 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-01-22 16:53:12 ERROR (SyncWorker_17) [homeassistant.util.package] Unable to install package uuid: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7590a7b0>: Failed to establish a new connection: [Errno -3] Try again’,)‘: /simple/uuid/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7590a9f0>: Failed to establish a new connection: [Errno -3] Try again’,)‘: /simple/uuid/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7590a470>: Failed to establish a new connection: [Errno -3] Try again’,)‘: /simple/uuid/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7590a8d0>: Failed to establish a new connection: [Errno -3] Try again’,)‘: /simple/uuid/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7590a450>: Failed to establish a new connection: [Errno -3] Try again’,)': /simple/uuid/
Could not find a version that satisfies the requirement uuid (from versions: )
No matching distribution found for uuid
2019-01-22 16:53:12 ERROR (MainThread) [homeassistant.requirements] Not initializing sonoff because could not install requirement uuid
2019-01-22 16:53:12 ERROR (MainThread) [homeassistant.setup] Setup failed for sonoff: Could not install all requirements

tried again run this command:

bash-4.4# pip3 install uuid --no-cache-dir --proxy https://myproxy:8080
Requirement already satisfied: uuid in /usr/local/lib/python3.6/site-packages (1.30)
bash-4.4#

still error during loading custom components.

@e-budianto unfortunately I stand by my original post that it’s a problem on your HA install! judging from the output above you use a proxy to access internet, the above commands were executed properly but clearly where pip3 installs the package is not accessible by HA. i think a better way would be to find a way properly give internet access to docker and let HA do its thing and install the package where it needs to (or try to find where the HA install resides and manually copy uuid package there, i wouldn’t recommend this but mostly as a last resort)

i never used HASSIO so i’m a bit blind in this matter, maybe someone else with hassio experience can shed some light in this matter!

Many thanks @peterbuga
I have installed this (Websocket branch) and am testing now. I am getting no errors on startup which is great!
I am able to control switches just as before :+1:

On the sensors, I am getting mixed results.
I have 3 POW switches installed. When I started up, they were all set to state=0.
I turned one on. It has a thermostat controlled heater connected to it. The state went to unknown. Then about 60 seconds later, it started showing the correct load in W, which is great. I turned it off. It went to unknown for a couple of minutes, then went back to 0.

I tried on a second switch. That one went to unknown and just stayed like that for at least 5 minutes, I turned off the switch and after a couple more minutes it returned to 0. FWIW this switch is not on the same LAN as my HA instance. I don’t know if that matters. I can see the readings on the Ewelink app whichever network I am on.

Thanks again for your work on this. If you would like me to do any other testing, or if you have any advice, please just let me know. I’ll stick with this rev as it’s at least as functional as the previous one.

@Michaelrch thanks from prompt reply too, appreciate it!

I have to admit the sensors part (like most of work on this component lately :smile:) has been purely theoretical from the dumps (thanks everyone for providing this data).

That being said the sensors data is refreshed every 60seconds (default) or whatever refresh-value you had it setup, I just assumed that despite the switches, getting second-like updates on sensors might not be such a high priority. I’m actually unaware if any sensor data is sent over the websocket connection (if this would be the case that would be extremely useful!) or it’s just available over the device details.
I sort of got stuck while trying to integrate some new devices and I’m going to integrate a deeper debug-logging option inside the component that will capture device data + websocket data and this way I will have more information of what exactly happens over a period of time.

If you (or anyone else) are willing to get the hands dirty and generate some log files I will, again, highly appreciate it!

1 Like