rstrouse / ESPSomfy-RTS-HA

Control your somfy shades in Home Assistant
The Unlicense
125 stars 9 forks source link

Excessive Load Caused by Frequent WebSocket Updates in Home Assistant Integration #71

Closed Jezza34000 closed 2 months ago

Jezza34000 commented 3 months ago

Hi @rstrouse,

The integration uses a WebSocket to send information. I've observed that the WebSocket sends up to 3 updates per second, (Free Memory, Max Memory, Min Memory, Wifi Strenngth) which leads to constant updates in Home Assistant. This behavior occurs even when the sensors are disabled. This cause excessive load on the Home Assistant system & unnecessary updates when the sensors are disabled.

I propose two solutions to address this issue:

1- Rewriting the code: I volunteer to rewrite this part of the code to optimize it and prevent HA core update calls if the sensors are disabled ?

2- Reducing Update Frequency: I suggest that you, as the firmware creator, reduce the update frequency of this information directly in the ESPSomfyRTS firmware. An update frequency of every 15 seconds seems sufficiently frequent ?

Let me know if you're interessted for proposal 1 :-)

chemelli74 commented 3 months ago

Interesting analysis, thx for the detailed infos.

I think that both should be done to make component robust and performant.

Jezza34000 commented 3 months ago

I agree the 2 points must be done to obtain optimal operation :+1:

rstrouse commented 3 months ago

I have already been on this due to the way recorder records these values. It is not the socket that this the problem or even that HA is showing the value in the interface. It is the recording of the statistics. Every attribute change is persisted to statistics so unfortunately, things like real time diagnostic values are a bit of a challenge on this platform. I have employed median smoothing for the values in HA and the next firmware release already has code that limits the output on integration sockets.

If you pull the code from the main branch the median smoothing is already in effect.

rstrouse commented 3 months ago

If you install the v2.4.5 pre-release of the firmware the socket limits emits to changes >= 1.5k. It also reduces the emit to 15 seconds when not trending and 7 seconds when trending. Typical updates range from 30 seconds to 5 minutes with the new firmware and integration.

rstrouse commented 3 months ago

I posted a release for the HA component and will be posting a firmware release shortly.

rstrouse commented 3 months ago

Firmware and Integration have been released.

rstrouse commented 2 months ago

I am going to close this for now as the plugin now performs median smoothing for the state data.