peterbuga / HASS-sonoff-ewelink

Home Assistant component to control Sonoff/eWeLink devices with original firmware
MIT License
797 stars 294 forks source link

Dimmer for example vHome #37

Open Rom1985 opened 5 years ago

Rom1985 commented 5 years ago

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

peterbuga commented 5 years ago

Hi @Rom1985 please follow these basic steps https://github.com/peterbuga/HASS-sonoff-ewelink/tree/master/sonoff-debug and how to provide device data for me to integrate. Without this information I don't know the device works!

Could you please let me know if the ON/OFF toggle works ok right now?

thanks

Rom1985 commented 5 years ago

Could you please let me know if the ON/OFF toggle works ok right now?

thanks

Thanks for the answer. Yes. The on / off function works well on these dimmers. But there is no brightness adjustment.

peterbuga commented 5 years ago

I just mentioned above that I need device data from you to fully integrate this sonoff led :| implicitly the brightness part... particularly this https://github.com/peterbuga/HASS-sonoff-ewelink/issues/21#issuecomment-451238585

Rom1985 commented 5 years ago

I run python3 sonoff-debug.py -u 'email or phone-number username' -p 'password' > devices.json I receive:

File "sonoff-debug.py", line 22 print 'Please read the instructions better!' ^ SyntaxError: Missing parentheses in call to 'print'

peterbuga commented 5 years ago

@Rom1985 i could say the error above it's somehow my fault, so sorry for that đŸ˜„ i just updated the sonoff-debug.py script to make it more universal (as in it works for a person, but does not for another due to various account/devices configurations) please download and use this latest version from here https://github.com/peterbuga/HASS-sonoff-ewelink/blob/master/sonoff-debug/sonoff-debug.py instead of python3 you can also try to use python2.7 or simply python

Rom1985 commented 5 years ago

@peterbuga I run python3 sonoff-debug.py -u 'email or phone-number username' -p 'password' > devices.json I do not get errors. But file devices.json looks like this: "Please read the instructions better!"

p.s. I run the script on raspberry pi b+. For the version of python2.7, I do not have the necessary modules. Modules are only for version python3

peterbuga commented 5 years ago

@Rom1985 aaand again my bad :( sometimes i take some things for granted and i miss on some of the basic stuff 😓 you can run it like this python3 sonoff-debug.py 'email or phone-number username' 'password' with no -u and -p flags or you can redownload a new (fixed) version from above. apologies again!

Rom1985 commented 5 years ago

@peterbuga I get: Traceback (most recent call last): File "sonoff-debug.py", line 58, in do_login hex_dig = hmac.new(decryptedAppSecret, json.dumps(app_details), digestmod=hashlib.sha256).digest() File "/usr/lib/python3.5/hmac.py", line 144, in new return HMAC(key, msg, digestmod) File "/usr/lib/python3.5/hmac.py", line 84, in init self.update(msg) File "/usr/lib/python3.5/hmac.py", line 93, in update self.inner.update(msg) TypeError: Unicode-objects must be encoded before hashing

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "sonoff-debug.py", line 100, in do_login() File "sonoff-debug.py", line 62, in do_login hex_dig = hmac.new(decryptedAppSecret, json.dumps(app_details), digestmod=hashlib.sha256).digest() File "/usr/lib/python3.5/hmac.py", line 144, in new return HMAC(key, msg, digestmod) File "/usr/lib/python3.5/hmac.py", line 42, in init raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).name) TypeError: key: expected bytes or bytearray, but got 'str'

peterbuga commented 5 years ago

again differences between python versions :| super totally fixed it, tested all the combos i could think of so far! download again https://github.com/peterbuga/HASS-sonoff-ewelink/blob/master/sonoff-debug/sonoff-debug.py

Rom1985 commented 5 years ago

@peterbuga I run and see -> screenshot scr

After a while I press Ctrl + c. I see: ^CTraceback (most recent call last): File "sonoff-debug.py", line 100, in do_login() File "sonoff-debug.py", line 67, in do_login r = requests.post('https://%s-api.coolkit.cc:8080/api/user/login' % api_region, headers=headers, json=app_details) File "/usr/lib/python3/dist-packages/requests/api.py", line 110, in post return request('post', url, data=data, json=json, kwargs) File "/usr/lib/python3/dist-packages/requests/api.py", line 56, in request return session.request(method=method, url=url, kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 488, in request resp = self.send(prep, send_kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 609, in send r = adapter.send(request, kwargs) File "/usr/lib/python3/dist-packages/requests/adapters.py", line 423, in send timeout=timeout File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 594, in urlopen chunked=chunked) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 350, in _make_request self._validate_conn(conn) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 837, in _validate_conn conn.connect() File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 281, in connect conn = self._new_conn() File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 138, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 88, in create_connection sock.connect(sa) KeyboardInterrupt

File devices.json is empty

peterbuga commented 5 years ago

@Rom1985 oh man sorry to disappoint but I really have no exact idea of what is happening on your environment :| in theory it should definitely work, but instead I think you are stuck in the login-loop where the script tries to detect the correct login region. this worked ok so far, and exactly the same logic is inside the custom component, therefore, if this doesn't work the component won't work ok either :|

judging from your screenshot and IF you installed Home Assistant like this https://www.home-assistant.io/docs/installation/raspberry-pi/ you could try to switch to homeassistant user and activate the virtual environment and then run the sonoff-debug.py script. although running as root should work too (but strangely it doesn't) running it like this you are sure to access the same packages as HA installation!

$ sudo -u homeassistant -H -s
$ source /srv/homeassistant/bin/activate

don't run the commands if you know it's not going to work for you (or maybe paths might need to be updated). also, they won't do any damage, worst case scenario just throw some error

ghizmo82 commented 5 years ago

there is a new for this article?

peterbuga commented 5 years ago

@ghizmo82 as you can see @Rom1985 had a hard time providing the dump data needed for me to be able to implement this. would you be willing to step in and help out too? (if so try to follow all of the above steps)

ghizmo82 commented 5 years ago

can you explain the procedure to follow? sorry but I don't speak English very well

peterbuga commented 5 years ago

@ghizmo82 start from here https://github.com/peterbuga/HASS-sonoff-ewelink/issues/37#issuecomment-453002209

ghizmo82 commented 5 years ago

i have to download sonoff-debug.py but in what path should i enter it? after i launch the script from terminal?

peterbuga commented 5 years ago

you put it anywhere, you go in command line, cd (change directory) to that place you added it and you just run it as it's specified above. just like that. if you think it's too complicated don't stress too much about it, eventually someone else will post a dump for it

donandns commented 5 years ago

Hi!!! Finally I made what you asked me to do (HA forum).

Just to refresh, my first post (HA forum): "First of all, sorry about my english (ain’t my native language). I bought a generic (aliexpress) dimmer switch. It works perfectly on ewelink app.

On HA (hassio), just shows on off (switch) without dimmer, at least I couldn’t find these entities. In “services” just appear the switch’s entity (switch.sonoff_xxxxxxxxx).

Did you find any advanced user to follow you up on this question (I’m a newbie one)? How can I make my self useful to this task? I promiss that I’ll respond ASAP.

Running: RPI 3B Hassio HassOS 1.13 HA 0.94.4"

OBS: There are some sonoffs, the dimmer is switch.sonoff_1000437aef.

I made a persistant notification debug and the results are these:

Steps that I did: 1 - ewelink app turn on switch (brightness 50 by default) 2 - ewelink app set brightness to 20 (not exactly this value) 3 - ewelink app set brightness to 0 4 - ewelink app set brightness to 30 (not exactly this value) 5 - ewelink app set brightness to 60 (not exactly this value) 6 - ewelink app set brightness to 90 (not exactly this value) 7 - ewelink app set brightness to 100 8 - ewelink app set brightness to 50 (not exactly this value) 9 - one touch on physical button (I think it was the lower brightness button) 10 - one touch on physical button (I think it was the bigger brightness button) 11 - three fast touches on physical button (I think it was lower button) 12 - three fast touches on physical button (I think it was bigger button)

Debug persistant notification:

`------------COPY-FROM-HERE--------------

2019-08-07 20:38:14.016 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "params": {"bright": 30}, "sequence": "1565221235087", "tempRec": "1000437aef", "ts": 0, "userAgent": "app"}

2019-08-07 20:38:14.703 [s] {"entity_id": "switch.sonoff_1000437aef", "outlet": null, "state": "on"}

2019-08-07 20:38:14.704 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"bright": 30, "switch": "on"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:38:31.013 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "params": {"bright": 10}, "sequence": "1565221252110", "tempRec": "1000437aef", "ts": 0, "userAgent": "app"}

2019-08-07 20:38:31.702 [s] {"entity_id": "switch.sonoff_1000437aef", "outlet": null, "state": "on"}

2019-08-07 20:38:31.703 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"bright": 10, "switch": "on"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:38:53.895 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "params": {"bright": 38}, "sequence": "1565221275070", "tempRec": "1000437aef", "ts": 0, "userAgent": "app"}

2019-08-07 20:38:54.607 [s] {"entity_id": "switch.sonoff_1000437aef", "outlet": null, "state": "on"}

2019-08-07 20:38:54.609 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"bright": 38, "switch": "on"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:39:12.013 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "params": {"bright": 67}, "sequence": "1565221293126", "tempRec": "1000437aef", "ts": 0, "userAgent": "app"}

2019-08-07 20:39:12.708 [s] {"entity_id": "switch.sonoff_1000437aef", "outlet": null, "state": "on"}

2019-08-07 20:39:12.710 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"bright": 67, "switch": "on"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:39:27.410 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "params": {"bright": 85}, "sequence": "1565221308684", "tempRec": "1000437aef", "ts": 0, "userAgent": "app"}

2019-08-07 20:39:28.957 [s] {"entity_id": "switch.sonoff_1000437aef", "outlet": null, "state": "on"}

2019-08-07 20:39:28.958 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"bright": 85, "switch": "on"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:39:30.207 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"fwVersion": "2.0.2", "rssi": -58, "staMac": "xx:xx:xx:xx:xx:xx"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:39:50.714 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "params": {"bright": 100}, "sequence": "1565221331828", "tempRec": "1000437aef", "ts": 0, "userAgent": "app"}

2019-08-07 20:39:51.409 [s] {"entity_id": "switch.sonoff_1000437aef", "outlet": null, "state": "on"}

2019-08-07 20:39:51.411 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"bright": 100, "switch": "on"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:40:03.135 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000236d45", "from": "device", "params": {"rssi": -39}, "ts": 0, "userAgent": "device"}

2019-08-07 20:40:07.917 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "params": {"bright": 56}, "sequence": "1565221349082", "tempRec": "1000437aef", "ts": 0, "userAgent": "app"}

2019-08-07 20:40:08.622 [s] {"entity_id": "switch.sonoff_1000437aef", "outlet": null, "state": "on"}

2019-08-07 20:40:08.624 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"bright": 56, "switch": "on"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:41:40.934 [S] {"entity_id": "1000437aef", "new_state": "off", "outlet": null}

2019-08-07 20:41:41.603 [W] {"apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "error": 0, "sequence": "1565221300927625"}

2019-08-07 20:41:42.334 [s] {"entity_id": "switch.sonoff_1000437aef", "outlet": null, "state": "off"}

2019-08-07 20:41:42.335 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000437aef", "from": "device", "params": {"bright": 56, "switch": "off"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:41:47.934 [s] {"entity_id": "switch.sonoff_1000236d45", "outlet": null, "state": "off"}

2019-08-07 20:41:47.935 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000236d45", "from": "device", "params": {"switch": "off"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:42:53.424 [s] {"entity_id": "switch.sonoff_1000236d45", "outlet": null, "state": "on"}

2019-08-07 20:42:53.425 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000236d45", "from": "device", "params": {"switch": "on"}, "ts": 0, "userAgent": "device"}

2019-08-07 20:43:03.145 [W] {"action": "update", "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "deviceid": "1000236d45", "from": "device", "params": {"rssi": -42}, "ts": 0, "userAgent": "device"}

---------------END-OF-COPY----------------`

Thanks!!!