GithubHelp home page GithubHelp logo

peterbuga / hass-sonoff-ewelink Goto Github PK

View Code? Open in Web Editor NEW
793.0 83.0 297.0 195 KB

Home Assistant component to control Sonoff/eWeLink devices with original firmware

License: MIT License

Python 100.00%
sonoff ewelink stock-firmware smart-switch

hass-sonoff-ewelink's Introduction

Home Assistant component for original firmware Sonoff / eWeLink smart devices

Simple Home Assistant component to add/control Sonoff/eWeLink smart devices using the stock firmware and retaining the cloud capabilities.


WARNING: completely deactivate the sonoff component from HA while doing a firmware update, due to auto-relogin function you might be kicked out of the app before the process is completed. I would not be held liable for any problems occuring if not following this steps!


CHECK COMPATIBILITY LIST BELOW (not everyday updated)! TRY THE COMPONENT FIRST AND IF IT DOESN'T WORK FOR YOUR DEVICE DON'T COMPLAIN AND OPEN A PROPER ISSUE

Setup

To setup add to your configuration.yaml:

sonoff:
  username: [email or phone number]
  password: [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)

And copy the *.py files in custom_components folder using the same structure like defined here:

 custom_components
    └── sonoff
        └── __init__.py
        └── switch.py
        └── sensor.py

email [Deprecated] used only for compatibility, may be eliminated in future.

username the username that you registered for ewelink account be it an email or a phone number (the phone number should lead with region number, '+8612345678901' for example).

scan_interval you can define how fast the state of devices is refreshed (by default every 60sec). for example if you change the switch from an external source like Alexa or Google Home the change will show up in HA in maximum less than specified period, while changing it using HA interface/actions/etc it's instantly

grace_period eWeLink app allows only one active session at a time, therefore this will temporarily block HA refreshes for the specified amount (in seconds) to allow (or better said after) you to login in the app and do required changes to your devices. following that sonoff component does an internal re-login invalidating the mobile session and the process restarts. (as a workaround for this, you can create a 2nd account and share the devices from main one, therefore one will be used in HA another one in mobile app)

api_region this component tries to find, login & connect to the proper region assigned to you. specifying a proper region will help the component to load faster and reconnect after the expired grace period explained above, possible values: eu (default), us, as or cn

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)

debug log generation / new device / new features requests

debug if enabled this will give you the ability to generate a log of messages from ewelink that can be easily posted here to debug/implement new devices.

steps and how it works:

  • this option creates a pseudo switch entity switch.sonoff_debug (notice it won't show up automatically in frontend in lovelace you have to manually add it or toggle it from Developer tools > Services section).
  • to generate a sonoff debug log toggle the pseudo-switch ON and the capture of messages will silently start in the background. now pick up the phone -> open eWeLink app and start changing settings of your Sonoff device but not faster than 10+ seconds between each change.
  • when you finish toggle the pseudo-switch OFF and a new (very long) persistent notification will show up.
  • go to Developer tools > States section and look for a persistent_notification.notification entity (impossible to miss due to its extremely long attribute text) and copy the message from there (to remove this notifications and others just push the button Dismiss them from main HA notifications area and you can restart the process and generate a new log if needed).

INFORMATION: it'll be better if you share the device-to-debugged to a 2nd eWeLink account and use this in HA and main account in mobile app, this way you won't be logged out of the app anymore and the generated log will be restricted to only 1 device

NOTICE: you should NOT leave debug-mode enabled for everyday use, please please just don't!

This is just a proof of concept because I searched for it and there was no implementation to use Sonoff/eWeLink devices without flashing them. (althought I know how to do it, I don't have a real extensive usage for now and I prefer to keep them on stock firmware).

Compatibility list

Model Supported 1.6 1.8.1 2.6 2.6.1 2.7.0 2.7.1 3.0.0 3.0.1 3.3.0 Remarks
Sonoff Basic yes yes yes yes yes
Sonoff Basic R3 yes yes
Sonoff Dual yes
Sonoff RF yes yes yes yes
Sonoff SC (retired) yes hum/temp/dust/light/noise sensors
Sonoff G1 ?
Sonoff 4CH Pro yes yes yes yes
Sonoff 4CH Pro R2 yes yes yes yes
Sonoff S20 yes yes yes
Sonoff S30 yes yes
Sonoff S31 yes + power/current/voltage sensors
Sonoff S26 yes yes yes yes version: Euro
Sonoff T1 1C yes yes
Sonoff T1 EU 2C yes yes
Sonoff T1 UK 3C yes yes yes
Sonoff T1 US 3C yes
Sonoff TX 1C yes yes
Sonoff Pow yes + power sensor
Sonoff Pow R2 yes partial NO sensors data! + power/current/voltage sensors
Sonoff TH10/TH16 yes + temp/humidity sensors
Sonoff iFan02 yes it creates 4 switches, 1 for the light and 3 for the various fan speeds
Sonoff iFan03 yes it creates 4 switches, 1 for the light and 3 for the various fan speeds
Sonoff HT-TH31 ?
Sonoff Slampher RF yes yes yes yes yes
3 Gang Generic Wall Switch yes yes yes Manfufacturer: pro-sw, Model: PS-15-ES (according to ewelink app)
1 Gang Generic Wall Switch yes yes yes yes manfufacturer: KingART, model: KING-N1 (according to ewelink app), Chip: PSF-B85 (ESP8285)
WHDTS WiFi Momentary Inching Relay yes displayed as a switch button
MHCOZY WiFi Wireless 5V/12V yes
Geekcreit 2 Channel AC 85V-250V yes yes
Smart Wi-Fi Outlet yes
Sonoff Mini yes yes yes

yes = confirmed version, [empty] = unknown for sure

Updates

  • 2019.04.08
    • HA0.88+ new component structure
    • added basic rules to create the same number of switches as presented by the physical device
  • 2019.02.++ alternate faster version with state updates over websocket developed
  • 2019.01.06 create sensors for devices that have support for power/current/voltage/temperature/humidity
  • 2018.12.05
    • mandarin phone number login support
    • removed entity_name option, the entities will have a fixed structure from now on
  • 2018.12.01
    • ability to control devices with multiple switches
    • added mobile app specified device-name as default to be listed in HA entity, added entity_name option and removed the default sonoff_ prefix
    • fixed bug that will show device as unavailable in the grace period
  • 2018.11.29 shared devices from another account can be used also
  • 2018.11.28
    • mobile app-like login to the closest region
    • added scan_interval option
    • added grace_period option

Requests / Bugs

Feel free to properly ask support for new devices using the guidelines mentioned in the section above regarding the debug section (or the older basic version) / report bugs / request features / fork (& pull request) and I'll try to see what I can do.

Credits

awesome ❤️ & support 🙌!

Donate

Feel free to help me invest in more devices to test and add faster new features to this component! paypal

hass-sonoff-ewelink's People

Contributors

2016for avatar bauerseins avatar burdandrei avatar difelice avatar fixxcz avatar guykh avatar insajd avatar notabene01 avatar pawelbura avatar peterbuga avatar ping-localhost avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hass-sonoff-ewelink's Issues

"Error doing job: Task exception was never retrieved" issue under hass.io

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

Use binding the same way as google home

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.

Sonoff RF Bridge integration

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 } ] 

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)

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)

Unable to find component sonoff

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

Hello, this plugin is great (unable to login using phone number)

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
pycache sonoff-debug sonoff.py switch
pi@raspberrypi:
/.homeassistant/custom_components $ cd sonoff-debug
pi@raspberrypi:/.homeassistant/custom_components/sonoff-debug $ python sonoff-debug.py '+86xxxxxxxxx' 'xxxxxxxxx' > devices.json
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:
/.homeassistant/custom_components/sonoff-debug $

Sonoff Pow R2 with power measurements

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
  }
]

Issues after updating to HA 0.88

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

Anyone else have issues today?

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.

Broken Pipe errors / Bad write retry errors

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)

Switching not working

I created a dedicated account for this.
It reads the devices name and status correctly. The switching itself does not work.

Looks like adding device other than Sonoff Basic breaks the whole component

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'

succes test

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,

Error doing job: Task exception was never retrieved

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'

Sonoff S26 pn 2.6.1

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!

use LAN mode if HASS is unable to contact the server

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.

https://github.com/beveradb/sonoff-lan-mode-homeassistant

HA 0.88.1 on Termux do not work

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?

Turning on multiple switches

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.

New eWeLink device Sonoff G1

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
  }
]

New Device: Sonoff Pow

devices.txt

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

Include Geekcreit 2 Channel AC 85V-250V

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:

devices.txt

Regards,

'outlet' not defined

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

HA connection errors

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.

Error while setting up platform sonoff

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

Hassio hangs on bootup after adding the the sonoff component

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.

Sonoff T1 US 3C Compatibility

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!

Have component added as official home assistant component?

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?

Cannot establish a new connection

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

TH16 Sensor Readings

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 Switches

###################################
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.

HA Docker

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

Sonoff 1 channel inching 5V/12

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?

Sonoff 2 ch as 4 entities

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

sonoff T1 EU

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.

New device Kingart king-q4

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!

Installation

How install this component inside home assistant?
I tried to add repository url but it only adds an unknown box...

Websocket errors on HA startup

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.

home-assistant.log

devices.json.txt

edit @peterbuga: removed bold font

Problems with HA r. 087.1?

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,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.