peterbuga / HASS-sonoff-ewelink

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

Detected I/O inside the event loop #232

Open mgiako opened 4 years ago

mgiako commented 4 years ago

In HomeAssistant 0.109.0b0 I have the folowing warning:

Log Details (WARNING) Logger: homeassistant.util.async Source: util/async.py:120 First occurred: 1:09:34 PM (539 occurrences) Last logged: 5:13:47 PM

Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sonoff doing I/O at custom_components/sonoff/init.py, line 374: ), headers=self._headers)

gx9001 commented 4 years ago

Hi There @peterbuga, how is going?, so I run the Logger config, and play a little with turning ON and OFF the lights form HA, Alexa, HomeKit AND from Ewelink, trying to get all the info that I can. I use Sonoff T1 US (1G, 2G and 3G), POW, Basic, SV and one led strip.

< < debug log removed > >

Hope This will Work and help, thanks for your work!!! really appreciate.

peterbuga commented 4 years ago

@gx9001 i edited the post as it contained a lot of possible devices information + it was super long too. i saved it and i'll analyze it later ;)

gx9001 commented 4 years ago

@gx9001 i edited the post as it contained a lot of possible devices information + it was super long too. i saved it and i'll analyze it later ;)

Thank's I was Worry about it, so I do replace the api key, hope that wouldn't affect you.

fudu commented 4 years ago

logger: default: warning logs: custom_components.sonoff: debug custom_components.switch.sonoff: debug

My log...

homeassistant.log

fudu commented 4 years ago

Another thing. I don't know if it's a HA or sonoff component related issue, but now when I switch on a sonoff device with inching active the device status in HA does not reflect real device status. After power on a switch with one second inching I see "powered on" it for a while. Before it was in very real time

peterbuga commented 4 years ago

Another thing. I don't know if it's a HA or sonoff component related issue, but now when I switch on a sonoff device with inching active the device status in HA does not reflect real device status. After power on a switch with one second inching I see "powered on" it for a while. Before it was in very real time

i fail to see how this is affecting the HA, it's not like you're actively watching the toggle to see when/if it changes. this might be a side effect of the async re-write meaning: before HA considered the component's flow as a "blocker" (what ever action was triggered it blocked HA and had to be waited), now instead, all the sonoff actions (in theory at least) are taken on a side, HA continue to do its thing, sonoff component does it's own and by the time the inching device reports back you're back to original state => no state.

what i'm trying to say: is this affecting in any way your automations? does HA has absolutely no record of inching being triggered in history (probably by the 2nd sonoff account)? you can enable the log debug as mentioned above and see if truly no action is reported to HA. ps: as far as i know HAs events are 1-sec clock based (aka it evaluates all the states/automations/etc every 1 sec) => moving faster than this might skip the reporting (aka the blocking part above)

niccolobusato commented 4 years ago

great work man! keep going!!!

ootktk commented 4 years ago

@peterbuga thanks for all the help thus far! great to see such enthusiasm in the community!

tyjtyj commented 4 years ago

I only have 1 ewelink switch throwing this error when starting home assistant. Any idea what cause it ?

2020-05-12 05:09:15 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up sonoff platform for binary_sensor
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/binary_sensor.py", line 23, in async_setup_platform
    if hass.data[SONOFF_DOMAIN].uiid_to_name[device['uiid']] == 'RF_BRIDGE':
KeyError: 77
2020-05-12 05:09:15 ERROR (MainThread) [homeassistant.components.fan] Error while setting up sonoff platform for fan
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/fan.py", line 19, in async_setup_platform
    if 'FAN' in hass.data[SONOFF_DOMAIN].device_type_by_uiid(device):
TypeError: argument of type 'NoneType' is not iterable
2020-05-12 05:09:15 ERROR (MainThread) [homeassistant.components.switch] Error while setting up sonoff platform for switch
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/switch.py", line 20, in async_setup_platform
    if 'FAN' in hass.data[SONOFF_DOMAIN].device_type_by_uiid(device):
TypeError: argument of type 'NoneType' is not iterable

Also this from time to time .. should i just supress the error ?

ERROR (Thread-3) [custom_components.sonoff] websocket error: Connection is already closed.

rark-ha commented 4 years ago

@peterbuga thanks for your help. The updated files solved the issues for me.

peterbuga commented 4 years ago

@tyjtyj copy-paste all the files from the branch

tyjtyj commented 4 years ago

@tyjtyj copy-paste all the files from the branch

I got from async-patch branch. Am I doing it correct ?

https://github.com/peterbuga/HASS-sonoff-ewelink/tree/async-patch

Update: I just finished copy the whole sonoff folder again and this is the error MY Home Assistant version 0.109.6. If you needed debug logs, will provide.

2020-05-12 17:16:01 WARNING (MainThread) [homeassistant.setup] Setup of sonoff is taking over 10 seconds.
2020-05-12 17:16:03 WARNING (MainThread) [homeassistant.components.binary_sensor] Setup of binary_sensor platform ping is taking over 10 seconds.
2020-05-12 17:16:11 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up sonoff platform for binary_sensor
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/binary_sensor.py", line 23, in async_setup_platform
    if hass.data[SONOFF_DOMAIN].uiid_to_name[device['uiid']] == 'RF_BRIDGE':
KeyError: 77
2020-05-12 17:16:11 ERROR (MainThread) [homeassistant.components.fan] Error while setting up sonoff platform for fan
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/fan.py", line 19, in async_setup_platform
    if 'FAN' in hass.data[SONOFF_DOMAIN].device_type_by_uiid(device):
TypeError: argument of type 'NoneType' is not iterable
2020-05-12 17:16:11 ERROR (MainThread) [homeassistant.components.switch] Error while setting up sonoff platform for switch
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/home/homeassistant/.homeassistant/custom_components/sonoff/switch.py", line 20, in async_setup_platform
    if 'FAN' in hass.data[SONOFF_DOMAIN].device_type_by_uiid(device):
TypeError: argument of type 'NoneType' is not iterable
peterbuga commented 4 years ago

thanks to @michielton 's input + the debugs above i've been able to hopefully track & fix the error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x6e9f4890>>: 'entity_id' error.

i'm quite confident this affected only the devices that have multiple outlets defined like touch switches with 2-3 gangs or 4ch, therefore anyone with a device/error like this please try the latest code just pushed in the async-patch branch and let us know how it works.

peterbuga commented 4 years ago

@fudu @gx9001 have you seen the last (above) message 😬 ?

lamboid commented 4 years ago

Just updated with the async-patch files and getting this after a couple of restarts...

2020-05-14 10:55:26 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sonoff.sensor: Platform not found (No module named 'custom_components.sonoff.sensor').
2020-05-14 10:55:26 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sonoff.light: Platform not found (cannot import name 'EWeLinkDevice' from 'custom_components.sonoff' (/config/custom_components/sonoff/__init__.py)).
peterbuga commented 4 years ago

@lamboid wrong (sonoff) project! 🙄

fudu commented 4 years ago

@fudu @gx9001 have you seen the last (above) message ?

Yes, thanks!

peterbuga commented 4 years ago

@fudu @gx9001 have you seen the last (above) message ?

Yes, thanks!

aaaaaaand now it's working ok for you or not? i need at least 1 confirmation 😅

VonXavier commented 4 years ago

Szczegóły loga (WARNING) Logger: homeassistant.util.async Source: util/async.py:120 First occurred: 16:37:13 (104 occurrences) Last logged: 18:18:56

Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sonoff doing I/O at custom_components/sonoff/init.py, line 176: headers=self._headers, json=app_details) Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sonoff doing I/O at custom_components/sonoff/init.py, line 374: ), headers=self._headers) Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sonoff doing I/O at custom_components/sonoff/init.py, line 221: r = requests.post('https://%s-disp.coolkit.cc:8080/dispatch/app' % self._api_region, headers=self._headers)

peterbuga commented 4 years ago

@VonXavier read the thread please!

fudu commented 4 years ago

@fudu @gx9001 have you seen the last (above) message ?

Yes, thanks!

aaaaaaand now it's working ok for you or not? i need at least 1 confirmation

For me it's okay, thank you

gx9001 commented 4 years ago

@fudu @gx9001 have you seen the last (above) message ?

Yes, thanks!

aaaaaaand now it's working ok for you or not? i need at least 1 confirmation 😅

Sorry, for the delay, I have copy the new files ande so far it is working fine!!! Thank you Men! great work!.

VonXavier commented 4 years ago

After copy all news file, there is an error what I wrote yesterday.

gx9001 commented 4 years ago

Hi There @peterbuga, after a day I do have an error,

Detalles del registro (ERROR) Logger: custom_components.sonoff Source: custom_components/sonoff/init.py:417 Integration: sonoff First occurred: 14 de mayo de 2020 23:36:48 (4 occurrences) Last logged: 1:36:21

websocket error: [Errno 104] Connection reset by peer

Thank's!

krasatos commented 4 years ago

@peterbuga Updated the files and restarted, No errors yet. 🤝 Will keep monitoring during the day and report back. Using several sonoff basics and one 4ch r2 pro

EDIT: after 11 days, no issues, well done :)

rpitera commented 4 years ago

@peterbuga - New branch is working for me, no I/O errors. Some new ones about deprecation, but that's to be expected with 0.110.x

Also, I have this working with a Sierra Modern Home Wi-Fi Smart Diffuser; it shows as a switch.

dapuzz commented 4 years ago

@peterbuga are we ready for a new release? :-) Tests seems to be ok! Thanks

quique123 commented 4 years ago

I just copied it into my rpi2/hassio machine (your latest async folder). [https://github.com/peterbuga/HASS-sonoff-ewelink/tree/async-patch] All seems well so far. I have a T3. I believe the old code was causing instability as reported by the home-assistant.log:

[homeassisdtant.util.async_] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom compo>
< component author for sonoff doing I/O at custom_components/sonoff/__init__.py, line 374: ), headers=self._headers)

So i replaced the old sonoff and sonoff-debug folders for these new ones. What happened before was that I would reboot my rpi2/hassio and it would work fine for a week or two, then lovelace UI would stop working (page wouldnt load on the browser) but ssh was fine into the pi. Eventually there was issues with the router and the pi would no longer connect to the router (no ping, no ip, no dhcp lease) perhaps because it just made it so unstable and i would have to reboot. Ill report back to see how this is doing.

niraviry commented 4 years ago

Unfortunately, the above error appears in my system - hassio version 0.110.4 with RPi4. Updating to the latest version causes the system to get stuck. I have no idea what is the error but when I return to the old version (samba still works) the system boots again but the above error remains. I need help as the error causes the system to loose web GUI.

dave-code-ruiz commented 4 years ago

Warning not show for me more, when i update with this code patch:

https://github.com/peterbuga/HASS-sonoff-ewelink/tree/async-patch

Thnks @peterbuga

jazzmonger commented 4 years ago

New branch installed today and the I/O error is gone! nice.

cristianovsky commented 4 years ago

Solucionado¡¡¡¡ despues de actualizar el patch....felicitaciones.