peterbuga / hass-sonoff-ewelink Goto Github PK
View Code? Open in Web Editor NEWHome Assistant component to control Sonoff/eWeLink devices with original firmware
License: MIT License
Home Assistant component to control Sonoff/eWeLink devices with original firmware
License: MIT License
Home-Assistant (0.88) is changing custom components structure, would be nice to adjust and keep compatibility :)
PS. Great job with this component!
Getting this in the logs:
2019-02-22 09:37:15 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.sonoff.switch. Make sure all dependencies are installed Traceback (most recent call last): File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 147, in _load_file module = importlib.import_module(path) File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked ImportError: No module named 'custom_components.sonoff.switch'; 'custom_components.sonoff' is not a package
Nothing has changed, maybe HA policies
Confirmed that this works with https://www.amazon.com/gp/product/B073VK9X49/ref=oh_aui_detailpage_o01_s01?ie=UTF8&psc=1
I'm using it now.
Hey peterbuga, this is marksev1 from HASS community... I added the lines you told me and now I get the following error:
2019-02-02 10:55:15 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/home/msev/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 287, in _handle_service_platform_call
await getattr(entity, func)(**data)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/msev/.homeassistant/custom_components/switch/sonoff.py", line 53, in turn_on
self._state = self._hass.data[SONOFF_DOMAIN].switch(True, self._deviceid, self._outlet)
File "/home/msev/.homeassistant/custom_components/sonoff.py", line 290, in switch
self._ws = self._get_ws()
File "/home/msev/.homeassistant/custom_components/sonoff.py", line 255, in _get_ws
self._ws = create_connection(('wss://{}:8080/api/ws'.format(self._wshost)), timeout=10)
File "/home/msev/homeassistant/lib/python3.7/site-packages/websocket/_core.py", line 511, in create_connection
websock.connect(url, **options)
File "/home/msev/homeassistant/lib/python3.7/site-packages/websocket/_core.py", line 220, in connect
options.pop('socket', None))
File "/home/msev/homeassistant/lib/python3.7/site-packages/websocket/_http.py", line 126, in connect
sock = _ssl_socket(sock, options.sslopt, hostname)
File "/home/msev/homeassistant/lib/python3.7/site-packages/websocket/_http.py", line 253, in _ssl_socket
sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
File "/home/msev/homeassistant/lib/python3.7/site-packages/websocket/_http.py", line 232, in _wrap_sni_socket
server_hostname=hostname,
File "/usr/local/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/usr/local/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/usr/local/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:1056)
Hello,
The module Geekcreit 2 Channel AC 85V-250V can be linked to ewlink. It appears as a switch at Home assistant (instead of two) and it doesn´t work. Here they are the parameters that appear in devices.json:
Regards,
Hello there,
Thanks for this integration, I've been waiting for this for a long time;
Can you please advice on how to do this integration if you have HA running in a docker container ?
Thanks
Can you please add support for cover switchs? Ewelink recognizes them as Kingart king-q4. With open, close, stop and percentage if possible, like Tuya devices do. Thanks!
hello, thank for your work, if this can help you. I have test with home assistant and this product
Tishric-Basic-Smart-WIFI-Switch-10A-16A
this is the json file :
[
{
"__v": 0,
"_id": "[hidden]",
"apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"brandName": "BLue50",
"createdAt": "xxxx-xx-xxxxx:xx:xx.xxx",
"deviceUrl": "",
"deviceid": "[hidden]",
"devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"extra": {
"_id": "[hidden]",
"extra": {
"apmac": "xx:xx:xx:xx:xx:xx",
"brandId": "593819fd98aebf3876f824f5",
"description": "20181012002",
"mac": "xx:xx:xx:xx:xx:xx",
"manufacturer": "\u6c5f\u95e8\u5e02\u4e94\u5341\u5ea6\u84dd\u667a\u80fd\u79d1\u6280\u6709\u9650\u516c\u53f8",
"model": "PSF-B01-GL",
"modelInfo": "5a93682432e9a1626586e218",
"ui": "\u5355\u901a\u9053\u63d2\u5ea7",
"uiid": 1
}
},
"group": "",
"groups": [],
"ip": "[hidden]",
"location": "",
"name": "[hidden]",,
"offlineTime": "xxxx-xx-xxxxx:xx:xx.xxx",
"online": true,
"onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx",
"params": {
"bindInfos": {
"alexa": []
},
"fwVersion": "2.6.1",
"init": 1,
"partnerApikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"pulse": "off",
"pulseWidth": 500,
"rssi": -57,
"sledOnline": "on",
"staMac": "xx:xx:xx:xx:xx:xx",
"startup": "stay",
"switch": "off"
},
"productModel": "SX1",
"settings": {
"alarmNotify": 1,
"opsHistory": 1,
"opsNotify": 0
},
"sharedTo": [],
"showBrand": true,
"type": "10",
"uiid": 1
}
]
Thank you again
I don't have to flash it with tasmota firmware,
Hi,
Has anybody tested sonoff configurations with the new release of HA, 0.87.1? Because HA don't reconize ittems after upgrade, in my case.
Tnxs,
I have installed HA 0.88.1 on tvbox using Termux.
When I launch HASS I got these errors
2019-03-02 21:56:09 INFO (MainThread) [homeassistant.setup] Setting up updater 2019-03-02 21:56:09 INFO (MainThread) [homeassistant.setup] Setting up sonoff 2019-03-02 21:56:10 ERROR (MainThread) [homeassistant.setup] Error during setup of component sonoff Traceback (most recent call last): File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/homeassistant/setup.py", line 151, in _async_setup_component hass, processed_config) File "/data/data/com.termux/files/home/.homeassistant/custom_components/sonoff/__init__.py", line 52, in async_setup hass.data[DOMAIN] = Sonoff(config) File "/data/data/com.termux/files/home/.homeassistant/custom_components/sonoff/__init__.py", line 96, in __init__ self.do_login() File "/data/data/com.termux/files/home/.homeassistant/custom_components/sonoff/__init__.py", line 162, in do_login self._bearer_token = resp['at'] KeyError: 'at' 2019-03-02 21:56:10 INFO (MainThread) [homeassistant.setup] Setting up sun 2019-03-02 21:56:10 INFO (MainThread) [homeassistant.setup] Setup of domain sun took 0.1 seconds.
Anyone know what is wrong?
Initially had a single Sonoff Basic, things were working well.
Added a Sonoff 4Ch pro, now don't see even the sonoff basic.
Error in Log:
Error while setting up platform sonoff
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/config/custom_components/switch/sonoff.py", line 23, in async_setup_platform
entity = SonoffSwitch(hass, device)
File "/config/custom_components/switch/sonoff.py", line 36, in __init__
SonoffDevice.__init__(self, hass, device)
File "/config/custom_components/sonoff.py", line 333, in __init__
self._state = device['params']['switch'] == 'on'
KeyError: 'switch'
Is there a simple way to do this?
Hello. Before the last update, my Sonoff T1 EU touch 2-channel detected 4 switches. I ignored the last 2 and used the first 2. After the last update I could no longer use it because it tries to insert the 2 channels with the same ID, generating an error and only showing me 1 switch.
Hello, this plugin is great. However, I am not a programmer.What do I need to do to get him to work.
I have done this now.
configuration.yaml:
sonoff:
username: +86xxxxxxxxxx(ewelink username)
password: 00000000(ewelink password)
scan_interval: 60
grace_period: 600
api_region: cn
Download your PY Added in the directory 《custom_components》
custom_components:
---sonoff.py
---switch
Restart HA
Log Details (ERROR)
Wed Dec 12 2018 11:16:32 GMT+0800 (**标准时间)
Couldn't authenticate using the provided credentials!
What else do I need to do to get him to display the switch and use him normally?
Test run the command in the Raspberry Pi home/pi/home assistant/custom_components/sonoff-debug directory
pi@raspberrypi:/.homeassistant/custom_components $ ls/.homeassistant/custom_components $ cd sonoff-debug
pycache sonoff-debug sonoff.py switch
pi@raspberrypi:
pi@raspberrypi:/.homeassistant/custom_components/sonoff-debug $ python sonoff-debug.py '+86xxxxxxxxx' 'xxxxxxxxx' > devices.json/.homeassistant/custom_components/sonoff-debug $
Traceback (most recent call last):
File "sonoff-debug.py", line 90, in
devices_json = get_devices()
File "sonoff-debug.py", line 69, in get_devices
headers.update({'Authorization' : 'Bearer ' + user_details['at']})
KeyError: 'at'
pi@raspberrypi:
Is this HA addon Cloud Polling or local Polling?
Since mid 2018, the firmware Itead have shipped with Sonoff devices has provided a feature called "LAN Mode" which allows the device to be controlled directly on the local network using a WebSocket connection on port 8081.
The feature is designed to only be used when there is no connection to the Itead cloud servers (e.g. if your internet connection is down, or their servers are down). As such, it is only enabled when the device is connected to your WiFi network, but unable to reach the Itead servers.
First, thank you for the time spent with this development. It is very nice not to have to flash Sonoff devices that are already embedded in projects that I started using before HA. I have three TH16's so I was eager to upgrade your files to take advantage of the temperature sensor readings from the Sonoffs. After upgrading your python files the TH16's only take a reading for temp and humidity whenever HA is restarted. They do not poll the temps every 60 seconds as set in my config file
###################################
###################################
sonoff:
username: !secret life360_username
password: !secret big_little_pwd
scan_interval: 60
grace_period: 180
api_region: 'us'
Also, changing switches on Sonoff basics and TH16's in HA no longer functions. They worked fine on previous version of your scripts before sensors were added. I have tried reinstalling the python code several times, to make sure there is no error on my part and also deleted the pycache files from all folders, no success. The polling problem is with both temp and humidity readings so probably not a Celsius to Fahrenheit issue (my graphs in HA display the only reading they get upon restart of HA in F correctly). I have no idea what the problem could be, waited to see if anyone else reported it, then decided to post my experience here. I am also logged out of the eWelink app on all my devices.
My sonoff basics are on 2.61 firmware and TH16's on 2.60 ( no update available for them yet). HA is 0.85.1
Hope this info helps.
Error while setting up platform sonoff
Traceback (most recent call last):
File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/config/custom_components/sensor/sonoff.py", line 33, in async_setup_platform
entity = SonoffSensor(hass, device, sensor)
File "/config/custom_components/sensor/sonoff.py", line 43, in init
SonoffDevice.init(self, hass, device)
File "/config/custom_components/sonoff.py", line 509, in init
if outlet is None:
NameError: name 'outlet' is not defined
Hello,
I get this error message every minute, but otherwise the plug-in works fine (I use it with sonoff touch and sonoff basic)
What can I do to help debug?
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 232, in async_update_ha_state
state = self.state
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 426, in state
return STATE_ON if self.is_on else STATE_OFF
File "/home/homeassistant/.homeassistant/custom_components/switch/sonoff.py", line 48, in is_on
self._state = self.get_state()
File "/home/homeassistant/.homeassistant/custom_components/sonoff.py", line 414, in get_state
return device['params']['switch'] == 'on' if device else False
KeyError: 'switch'
I have succesfully added 1 channel sonoff for garage door:
https://www.itead.cc/inching-self-locking-wifi-wireless-switch.html. Thanks @peterbuga! It worked fine on 2.6 firmware, and works now fine on 2.6.1 firmware.
But how to set the switch, to be acting like inching switch? Now when I turn on the switch it open door and stays on. To close door I must power off switch and power on again to close door and then power off at end. Any idea how to change the switch to go off by itself or act like inching?
Hi,
I known the Sonoff T1 US 3C Switch is not listed in the Compatibility list, but when trying to install your component into my Home Assistant, it has been able to discover my device.
However, the Sonoff T1 US 3C model has 3 switches but my HA can discover only 1 random switch among 3 :(
Is it possible to discover the rest 2 switches? It will be really great if you can add supporting for Sonoff T1 US 3C model in futures.
Anw, awesome work!
Thank you in advance!
HA appears to keep dropping connection to sonoff and cannot control anything.
Tried a number of restarts and also the debug script (which completes ok)
Any ideas?
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.py", line 277, in _handle_service_platform_call
await getattr(entity, func)(**data)
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/sonoff.py", line 437, in turn_on
self._state = self._hass.data[DOMAIN].switch(True, self._deviceid, self._outlet)
File "/config/custom_components/sonoff.py", line 341, in switch
self._ws.send(json.dumps(payload))
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 239, in send
return self.send_frame(frame)
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 264, in send_frame
l = self._send(data)
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 425, in _send
return send(self.sock, data)
File "/usr/local/lib/python3.6/site-packages/websocket/_socket.py", line 109, in send
raise WebSocketConnectionClosedException("socket is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.
not sure where to put this:
[
{
"__v": 0,
"_id": "[hidden]"
"apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"brandName": "New Smart ",
"createdAt": "xxxx-xx-xxxxx:xx:xx.xxx",
"deviceUrl": "",
"deviceid": "[hidden]"
"devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"extra": {
"_id": "[hidden]"
"extra": {
"apmac": "xx:xx:xx:xx:xx:xx",
"brandId": "5735f5f906d9751d4f109629",
"description": "20181023003",
"mac": "xx:xx:xx:xx:xx:xx",
"manufacturer": "\u90d1\u5dde\u5e02\u4e2d\u539f\u533a\u6c47\u8bda\u7535\u5b50\u6750\u6599\u7ecf\u8425\u90e8",
"model": "PSF-B01-GL",
"modelInfo": "589833ac2f979b623e2f503f",
"ui": "\u5355\u901a\u9053\u5f00\u5173",
"uiid": 6
}
},
"group": "",
"groups": [],
"ip": "[hidden]"
"location": "",
"name": "[hidden]",
"online": true,
"onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx",
"params": {
"fwVersion": "1.8.1",
"rssi": -57,
"staMac": "xx:xx:xx:xx:xx:xx",
"startup": "off",
"switch": "off"
},
"productModel": "G1",
"settings": {
"alarmNotify": 1,
"opsHistory": 1,
"opsNotify": 0
},
"sharedTo": [],
"showBrand": true,
"type": "10",
"uiid": 6
}
]
I'm using home assistant on a virtual environment. I do not see any sonoff and it appears:
Error while setting up platform sonoff
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for
return fut.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "/home/homeassistant/.homeassistant/custom_components/switch/sonoff.py", line 22, in async_setup_platform
if 'switches' in device['params']:
KeyError: 'params'
What can I do? Thanks
HA installation on macOS tries to validate the wss connection and breaks the flow.
Thanks a lot for your job. It's a fantastic component.
I've one issue: everything seems to work and the component found quickly mu devices, but It has added 4 entities for each sonoff 2ch device.
Have you seen it before?
Thanks
Hello.
Do you plan to support light switches with dimmer?
For example: https://www.ebay.com/itm/eWeLink-WiFi-Smart-Touch-Dimmer-Switch-UK-US-Plug-Wall-Panel-APP-Light-Control/254025532825
Just opened a PR adding support for temperature sensors for devices that provide this innformation such as TH16.
Here's the error:
Traceback (most recent call last):
File "sonoff-debug.py", line 57, in <module>
headers.update({'Authorization' : 'Bearer ' + user_details['at']})
KeyError: 'at'
Would appreciate your help. Thanks.
How install this component inside home assistant?
I tried to add repository url but it only adds an unknown box...
I see so many people who want to add their device to their home assistant, and still people at the home assistant forums tell them they must flash their devices, for those of us who don't mind using the ewelink app, this component makes life easier, I'm sure some people skip sonoff devices just because they can't solder, so perhaps see if it could be added as an official component soon?
Hello, I have a problem with sonoff component.
Component stopped working for me. Tried few restarts, downloaded latest version but result is same. Sonoff cannot establish a new connection when starting.
sonoff:
username: [email protected]
password: xxxxxxx
scan_interval: 60
grace_period: 600
api_region: 'eu'
entity_name: true
Wed Feb 20 2019 19:41:58 GMT+0100 (Středoevropský standardní čas)
Error during setup of component sonoff
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 57, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/local/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 301, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f8f4e6ee588>: Failed to establish a new connection: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='eu-disp.coolkit.cc', port=8080): Max retries exceeded with url: /dispatch/app (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f8f4e6ee588>: Failed to establish a new connection: [Errno -3] Try again',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/setup.py", line 145, in _async_setup_component
hass, processed_config)
File "/config/custom_components/sonoff.py", line 52, in async_setup
hass.data[DOMAIN] = Sonoff(config)
File "/config/custom_components/sonoff.py", line 96, in __init__
self.do_login()
File "/config/custom_components/sonoff.py", line 168, in do_login
self.set_wshost()
File "/config/custom_components/sonoff.py", line 173, in set_wshost
r = requests.post('https://%s-disp.coolkit.cc:8080/dispatch/app' % self._api_region, headers=self._headers)
File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='eu-disp.coolkit.cc', port=8080): Max retries exceeded with url: /dispatch/app (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f8f4e6ee588>: Failed to establish a new connection: [Errno -3] Try again',))
Ping from Hassio (inside docker) is ok.
ping eu-disp.coolkit.cc
PING eu-disp.coolkit.cc (52.28.157.61): 56 data bytes
64 bytes from 52.28.157.61: seq=0 ttl=46 time=23.010 ms
64 bytes from 52.28.157.61: seq=1 ttl=46 time=24.189 ms
Enviroment:
arch | x86_64
-- | --
dev | false
docker | true
hassio | true
os_name | Linux
python_version | 3.6.6
timezone | Europe/Prague
version | 0.87.1
virtualenv | false
Hi there!
Thanks so much for working on this Sonoff addition to home-assistant!
I just implemented your solution on my hass.io running on a RaspberryPi, with 1 Sonoff POW R2, and I'm getting the following error message practically every minute since I've restarted HA.
Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 232, in async_update_ha_state state = self.state File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 426, in state return STATE_ON if self.is_on else STATE_OFF File "/config/custom_components/switch/sonoff.py", line 48, in is_on self._state = self.get_state() File "/config/custom_components/sonoff.py", line 414, in get_state return device['params']['switch'] == 'on' if device else False KeyError: 'switch'
Would you mind letting me know what could cause this, and potentially how to solve? If this is something that has been answered before apologies, but I couldn't find any answers.
Thanks in advance!
Cheers,
Daniel
Keep getting some of these here and there:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.py", line 277, in _handle_service_platform_call
await getattr(entity, func)(**data)
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/sonoff.py", line 420, in turn_on
self._state = self._hass.data[DOMAIN].switch(True, self._deviceid, self._outlet)
File "/config/custom_components/sonoff.py", line 322, in switch
self._ws.send(json.dumps(payload))
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 239, in send
return self.send_frame(frame)
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 264, in send_frame
l = self._send(data)
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 425, in _send
return send(self.sock, data)
File "/usr/local/lib/python3.6/site-packages/websocket/_socket.py", line 112, in send
return sock.send(data)
File "/usr/local/lib/python3.6/ssl.py", line 941, in send
return self._sslobj.write(data)
File "/usr/local/lib/python3.6/ssl.py", line 642, in write
return self._sslobj.write(data)
ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:2138)
This dumps contain one single Wireless Door Window Detector
Open door detector
[
{
"__v":0,
"_id":"[hidden]",
"apikey":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"brandName":"Sonoff",
"createdAt":"xxxx-xx-xxxxx:xx:xx.xxx",
"deviceStatus":"",
"deviceUrl":"",
"deviceid":"[hidden]",
"devicekey":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"extra":{
"_id":"[hidden]",
"extra":{
"apmac":"xx:xx:xx:xx:xx:xx",
"brandId":"58e5f344baeb368720e25469",
"description":"WO1852",
"mac":"xx:xx:xx:xx:xx:xx",
"manufacturer":"\u6df1\u5733\u677e\u8bfa\u6280\u672f\u6709\u9650\u516c\u53f8",
"model":"PSC-B67-GL",
"modelInfo":"5a2e1ae50cf772f92c342ef6",
"ui":"\u529f\u7387\u68c0\u6d4b\u63d2\u5ea7\u8fc7\u8f7d\u544a\u8b66",
"uiid":32
}
},
"group":"",
"groups":[
],
"ip":"[hidden]",
"location":"",
"name":"[hidden]",
"offlineTime":"xxxx-xx-xxxxx:xx:xx.xxx",
"online":true,
"onlineTime":"xxxx-xx-xxxxx:xx:xx.xxx",
"params":{
"alarmCValue":[
-1,
-1
],
"alarmPValue":[
-1,
-1
],
"alarmType":"pcv",
"alarmVValue":[
-1,
-1
],
"controlType":8,
"current":"0.16",
"endTime":"",
"fwVersion":"2.8.0",
"hundredDaysKwh":"get",
"init":1,
"oneKwh":"get",
"partnerApikey":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"power":"21.90",
"rssi":-60,
"sledOnline":"on",
"staMac":"xx:xx:xx:xx:xx:xx",
"startTime":"xxxx-xx-xxxxx:xx:xx.xxx",
"switch":"on",
"timeZone":2,
"voltage":"235.62"
},
"productModel":"Pow_R2",
"settings":{
"alarmNotify":1,
"opsHistory":1,
"opsNotify":0
},
"sharedTo":[
],
"showBrand":true,
"type":"10",
"uiid":32
},
{
"__v":0,
"_id":"[hidden]",
"apikey":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"brandName":"Sonoff",
"createdAt":"xxxx-xx-xxxxx:xx:xx.xxx",
"deviceStatus":"",
"deviceUrl":"",
"deviceid":"[hidden]",
"devicekey":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"extra":{
"_id":"[hidden]",
"extra":{
"apmac":"xx:xx:xx:xx:xx:xx",
"brandId":"58e5f344baeb368720e25469",
"description":"WO1851",
"mac":"xx:xx:xx:xx:xx:xx",
"manufacturer":"\u6df1\u5733\u677e\u8bfa\u6280\u672f\u6709\u9650\u516c\u53f8",
"model":"PSF-BRA-GL",
"modelInfo":"5a2e1b360cf772f92c342f01",
"ui":"RFBridge",
"uiid":28
}
},
"group":"",
"groups":[
],
"ip":"[hidden]",
"location":"",
"name":"[hidden]",
"offlineTime":"xxxx-xx-xxxxx:xx:xx.xxx",
"online":true,
"onlineTime":"xxxx-xx-xxxxx:xx:xx.xxx",
"params":{
"cmd":"trigger",
"fwVersion":"2.7.0",
"init":1,
"rfChl":0,
"rfList":[
{
"rfChl":0,
"rfVal":"331801CC0582EE4D13"
}
],
"rfTrig0":"xxxx-xx-xxxxx:xx:xx.xxx",
"rssi":-37,
"sledOnline":"on",
"timers":[
]
},
"productModel":"RF_Bridge",
"settings":{
"alarmNotify":1,
"opsHistory":1,
"opsNotify":0
},
"sharedTo":[
],
"showBrand":true,
"tags":{
"disable_timers":[
],
"zyx_info":[
{
"buttonName":[
{
"0":"Button Name1"
}
],
"name":"[hidden]",
"remote_type":"6"
}
]
},
"type":"10",
"uiid":28
}
]
Closed door detector
[ { "__v": 0, "_id": "[hidden]" "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "brandName": "Sonoff", "createdAt": "xxxx-xx-xxxxx:xx:xx.xxx", "deviceStatus": "", "deviceUrl": "", "deviceid": "[hidden]" "devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "extra": { "_id": "[hidden]" "extra": { "apmac": "xx:xx:xx:xx:xx:xx", "brandId": "58e5f344baeb368720e25469", "description": "WO1852", "mac": "xx:xx:xx:xx:xx:xx", "manufacturer": "\u6df1\u5733\u677e\u8bfa\u6280\u672f\u6709\u9650\u516c\u53f8", "model": "PSC-B67-GL", "modelInfo": "5a2e1ae50cf772f92c342ef6", "ui": "\u529f\u7387\u68c0\u6d4b\u63d2\u5ea7\u8fc7\u8f7d\u544a\u8b66", "uiid": 32 } }, "group": "", "groups": [], "ip": "[hidden]" "location": "", "name": "[hidden]", "offlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", "online": true, "onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", "params": { "alarmCValue": [ -1, -1 ], "alarmPValue": [ -1, -1 ], "alarmType": "pcv", "alarmVValue": [ -1, -1 ], "controlType": 8, "current": "0.16", "endTime": "", "fwVersion": "2.8.0", "hundredDaysKwh": "get", "init": 1, "oneKwh": "get", "partnerApikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "power": "21.87", "rssi": -60, "sledOnline": "on", "staMac": "xx:xx:xx:xx:xx:xx", "startTime": "xxxx-xx-xxxxx:xx:xx.xxx", "switch": "on", "timeZone": 2, "voltage": "232.78" }, "productModel": "Pow_R2", "settings": { "alarmNotify": 1, "opsHistory": 1, "opsNotify": 0 }, "sharedTo": [], "showBrand": true, "type": "10", "uiid": 32 }, { "__v": 0, "_id": "[hidden]" "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "brandName": "Sonoff", "createdAt": "xxxx-xx-xxxxx:xx:xx.xxx", "deviceStatus": "", "deviceUrl": "", "deviceid": "[hidden]" "devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "extra": { "_id": "[hidden]" "extra": { "apmac": "xx:xx:xx:xx:xx:xx", "brandId": "58e5f344baeb368720e25469", "description": "WO1851", "mac": "xx:xx:xx:xx:xx:xx", "manufacturer": "\u6df1\u5733\u677e\u8bfa\u6280\u672f\u6709\u9650\u516c\u53f8", "model": "PSF-BRA-GL", "modelInfo": "5a2e1b360cf772f92c342f01", "ui": "RFBridge", "uiid": 28 } }, "group": "", "groups": [], "ip": "[hidden]" "location": "", "name": "[hidden]", "offlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", "online": true, "onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx", "params": { "cmd": "trigger", "fwVersion": "2.7.0", "init": 1, "rfChl": 0, "rfList": [ { "rfChl": 0, "rfVal": "331801CC0582EE4D13" } ], "rfTrig0": "xxxx-xx-xxxxx:xx:xx.xxx", "rssi": -37, "sledOnline": "on", "timers": [] }, "productModel": "RF_Bridge", "settings": { "alarmNotify": 1, "opsHistory": 1, "opsNotify": 0 }, "sharedTo": [], "showBrand": true, "tags": { "disable_timers": [], "zyx_info": [ { "buttonName": [ { "0": "Button Name1" } ], "name": "[hidden]", "remote_type": "6" } ] }, "type": "10", "uiid": 28 } ]
Thanks for developing this HA component. I've got more than 10 wifi light switches ("LX-WIFI-030), both single and multi channel versions plus 5 sonoff S26s working on the master branch components (except for the switch labels). I tried to switch to the websocket branch components as it properly displays the switch labels but I'm getting a lot of websocket errors and the switching doesn't work either. It turns on then off on the dashboard but not actual actually switching the lights See part of the HA log showing this. I'm using Raspberry Pi 3b+ running Raspbian Stretch, python 2.7.13 and 3.5.3, HAss version 0.82
2019-01-08 13:01:45 WARNING (MainThread) [homeassistant.components.mqtt] Data in your config entry is going to override your configuration.yaml: {'broker': '192.168.20.246', 'discovery': True, 'port': 1883}
2019-01-08 13:01:48 WARNING (Recorder) [homeassistant.components.recorder.migration] Database requires upgrade. Schema version: None
2019-01-08 13:01:49 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-08 13:01:54 ERROR (Thread-5) [homeassistant.components.weather.bom] Could not get BOM weather station from lat/lon
2019-01-08 13:01:54 WARNING (MainThread) [homeassistant.loader] You are using a custom component for switch.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-08 13:01:55 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:01:56 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:01:58 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:01:59 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:01 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:02 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:04 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:06 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:07 ERROR (Thread-5) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2019-01-08 13:02:07 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:09 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:10 ERROR (Thread-3) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2019-01-08 13:02:10 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:11 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
2019-01-08 13:02:13 ERROR (Thread-17) [custom_components.sonoff] websocket error: unorderable types: float() > NoneType()
../home-assistant.log
Can't work out what's causing it. Hope you can help. Thanks.
I've attached logs and the devices.json file.
edit @peterbuga: removed bold font
Would it be possible to make this into a add-on repository for easier setup?
The Sonoff LED device has been discontinued, but it consisted of a Sonoff Basic form factor box attached to a string of white LEDs. I can't find it on their website any more. Anyway, here is the output of sonoff-debug.
Google home has eWelink binding. I think it will be better to use the same bindings api. Current imlementation by using mobile api does not work consistent, a lot of times it is not responding in HA.
Names can be assigned to outlets. they apears as tags and can be used in Home Assitant interface.
I changed the code, you can find it there: https://github.com/lfasci/HASS-sonoff-ewelink
Can this be included in your master ?
Bye
Hi,
Currently I have a couple of sonoffs (but most are flashed to different firmware). There is one I would like to use in home assistant (and which is currently not supported by your script :)). The sonoff pow is basically a sonoff basic with power measurement capabilities (which also means that if flashed to alternate firmware you will need to recalibrate).
Attached is my output file (note I noticed my wifi password being in there so it is replaced by xxxx). Would be great if you could add the sonoff pow (and would be even better if power measurement is also presented in home assistant).
With kind regards,
StaticCube / Ferry
Hi there, first of all I'd like to thank you for your work. For some reason everytime I try to add the custom component and reboot my raspberry pi 2 will hang at "starting eudev-3.2.5", if I delete the custom_components folder and delete de sonoff part of my configuration.yaml it will go back to booting perfectly. I don't know what I'm doing wrong, I created the custom_component folder with its subfolders and files on the config/ folder. I'm running hassOS 1.13. Thanks in advance.
This is an amazing and much needed project, so firstly thanks for putting this together! Just tested my S26s which are on firmware 2.61 (I could not choose to update to 2.6 fro 1.8), so far no recognition in HA. Checked logs, all seems fine with authentification.
Anything else to check or any expected expansion on the firmware that will be supported for this device?
TIA!
My output
[
{
"__v": 0,
"_id": "[hidden]"
"apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"brandName": "Sonoff",
"createdAt": "xxxx-xx-xxxxx:xx:xx.xxx",
"deviceStatus": "",
"deviceUrl": "",
"deviceid": "[hidden]"
"devicekey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"extra": {
"_id": "[hidden]"
"extra": {
"apmac": "xx:xx:xx:xx:xx:xx",
"brandId": "58e5f344baeb368720e25469",
"description": "WO1818609",
"mac": "xx:xx:xx:xx:xx:xx",
"manufacturer": "\u6df1\u5733\u677e\u8bfa\u6280\u672f\u6709\u9650\u516c\u53f8",
"model": "PSC-B67-GL",
"modelInfo": "5a2e1ae50cf772f92c342ef6",
"ui": "\u529f\u7387\u68c0\u6d4b\u63d2\u5ea7\u8fc7\u8f7d\u544a\u8b66",
"uiid": 32
}
},
"group": "",
"groups": [],
"ip": "[hidden]"
"location": "",
"name": "[hidden]",
"offlineTime": "xxxx-xx-xxxxx:xx:xx.xxx",
"online": true,
"onlineTime": "xxxx-xx-xxxxx:xx:xx.xxx",
"params": {
"alarmCValue": [
-1,
15
],
"alarmPValue": [
-1,
-1
],
"alarmType": "c",
"alarmVValue": [
-1,
-1
],
"current": "0.04",
"endTime": "xxxx-xx-xxxxx:xx:xx.xxx",
"fwVersion": "2.7.0",
"hundredDaysKwh": "get",
"init": 1,
"oneKwh": "get",
"power": "1.57",
"rssi": -49,
"staMac": "xx:xx:xx:xx:xx:xx",
"startTime": "xxxx-xx-xxxxx:xx:xx.xxx",
"startup": "stay",
"switch": "on",
"timeZone": 1,
"voltage": "231.86"
},
"productModel": "Pow_R2",
"settings": {
"alarmNotify": 1,
"opsHistory": 1,
"opsNotify": 0
},
"sharedTo": [],
"showBrand": true,
"type": "10",
"uiid": 32
}
]
Hi,
I followed the readme, but the component fails to load.
Checking the config in the ui, tells component not found: sonoff.
This is the home-assistant.log:
2019-01-09 22:41:30 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.sonoff. Make sure all dependencies are installed
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 92, in get_component
module = importlib.import_module(path)
File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 673, in exec_module
File "", line 222, in _call_with_frames_removed
File "/home/homeassistant/.homeassistant/custom_components/sonoff.py", line 26, in
import websocket
ImportError: No module named 'websocket'
2019-01-09 22:41:30 ERROR (MainThread) [homeassistant.loader] Unable to find component sonoff
2019-01-09 22:41:30 ERROR (MainThread) [homeassistant.setup] Setup failed for sonoff: Component not found.
2019-01-09 22:41:31 ERROR (MainThread) [homeassistant.components.device_tracker] Unable to load /home/homeassistant/.homeassistant/known_devices.yaml: Config file not found: /home/homeassistant/.homeassistant/known_devices.yaml
2019-01-09 22:41:32 ERROR (Thread-8) [homeassistant.components.notify.ios] The notify.ios platform was loaded but no devices exist! Please check the documentation at https://home-assistant.io/ecosystem/ios/notifications/ for more information
2019-01-09 22:57:17 ERROR (Thread-4) [homeassistant.loader] Error loading custom_components.sonoff. Make sure all dependencies are installed
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 92, in get_component
module = importlib.import_module(path)
File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 673, in exec_module
File "", line 222, in _call_with_frames_removed
File "/home/homeassistant/.homeassistant/custom_components/sonoff.py", line 26, in
import websocket
ImportError: No module named 'websocket'
2019-01-09 22:57:17 ERROR (Thread-4) [homeassistant.loader] Unable to find component sonoff
I created a dedicated account for this.
It reads the devices name and status correctly. The switching itself does not work.
Hi,
Thank you for your work on this. Is it possible to look at adding the Sonoff B1.
Sonoff-debug info attached
Thanks
Greg
sonoffB1.txt
Nothing's working, especially cannot get my switch's to work in ifttt webhook automations. Using hassio getting a bunch of errors, worked fine the last week or so, just stopped last night. Seems if I restart my raspberry pi it works again but after I try to control some switch's with a ifttt webhook they stop working unless I restart my pi, here is the error:
Log Details (ERROR)
Wed Jan 16 2019 22:20:55 GMT-0800 (Pacific Standard Time)
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.py", line 277, in _handle_service_platform_call
await getattr(entity, func)(**data)
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/sonoff.py", line 461, in turn_off
self._state = self._hass.data[DOMAIN].switch(False, self._deviceid, self._outlet)
File "/config/custom_components/sonoff.py", line 341, in switch
self._ws.send(json.dumps(payload))
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 239, in send
return self.send_frame(frame)
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 264, in send_frame
l = self._send(data)
File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 425, in _send
return send(self.sock, data)
File "/usr/local/lib/python3.6/site-packages/websocket/_socket.py", line 109, in send
raise WebSocketConnectionClosedException("socket is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.
Currently the switches turn on one by one with a 2 second delay for each sonoff (or outlet within each)
While using ifttt and Google Assistant, turn on all the lights works very well.
Let's see if we can figure something out.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.