Sonoff /eWeLink component for original firmware

That’s what I understood.
To avoid trouble, I comment the sonoff section of my config file.
Restart HASSIO.
Update my Sonoff switches
Uncomment the sonoff section of my config file.
Restart HASSIO.

Seems to go fine.
The danger to avoid is HASSIO could/will login to ewelink (which it is trying to do all the time) right when the Ewelink app is trying to complete the update process, therefore disrupting the connection to the device is even breaking the firmware update process.

@peterbuga thanks for your clarification. Your warning advice is absolutely clear and is enough! My question because I’m trying to figure out how (technically speaking) if I updat the devices fw via eWelink app and the component on HA is in dialogue with the eWelink server this corrupt the fw update, maybe for the same reason because you can’t connect two smartphone at the same time, is an eWelink limit.

Thanks @Michaelrch for this clear guide, super helpful!

A million thanks @peterbuga

That’s a very valuable component to use the main switch functionality of sonoffs.

Glad to say it worked like a charm, already tested it on a sonoff basic.

It also imported a sonoff inching i got in my account, but it’s remotely placed so i cant test if it’s working, but will when im over there and report back.

Thanks again!

That’s a good point @krash
@peterbuga, is it possible to get control of other features of the switch like turning on and off inching settings, or the device LED?
Is not super important. It would just be handy for some applications. Eg I have my DUALs running some window blinds. A short pulse would be best for opening or closing the slats (using inching) while to raise or lower blinds takes 30 seconds. So it would be handy to be able to do both modes programmatically.

there are already opened issues on the github project to add various new devices/sensors to this component, i’m really excited to add them all! due to this holidays period and because + kinda traveled i halted the development for now. one really big problem while developing this specific component is that i cannot test what i’m writing because i don’t have the devices itself :sweat_smile: therefore it’s a bit blind coding from me + testing help from the person who requests a specific device/feature.

please open an issue with sonoff-debug.py output and i’ll try to add the inching options too for a real inching device. In the case of Sonoff Dual i think you can just send ON/OFF commands from HA, if this doesn’t work i might add be able to add a service call to (hopefully) simulate the inching [with a variable time configuration] on normal non-inching devices, how does this sound ?

Thanks @peterbuga
I’m extra impressed that you go his far without even having a Sonoff! Extra kudos. DM and I’m happy to PayPal you the cost of a new DUAL or Basic!

Re the inching, it’s actually a mode that you put the device in. It came in a recent firmware update. I don’t have a dedicated inching device like @krash

In the device settings, say for a Basic, you specify the mode (inching on/off) then you specify the inching time in milliseconds. Then when you command the device on, it goes on and then off automatically after the interval, I think as one command that the Sonoff gets.

I have tried sending an On quickly followed by an Off but the lag makes it an unreliable process. I think the inching mode takes out the lag because the Sonoff does the on/off interval locally.

So would it be useful to do the required fiddling with the settings and sending the command to the device from the app? Would your debug capture see everything relevant even if it was going from the Ewelink app?

Happy to provide debug information for you, just tell me how to do it. I’ll just have to be on site to check the actual operation of the device.

No need for extra funds but I highly appreciate it, means a lot :blush:! I actually have 2 Sonoff Basic (this is from where the project started) and as the name implies they’re basic and they don’t show too much information compared to other sonoff devices. So far I worked my way using the sonoff-debug.py dumps from helping persons + decompiled eWeLink app to get the idea of how things work.

i really had no idea there’s support for this in latest firmwares, when i’ll get around my sonoffs i’ll try it and let see what i can make of it, it’s a good idea :+1:

The component works perfectly also with:
Sonoff RF (RF 1ch switch fw 2.6.1)
Sonoff CH4 Pro (fw 2.7.1)
Thanks again

1 Like

For those interested I’ve pushed an update that exposes sensor entities for devices that return power/current/voltage/temperature/humidity values, this way the automations flow can be easier scripted (the same values are available also under devices’ switch entity attributes).

As always any input/bug report is well received :open_hands:

Enjoy ;)!

4 Likes

Hello guys. There is any need to do something when new devices is added in ewelink account?

restart HA to reinitialize sonoff component and pull the list containing new devices :wink:

Hi everybody and thanks to peterbuga for the much needed component :slight_smile:
i’ve been able to configure a Sonoff Basic, but have the same bug reported for MacOS.

In detail, if it helps…

  • configuration worked
  • i can see the switch
  • no errors by HA at startup
  • the error only occurs when i try to turn the switch on or off

at startup:
2019-01-09 17:58:28 INFO (MainThread) [homeassistant.loader] Loaded sonoff from custom_components.sonoff

2019-01-09 17:58:28 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-09 17:58:28 INFO (MainThread) [homeassistant.setup] Setting up sonoff

2019-01-09 17:58:28 INFO (MainThread) [custom_components.sonoff] Found websocket address: eu-pconnect3.coolkit.cc

2019-01-09 17:58:28 INFO (MainThread) [homeassistant.setup] Setup of domain sonoff took 0.5 seconds.

but when i try to operate the switch i get the same error already described:
2019-01-09 18:01:10 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 277, in _handle_service_platform_call
await getattr(entity, func)(**data)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/var/root/.homeassistant/custom_components/switch/sonoff.py”, line 58, in turn_off
self._state = self._hass.data[SONOFF_DOMAIN].switch(False, self._deviceid, self._outlet)
File “/var/root/.homeassistant/custom_components/sonoff.py”, line 289, in switch
self._ws = self._get_ws()
File “/var/root/.homeassistant/custom_components/sonoff.py”, line 254, in _get_ws
self._ws = create_connection((‘wss://{}:8080/api/ws’.format(self._wshost)), timeout=10)
File “/var/root/.homeassistant/deps/lib/python/site-packages/websocket/_core.py”, line 511, in create_connection
websock.connect(url, **options)
File “/var/root/.homeassistant/deps/lib/python/site-packages/websocket/_core.py”, line 220, in connect
options.pop(‘socket’, None))
File “/var/root/.homeassistant/deps/lib/python/site-packages/websocket/_http.py”, line 126, in connect
sock = _ssl_socket(sock, options.sslopt, hostname)
File “/var/root/.homeassistant/deps/lib/python/site-packages/websocket/_http.py”, line 253, in _ssl_socket
sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
File “/var/root/.homeassistant/deps/lib/python/site-packages/websocket/_http.py”, line 232, in _wrap_sni_socket
server_hostname=hostname,
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”, line 412, in wrap_socket
session=session
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”, line 853, in _create
self.do_handshake()
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”, line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1051)

Hi @gatphone I know about this problem :sweat_smile: I even opened an issue myself a while ago about this but it’s sort of low priority because not a lot of people choose to do a macOS install and not to mention takes quite a lot for me to replicate the error :grin: (i do have a mac luckily :crossed_fingers:) i took the time to extend the list of available devices…

all i can say is: help is on the way (i just don’t know when exactly)
i recommend whipping fast a virtual machine and install HA there for the time being.

For MacOS users, this solves (python side) the wss problem:

just installing certifi and running the install certificates command solved the issue.
I now have a full functional Sonoff with HA on Mac OS.

Hope this helps

2 Likes

Great find! I’m adding this as a fix for the problem, you just saved me for some work :raised_hands:!

2 Likes

Yes, lucky find :smiley:
happy to have saved you some work :slight_smile:

Everything seems to work properly, but I am getting a constant flow of the same error about every 10 seconds. Help?

…only using one Sonoff basic, everything else is flashed, but would love to fix error and use more stock devices. Thanks for awesome add @peterbuga

@Dino-Tech from previous similar installation reports you need to:

  • check for the existence and proper instalation of websocket-client and/or requests python packages (please google how to do this, there’s ton of already answered questions)
  • check if sonoff-debug.py script returns output without any erros
  • if you have a Sonoff B1 device, use this branch for now https://github.com/peterbuga/HASS-sonoff-ewelink/tree/sonoff-bulb
1 Like