asantaga / lightwaverf_HA_EnergySensor

Home Assistant Sensor for the LightwaveRF energy monitor
MIT License
5 stars 3 forks source link

Address in use error #7

Closed danielsmith89 closed 2 years ago

danielsmith89 commented 2 years ago

Hello,

Just installed this, and it works great most of the time, but occasionally I will get the following error in the logs and the sensors won't start updating again until I restart Home Assistant. Any ideas? Thanks


Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 401, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 609, in async_device_update
    raise exc
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/lightwaverf_energy/sensor.py", line 55, in update
    sock.bind(("0.0.0.0", 9761))
OSError: [Errno 98] Address in use
asantaga commented 2 years ago

Hey , coincidentally Ive started seeing these errors too. I'll investigate

danielsmith89 commented 2 years ago

Great, thanks so much.

At the moment, my temporary fix is to keep restarting home assistant when it stops changing value.

danielsmith89 commented 2 years ago

Not sure how far you've managed to get, but I think it's related to having the HA LightwaveRF integration installed too for switches etc... As that has started playing up since I installed your plugin. I think they are both fighting to bind to that port so intermittently fail.

proffalken commented 2 years ago

Just did a quick check, I get this error even after removing the HA LightwaveRF integration, so I'm not sure that's the issue here.

This is a fresh installation via HACS onto a HA instance that's only been running for a few days.

It almost feels as if the first run isn't being killed off after the timeout and is hanging around for some reason, I can't see anything else in the HA code that would cause this :(

asantaga commented 2 years ago

sorry guys, been very busy at my end.. Alas my server is no longer receiving the udp packets. I need to get a new router...

Will get to the bottom of this at the end of the week when I have a new router

proffalken commented 2 years ago

Let me know if there's any debug stuff I can add to the code, happy to test it here if that would help?

asantaga commented 2 years ago

Code isnt very complex TBH, it just worked.. Alas we have a 10 month old which keeps me.. very busy.. (wife prefers I change nappies than code :--( boo hoo)

proffalken commented 2 years ago

Alas we have a 10 month old which keeps me.. very busy.. (wife prefers I change nappies than code :--( boo hoo)

We had some of those once, now they're teenagers, good luck!

I'll have a hack around, see what I can find :)

asantaga commented 2 years ago

Alas we have a 10 month old which keeps me.. very busy.. (wife prefers I change nappies than code :--( boo hoo)

We had some of those once, now they're teenagers, good luck!

I'll have a hack around, see what I can find :)

Im an old fart too, but boy sleep deprivation and a heavy work schedule.

proffalken commented 2 years ago

@asantaga I updated the code to close the socket after we're done (see above PR) and it now seems to behave as expected:

2021-08-07 05:58:38 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.electricity_current_usage_w is taking over 10 seconds
2021-08-07 05:58:38 ERROR (SyncWorker_0) [custom_components.lightwaverf_energy.sensor] No data received from lightwaveRF energy monitor timed out
2021-08-07 05:58:48 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.electricity_energy_today_usage_kwh is taking over 10 seconds
2021-08-07 05:58:48 ERROR (SyncWorker_1) [custom_components.lightwaverf_energy.sensor] No data received from lightwaveRF energy monitor timed out

I'm not getting any data, but I suspect that's an issue with my own setup rather than with the code as even a basic socket listener script doesn't collect any data from the hub!

asantaga commented 2 years ago

thanks I'll test this later this eve, my LWRF is also not sending data, not sure why.... Sigh

and thank you :-)