Cache and Retry Mechanism - HAEdwin/homeassistant-apsystems_ecu_reader GitHub Wiki

The APsystems ECU Reader integration implements a sophisticated cache and retry system to ensure reliable data delivery even when communication with the ECU is temporarily disrupted. This document explains how these features work and how to interpret related sensors.

Communication Process

Under normal operation, the integration polls the APsystems ECU on a regular interval (configurable during setup). However, ECU devices can sometimes be unresponsive due to:

  • Network connectivity issues
  • High load on the ECU
  • Internal ECU processes (like data logging)
  • Firmware updates
  • Other temporary issues

Retry Mechanism

When the integration fails to get a response from the ECU, it follows this process:

  1. Initial Failure: The integration attempts to reconnect immediately
  2. Subsequent Failures: The integration follows an exponential backoff strategy:
    • First retry: Almost immediately
    • Second retry: Short delay (a few seconds)
    • Third and subsequent retries: Increasingly longer delays

This approach prevents network congestion while still attempting to restore communication in a timely manner.

Cache System

The integration maintains a local cache of the last successfully retrieved data. This allows Home Assistant to continue displaying solar production information even during communication outages.

How Caching Works

  1. On successful communication with the ECU, data is stored in the integration's cache
  2. If communication fails, the integration serves the cached data
  3. Cached data is marked with a timestamp to indicate its age
  4. The binary sensor binary_sensor.using_cached_data indicates when cached data is being used

Cache Counter

The integration provides a diagnostic sensor sensor.using_cache_counter that shows how many consecutive times cached data has been used. This counter:

  • Increments with each failed communication attempt
  • Resets to zero when communication is successful
  • Can help diagnose persistent connectivity issues

Diagnostic Entities

Entity Type Description
binary_sensor.using_cached_data Binary Sensor ON when using cached data, OFF when using fresh data
sensor.using_cache_counter Sensor Number of consecutive failed communications

Best Practices

  1. Monitor the cache counter: A steadily increasing counter indicates ongoing communication problems
  2. Check network connectivity: If cached data is frequently used, verify the network connection between Home Assistant and the ECU
  3. ECU placement: Ensure your ECU has good Wi-Fi signal or a reliable wired connection
  4. Consider adjusting poll interval: If communication issues persist, increasing the poll interval may help reduce load on the ECU

Notes

  • The cache system ensures your energy production data remains available in Home Assistant dashboards even during temporary outages
  • Historical data integrity is maintained because the ECU itself stores detailed production data that is retrieved once communication is restored
  • Energy sensors (today's production, lifetime energy) will maintain their values during outages, while power sensors will show the last known values with the "using cached data" indicator

When the binary_sensor.using_cached_data sensor is ON for extended periods, check your network configuration and ECU status. You might have to restart the ECU using an automation and a smart plug (2160). On the ECU-C and ECU-R-Pro restart is automatically initiated by the integration.