Skip to content

RetrieveHass freq parameter not normalised to pd.Timedelta causing AttributeError in Docker Standalone deployments #728

@rossco555

Description

@rossco555

Please forgive me, this is above my head and below was generated by Claude following investigations into my issues. I believe it is a bug, but I'm largely trusting Claude for that.

Describe the bug
_process_history_dataframe in retrieve_hass.py calls self.freq.seconds but self.freq is passed as an integer (the optimization_time_step value from config, e.g. 30) rather than a pd.Timedelta object. This causes AttributeError: 'int' object has no attribute 'seconds' which is silently caught upstream and misreported as "The retrieved JSON is empty, A sensor may have 0 days of history".

Additionally, when a pd.Timedelta object is passed, recent versions of pandas have removed the .nanos attribute, causing a further AttributeError: 'Timedelta' object has no attribute 'nanos'.

To Reproduce

  1. Install EMHASS as Docker standalone container
  2. Set optimization_time_step: 30 in config (integer, as documented)
  3. Run dayahead-optim or forecast-model-fit
  4. Observe misleading "empty JSON" error in logs

Expected behavior
RetrieveHass.__init__ should normalise the freq parameter to pd.Timedelta regardless of input type. Suggested fix:

if isinstance(freq, (int, float)):
    self.freq = pd.Timedelta(minutes=int(freq))
else:
    self.freq = freq

This ensures self.freq is always a pd.Timedelta throughout the class. Any subsequent use of .seconds will then work correctly without needing to handle multiple types downstream.

Home Assistant installation type

  • Home Assistant OS (running in Docker on Synology NAS)

Your hardware

  • OS: Linux (Synology DSM)
  • Architecture: amd64

EMHASS installation type

  • Docker Standalone (separate container, connecting to HA via host.docker.internal)

Additional context
The type hint on RetrieveHass.__init__ correctly specifies freq: pd.Timedelta but the caller in command_line.py passes retrieve_hass_conf["optimization_time_step"] which is a raw integer. The fix belongs in __init__ to normalise at the boundary rather than patching each usage site.

Note: pd.Timedelta.nanos has been removed in recent pandas versions. Use pd.Timedelta.seconds or int(pd.Timedelta(minutes=x).total_seconds()) for portable code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions