Sonoff /eWeLink component for original firmware

So I built a home automation system for my pool and hot tub control. Heater thermostat was out so used a sonoff TH16 to monitor hot tub temp and kick heater power off at 104. Problem now is that I made the mistake of upgrading firmware to 3.3 and now the Temp does not update… the hot tub got to 120 degrees.
Any fixes available yet to have the TH16 update temp?

This sonoff/eWelink componet has been great until this latest sonoff firmware upgrade.

Using Hass.io Home Assistant and Node Red for automation.

Oh right, the 3.3.0+ is the problem I guess. My POW R2 with that version of firmware is doing the same. The refresh rate do not work unless you open the ewelink. Maybe some king of downgrade would help if there is a chance.

Jumped ship from sonoff software to flashing ESPhome firmware and all is now good. Was hoping to stay with sonoff and not flash custom firmware but it was a breeze.

Wise man :slight_smile:

Hi,
How did you create these graphs? Can we export Sonoff Pow measured Voltage, current and Power in tables or graphs?
Kind Regards.

Hi Peter,
i’ve Hassio (in a RPI3b) working. and i’ve one sonoff Led Lamp B. i’ve tried to install your component but i got this error :
"
2019-09-25 10:26:14 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 266, in async_update_ha_state
self._async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 300, in _async_write_ha_state
state = self.state
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 554, in state
return STATE_ON if self.is_on else STATE_OFF
File “/config/custom_components/sonoff/switch.py”, line 75, in is_on
self._state = self.get_state()
File “/config/custom_components/sonoff/init.py”, line 648, in get_state
return device[‘params’][‘switch’] == ‘on’ if device else False
KeyError: ‘switch’

"

my conf is :


script: !include scripts.yaml

sonoff:
username: myusername.mail
password: mypassword
scan_interval: 60
grace_period: 600
api_region: ‘eu’
entity_prefix: True
debug: True

can you help me?

thanks

Don’t ask me what I did but it is all working now. I suspect I had a space somewhere I was not supposed to.

I did put a delay 1s between each service and the issue was fixed. Thank you very much.

    alias: 'Tự động tắt đèn phòng ăn (out motion)'
    trigger:
      - platform: state
        entity_id: sensor.motiondetect_corridor
        to: 'Clear'
        from: 'Detect Mode'
    condition:
      - condition: time
        after: '23:00:00'
        before: '05:00:00'
    action:
      - service: switch.turn_off
        entity_id: switch.sonoff_10008700fd_1
      - delay:
          seconds: 1
      - service: switch.turn_off
        entity_id: switch.sonoff_10008700fd_2

Hi I get this on the log file:
[custom_components.sonoff] found new region: >>> as <<< (you should change api_region option to this value in configuration.yaml)

This is my config:
sonoff:
username: ‘+97254453642’
password: ***********
scan_interval: 60
grace_period: 600
api_region: ‘eu’

do i need to change something?

Hazzz . today , it not woking…

2019-09-27 16:11:39 WARNING (MainThread) [homeassistant.loader] You are using a custom integration 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-09-27 16:11:42 ERROR (MainThread) [homeassistant.setup] Error during setup of component sonoff
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/setup.py”, line 168, in _async_setup_component
hass, processed_config
File “/config/custom_components/sonoff/init.py”, line 53, in async_setup
hass.data[DOMAIN] = Sonoff(hass, config)
File “/config/custom_components/sonoff/init.py”, line 108, in init
self.do_login()
File “/config/custom_components/sonoff/init.py”, line 192, in do_login
self.update_devices() # to write the devices list
File “/config/custom_components/sonoff/init.py”, line 357, in update_devices
if self.is_grace_period():
File “/config/custom_components/sonoff/init.py”, line 322, in is_grace_period
grace_time_elapsed = self._skipped_login * int(SCAN_INTERVAL.total_seconds())

plz help me !!!
config

sonoff:
username: !secret sonoff_user
password: !secret sonoff_pass
scan_interval: 90
grace_period: 600
api_region: ‘eu’
entity_prefix: True
debug: False

LOG ERROR

Error during setup of component sonoff
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 168, in _async_setup_component
    hass, processed_config
  File "/config/custom_components/sonoff/__init__.py", line 53, in async_setup
    hass.data[DOMAIN] = Sonoff(hass, config)
  File "/config/custom_components/sonoff/__init__.py", line 108, in __init__
    self.do_login()
  File "/config/custom_components/sonoff/__init__.py", line 170, in do_login
    self.do_login()
  File "/config/custom_components/sonoff/__init__.py", line 192, in do_login
    self.update_devices() # to write the devices list
  File "/config/custom_components/sonoff/__init__.py", line 357, in update_devices
    if self.is_grace_period():
  File "/config/custom_components/sonoff/__init__.py", line 322, in is_grace_period
    grace_time_elapsed = self._skipped_login * int(SCAN_INTERVAL.total_seconds())
NameError: name 'SCAN_INTERVAL' is not defined

You have no indentation in your yaml file.

no no . it is format 4rum
BUT
1

@MetalSpine terrible sorry for what happened to you but I hope you understand these kind of issues are not something I can fix/prevail (I still don’t understand why everyone keeps updating stuff if they’re working just fine as they are, especially when working in a hack-ish environment ¯\_(ツ)_/¯ ). in the same time glad you sorted it out :+1:
(as a side note i’m thinking to completely remove the sensor support from this component to avoid people creating important actions leveraging on not-so-safe reporting. not the best idea, but i guess better safe than sorry!)

@RTamag “sonoff Led Lamp B” is this a sonoff B1? if so, read this fresh new problem :roll_eyes:

@yoni3210 “do i need to change something?” it’s optional, but it’s a bit faster to boot if you do so => api_region: 'as'

@DannyGoh @vipk31 check here

I got the latest source code but still got an error

Error during setup of component sonoff
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 168, in _async_setup_component
    hass, processed_config
  File "/config/custom_components/sonoff/__init__.py", line 53, in async_setup
    hass.data[DOMAIN] = Sonoff(hass, config)
  File "/config/custom_components/sonoff/__init__.py", line 101, in __init__
    self.do_login()
  File "/config/custom_components/sonoff/__init__.py", line 194, in do_login
    self.update_devices() # to write the devices list
  File "/config/custom_components/sonoff/__init__.py", line 359, in update_devices
    if self.is_grace_period():
  File "/config/custom_components/sonoff/__init__.py", line 324, in is_grace_period
    grace_time_elapsed = self._skipped_login * int(self.get_scan_interval().total_seconds())
  File "/config/custom_components/sonoff/__init__.py", line 104, in get_scan_interval
    if self._hass.data[DOMAIN].get_debug_state():
KeyError: 'sonoff'

Can help me

No apologies needed! Right after I hit update I instantly regretted it and thought I should have researched it first. Your code is still running all my other sonoff devices!

My pool and hot tub valves, pump, heater, air jets and lights all work automatically using your code for sonoff integration into home assistant.

Deeply appreciate your work.

Thank you @peterbuga

1 Like

a small bug was introduced by the time you probably tried it (sorry for that), but’s fixed now … i hope. not sure why but HA seems to behave slightly different on different environments :confused:

First of all great job!!! @peterbuga
I have an issue, that my sockets (S20 2 pieces) are is unavailable after a few mins, i updated the files to latest yesterday.

i created another account for ha and share the account from the main account, i’m using the second one that i created for HA.

This is the error from the log file:

2019-09-30 12:23:47 WARNING (MainThread) [custom_components.sonoff] Grace period activated!
2019-09-30 12:24:01 WARNING (MainThread) [homeassistant.components.device_tracker] Updating device list from legacy took longer than the scheduled scan interval 0:00:12
2019-09-30 12:24:26 WARNING (MainThread) [homeassistant.components.device_tracker] Updating device list from legacy took longer than the scheduled scan interval 0:00:12
2019-09-30 12:25:31 WARNING (MainThread) [homeassistant.components.device_tracker] Updating device list from legacy took longer than the scheduled scan interval 0:00:12
2019-09-30 12:25:34 ERROR (Thread-7) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x7fe6efbb5490>>: string indices must be integers
2019-09-30 12:25:34 ERROR (Thread-16) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x7fe6efbb5490>>: string indices must be integers
2019-09-30 12:25:34 ERROR (Thread-10) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x7fe6efbb5490>>: string indices must be integers
2019-09-30 12:25:34 ERROR (Thread-19) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x7fe6efbb5490>>: string indices must be integers
2019-09-30 12:25:34 ERROR (Thread-13) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x7fe6efbb5490>>: string indices must be integers
2019-09-30 12:25:34 ERROR (Thread-25) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x7fe6efbb5490>>: string indices must be integers
2019-09-30 12:25:34 ERROR (Thread-2) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x7fe6efbb5490>>: string indices must be integers
2019-09-30 12:25:34 ERROR (Thread-22) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x7fe6efbb5490>>: string indices must be integers

After the state changes to unavailable, i got the code below:

2019-09-30 12:46:29 ERROR (Thread-16) [custom_components.sonoff] websocket error: Connection is already closed.
2019-09-30 12:46:31 ERROR (Thread-16) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:46:31 ERROR (Thread-10) [custom_components.sonoff] websocket error: [Errno 9] Bad file descriptor
2019-09-30 12:46:32 ERROR (Thread-16) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:46:33 ERROR (Thread-10) [custom_components.sonoff] websocket error: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2508)
2019-09-30 12:46:33 ERROR (Thread-16) [custom_components.sonoff] websocket error: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1076)
2019-09-30 12:46:34 ERROR (Thread-10) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:46:35 ERROR (Thread-16) [custom_components.sonoff] websocket error: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2508)
2019-09-30 12:46:35 ERROR (Thread-10) [custom_components.sonoff] websocket error: [SSL: CERT_LENGTH_MISMATCH] cert length mismatch (_ssl.c:1076)
2019-09-30 12:46:36 ERROR (Thread-10) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:46:37 ERROR (Thread-10) [custom_components.sonoff] websocket error: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1076)
2019-09-30 12:46:37 ERROR (Thread-16) [custom_components.sonoff] websocket error: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2508)
2019-09-30 12:46:39 ERROR (Thread-10) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:46:41 ERROR (Thread-19) [custom_components.sonoff] websocket error: Connection is already closed.
2019-09-30 12:46:51 ERROR (Thread-10) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'connected'
2019-09-30 12:46:53 WARNING (MainThread) [homeassistant.components.device_tracker] Updating device list from legacy took longer than the scheduled scan interval 0:00:12
2019-09-30 12:46:53 ERROR (Thread-22) [custom_components.sonoff] websocket error: Connection is already closed.
2019-09-30 12:47:03 ERROR (Thread-10) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'connected'
2019-09-30 12:47:06 ERROR (Thread-22) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'connected'
2019-09-30 12:47:08 WARNING (MainThread) [custom_components.sonoff] Grace period activated!
2019-09-30 12:47:11 ERROR (Thread-25) [custom_components.sonoff] websocket error: Connection is already closed.
2019-09-30 12:47:13 ERROR (Thread-25) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:47:13 ERROR (Thread-22) [custom_components.sonoff] websocket error: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2508)
2019-09-30 12:47:13 ERROR (Thread-25) [custom_components.sonoff] websocket error: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1076)
2019-09-30 12:47:16 ERROR (Thread-22) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:47:19 ERROR (Thread-28) [custom_components.sonoff] websocket error: Connection is already closed.
2019-09-30 12:47:21 ERROR (Thread-28) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:47:22 ERROR (Thread-22) [custom_components.sonoff] websocket error: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2508)
2019-09-30 12:47:22 ERROR (Thread-28) [custom_components.sonoff] websocket error: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1076)
2019-09-30 12:47:23 ERROR (Thread-28) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:47:23 ERROR (Thread-22) [custom_components.sonoff] websocket error: [Errno 9] Bad file descriptor
2019-09-30 12:47:25 ERROR (Thread-28) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:47:25 ERROR (Thread-28) [custom_components.sonoff] websocket error: [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1076)
2019-09-30 12:47:25 ERROR (Thread-22) [custom_components.sonoff] websocket error: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2508)
2019-09-30 12:47:26 ERROR (Thread-28) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:47:27 ERROR (Thread-22) [custom_components.sonoff] websocket error: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2508)
2019-09-30 12:47:27 ERROR (Thread-28) [custom_components.sonoff] websocket error: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1076)
2019-09-30 12:47:28 ERROR (Thread-22) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'
2019-09-30 12:47:29 ERROR (Thread-28) [custom_components.sonoff] websocket error: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2508)
2019-09-30 12:47:29 ERROR (Thread-22) [custom_components.sonoff] websocket error: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1076)
2019-09-30 12:47:30 ERROR (Thread-28) [custom_components.sonoff] websocket error: 'NoneType' object has no attribute 'is_ssl'

This the config:

sonoff:
  username: [email protected]
  password: sdgfsdfgsd
  scan_interval: 60 
  grace_period: 600
  api_region: 'as'
  # entity_prefix: True
  # debug: False

Any idea what to do ?

nop :roll_eyes: