-
Notifications
You must be signed in to change notification settings - Fork 96
Energy sensor stops updating for days (F454 gateway - command session connection reset loop) #209
Description
hallo,
Description
The energy sensor (sensor.energia_51_energia_51_energy) stops updating for several days at a time. The sensor never goes unavailable — it just freezes at the last known value. When it finally resumes (after a manual reload or integration restart), it dumps all accumulated energy as a single spike, making the Home Assistant Energy Dashboard completely unreliable.
Environment
- Integration version: 0.9.3
- Gateway: BTicino F454
- Home Assistant version: Core 2026.3.2 , Supervisor 2026.03.2
- Installation type: HACS custom integration
Steps to reproduce
- Let Home Assistant run for several days without restarting
- Observe the energy sensor — it will stop incrementing after a variable period (typically overnight)
- Check the History panel — the sensor value is flat for days, then jumps with a large spike when it resumes
Root cause (identified via debug logs)
With custom_components.myhome: debug enabled, the logs clearly show that 5 simultaneous command sessions are opened to the F454 gateway. The gateway periodically resets all of them at the same time (exactly every 60 seconds):
2026-03-22 14:32:01.512 DEBUG [custom_components.myhome] [F454 gateway - 192.168.1.35] Command session connection reset, retrying...
2026-03-22 14:32:01.514 DEBUG [custom_components.myhome] [F454 gateway - 192.168.1.35] Command session connection reset, retrying...
2026-03-22 14:32:01.516 DEBUG [custom_components.myhome] [F454 gateway - 192.168.1.35] Command session connection reset, retrying...
2026-03-22 14:32:01.519 DEBUG [custom_components.myhome] [F454 gateway - 192.168.1.35] Command session connection reset, retrying...
2026-03-22 14:32:01.522 DEBUG [custom_components.myhome] [F454 gateway - 192.168.1.35] Command session connection reset, retrying...
This pattern repeats every minute. The F454 has a very low limit on simultaneous connections and appears to forcefully reset them all when overloaded. Most of the time the integration reconnects successfully, but occasionally — especially at night when other activity is low — the energy sensor fails to resume updates after the reset.
After the reset, the integration does reconnect (as seen in logs):
2026-03-22 14:32:01.530 DEBUG [custom_components.myhome] Command session connection reset, retrying...
2026-03-22 14:32:01.534 DEBUG [custom_components.myhome] Opening command session.
2026-03-22 14:32:01.540 DEBUG [custom_components.myhome] Negotiating command session.
2026-03-22 14:32:01.550 DEBUG [custom_components.myhome] Command session established.
But the energy polling does not always resume correctly after reconnection.
Impact
- Energy sensor frozen for 4-5 days at a time
- Large energy spikes on resume (e.g. 50+ kWh in a single bar) in the Energy Dashboard
- Energy Dashboard data is completely unreliable
Workaround
A Home Assistant automation that reloads the config entry if the sensor has not changed for 12 hours:
triggers:
- trigger: time_pattern
hours: /1
conditions:
- condition: template
value_template: >
{{ (now().timestamp() - as_timestamp(states.sensor.energia_51_energia_51_energy.last_changed)) > 43200 }}
actions:
- action: homeassistant.reload_config_entry
target:
entity_id: sensor.energia_51_energia_51_energy
mode: singleThis restores updates but does not fix the root cause.
########
Code analysis (OWNd library)
After reviewing the OWNd source code (connection.py), the root cause is clearer:
1. Multiple parallel sessions
The integration opens 5 simultaneous OWNCommandSession instances toward the F454.
The gateway has a low connection limit and resets all of them simultaneously every ~60 seconds.
2. 60 second reconnect delay
In OWNSession.connect(), when a ConnectionResetError is caught, the library waits exactly 60 seconds before retrying:
except ConnectionResetError:
await asyncio.sleep(60)
retry_count += 1This matches exactly what is observed in the logs — connection resets every 60 seconds.
3. No resume guarantee for energy polling
After reconnection, the energy polling does not always resume correctly,
causing the sensor to freeze indefinitely until a full integration reload.