Skip to content

feat(steam_ac): Add historical entities#637

Open
dgibbs64 wants to merge 98 commits into
tolwi:mainfrom
dgibbs64:feat/missing-entities
Open

feat(steam_ac): Add historical entities#637
dgibbs64 wants to merge 98 commits into
tolwi:mainfrom
dgibbs64:feat/missing-entities

Conversation

@dgibbs64
Copy link
Copy Markdown

@dgibbs64 dgibbs64 commented Dec 10, 2025

This PR adds missing historical entities for Stream AC devices, as well as updated icons and renamed entities to be more consistent and group better.

The Following Entities have been added:

HIST_CODE_ENERGY_INDEPENDENCE

  • Energy Independence (Today) - energy_independence_today
  • Energy Independence (Yearly) - energy_independence_yearly

HIST_CODE_ENV_IMPACT

  • Environmental Impact (Today) - environmental_impact_today
  • Environmental Impact (Cumulative) - environmental_impact_cumulative

HIST_CODE_SAVINGS_TOTAL
Note: This entity has issues selecting the currency unit displayed in the API. It will display as Euro only. I have added an attribute to show the currency unit returned by the API. If anyone knows how to sort this that would be great.

  • Solar Energy Savings (Today) - solar_energy_savings_today
  • Solar Energy Savings (Cumulative) - solar_energy_savings_cumulative

HIST_CODE_SOLAR_GENERATED

  • Solar-Generated Energy (Today) - solar_generated_energy_today
  • Solar-Generated Energy (Cumulative) - solar_generated_energy_cumulative

HIST_CODE_ELECTRICITY_CONS

  • Electricity Consumption (Today) - electricity_consumption_today
  • Electricity Consumption (Cumulative) - electricity_consumption_cumulative

HIST_CODE_GRID
(Data that comes from the shelly device into ecoflow app)

  • Grid Export - grid_export_today
  • Grid Export Cumulative - grid_export_cumulative
  • Grid Import - grid_import_today
  • Grid Import Cumulative - grid_import_cumulative

HIST_CODE_BATTERY

  • Battery Charge (Today) -battery_charge_today
  • Battery Charge (Cumulative) -battery_charge_cumulative
  • Battery Discharge (Today) - battery_discharge_today
  • Battery Discharge (Cumulative) - battery_discharge_cumulative

Renamed the following to create a more consistent naming convention and allow related entities to better group together,

  • In Power > Input Power
  • Out Power > Output Power
  • Cumulative Capacity Charge (mAh) > Capacity Charge (Cumulative)
  • Cumulative Energy Charge (Wh) > Energy Charge (Cumulative)
  • Cumulative Capacity Discharge (mAh) > Capacity Discharge (Cumulative)
  • Cumulative Energy Discharge (Wh) > Energy Discharge (Cumulative)
  • Slave %i Cumulative Capacity Charge (mAh) > Slave %i Capacity Charge (Cumulative)
  • Slave %i Cumulative Energy Charge (Wh) > Slave %i Energy Charge (Cumulative)
  • Slave %i Cumulative Capacity Discharge (mAh) > Slave %i Capacity Discharge (Cumulative)
  • Slave %i Cumulative Energy Discharge (Wh) > Slave %i Energy Discharge (Cumulative)

*Cumulative entities set the api date from when EcoFlow came into business to ensure the data comes from a device install date.

Note: This PR was built with assistance from Copilot. I have completed multiple passes of the code and tested fully in a dev and live HA instance.

Hope this PR helps 😄

Adds an icon to the Solar Generated energy sensor for better visual representation in the user interface.
Adds a sensor to track the cumulative solar energy generated since May 2017.
This provides a long-term overview of solar energy production.
The implementation ignores errors during data retrieval to prevent other sensor updates from being blocked.
Adds a sensor to track the cumulative environmental impact (in grams) since May 2017, providing a more comprehensive view of long-term environmental benefits.

Also renames the cumulative solar generated sensor for clarity.
Improves the user interface by adding appropriate icons to
energy sensors for grid import/export and battery charge/discharge,
enhancing visual clarity and ease of understanding.
Adds icons to improve the visual representation of several sensors, including remaining time, state of health, and environmental impact.
This provides a more intuitive understanding of the data being displayed.
Adds icons to several sensor entities for better visualization in Home Assistant.
Renames ambiguous sensor names for clarity.
Shortens the offline barrier for historical data status updates, improving responsiveness.
Adds support for dynamic currency units for solar savings.
Removes duplicated charge remaining time sensor.
Adds historical data sensors for stream AC devices.

These sensors provide insights into energy independence,
environmental impact, solar energy savings, and energy consumption.
This allows users to monitor their energy usage and savings over time.
Adds missing historical data sensors for stream series devices.

These sensors provide insights into energy independence, environmental impact, solar savings, and energy consumption.
The constants are moved to a more appropriate location.
Adds several missing sensors to the Stream AC device, providing more
comprehensive data for energy monitoring and device status. This includes
various power, capacity, temperature, voltage and historical data sensors.
Simplifies the sensor declarations for Stream AC devices by removing unnecessary line breaks and improving readability.
This change enhances the maintainability of the code without altering its functionality.
Adds constants for various device features and data points,
including DC charge current options, main/fan/remote mode options,
power sub-mode options, and smart meter/stream series data fields.
This ensures that all available entities are properly defined
and accessible within the EcoFlow integration.
Adds definitions for smart meter entities and other previously missing entities.

This ensures that the integration can now properly display and control these
additional device features, providing a more complete user experience.
Renames environmental impact history entities and removes redundant "Wh" suffixes from solar and other energy history entity names for clarity and consistency.
Adds the missing "Energy Independence" sensor with its unit.

Updates the labels for total input and output power to be more
accurate and renames "Environmental Impact" to "Environmental
Impact Today" to better reflect the data it shows.
Adds missing energy sensor entities for the Stream AC device, including solar generation, electricity consumption, grid import/export, and battery charge/discharge.

Updates energy entity names to be more generic.
Adds immediate historical data fetching on entity add
to ensure data is available when other entities render.

Fixes dynamic currency updates to use a fixed Euro unit
and expose currency symbol via attribute. This simplifies
the logic and avoids potential errors.
Adds daily, weekly, monthly, and yearly energy independence
sensors, and cumulative environmental impact sensors.
The code retrieves historical data from the Ecoflow API
and populates the corresponding Home Assistant sensors.
Adds cumulative totals for environmental impact, solar savings, solar generation, electricity consumption, grid import/export, and battery charge/discharge.

Adds daily energy independence and consumption metrics.
These changes enhance the energy monitoring capabilities.
Adds missing energy and environmental entities to the EcoFlow integration.

Renames some existing entities for clarity and consistency.
Adds daily and cumulative values for solar energy savings, grid import/export, and battery charge/discharge.
Includes environmental impact entities.
Updates the solar power icons to use "mdi:solar-panel" for better clarity. This improves the visual representation of solar power entities within the user interface.
Deletes the apidocs.txt file.
The file is no longer needed in the repository.
Adds missing energy history sensors to the EcoFlow integration, including daily values for battery charge/discharge, electricity consumption, energy independence, environmental impact, grid import/export, solar generated energy, and solar energy savings.

This provides a more complete view of energy usage and savings.
Removes the retrieval of environmental impact aggregates for yesterday, week, month, and year to reduce unnecessary API calls and declutter the sensor data.

Keeps cumulative environmental impact data.
Removes the unit of measurement "mAh" from the remaining capacity sensor, as it's already implied by the sensor's name and attributes.
Corrects the type hint for the `selects` method in the StreamAC class to accurately reflect its return type. This ensures type safety and improves code maintainability.
Removes the DynamicCurrencySensorEntity and uses BaseSensorEntity with a fixed Euro currency.
This simplifies the code and avoids the need for dynamic unit updates.
The currency unit is now fixed, and the actual symbol is exposed as an attribute.
The label for energy independence yearly sensor
was corrected to match what is shown in the app.
Also cleans up the historical data pull for declutter
and reduce API calls.
Updates historical data status retrieval to only retrieve environmental impact and solar energy savings, streamlining the process and focusing on cumulative and daily data.
Also corrects a typo in a comment.
Removes unused imports to improve code cleanliness and reduce potential conflicts.
Addresses potential issues with StreamAC history updates by ensuring the history coordinator exists before attempting to refresh it.

Adds a type ignore comment for mypy to correctly handle the post_api call.

Adds type hint for _background_tasks.
Updates the type hint for the `disconnect_flags_or_rc` parameter in the `EcoflowMQTTClient.on_disconnect` method to allow `None`.
This prevents type errors when the parameter is not provided.

Removes a superfluous type ignore statement in stream_ac.py.
@dgibbs64
Copy link
Copy Markdown
Author

dgibbs64 commented Dec 30, 2025

@tolwi I believe this should now be up to standard (hopefully). All the entities work now, and I even got the currency unit working. I have formatted the files with ruff and got some passes on the linting. Please let me know if anything else needs sorting out or feel free to amend as needed to get it over the line and merged.

The only other thing to mention is that these new historical entities are based on a "Space" that can incorporate all devices in that space and cumulatively add them together. I am not sure of a way to make this clearer to the end user, however.

edit: one of the linting tasks looks to have broken the historic data refresh. I am determined to get this over the line.

Addresses potential errors during history coordinator setup and cleanup.

Ensures proper handling of background tasks and prevents issues during component unload.

Changes state class of historical sensors to TOTAL.
Updates VS Code extension recommendations to include Prettier.

This ensures consistent code formatting across the project, improving readability and maintainability.
Ensures the energy sensor entity correctly updates its value by calling the base class's update method directly. This resolves a potential inheritance issue and ensures proper sensor value updates.
Improves the robustness of fetching historical data for stream AC devices by adding exception handling for individual metric fetches.

It also updates the Ecoflow client to handle cases where the historical data API is accessed via different client capabilities. A fallback mechanism ensures compatibility with older clients.

Adds last history check markers so entities can reliably show "last checked" status, even if specific metric calls fail.
Separates precise battery SOC value to new entity.
The original SOC value is now mapped to the non-precise
value (integer), while the more precise float value is mapped to
the new "...(Precise)" entity.

This makes it possible to differentiate and use both
values in Home Assistant automations.
Reduces unnecessary entity updates by comparing incoming data before applying changes, preventing redundant processing.
This change optimizes the update coordinator to suppress updates when data is unchanged, reducing CPU load.
It also addresses potential issues with Stream AC history updates and ensures sensors reset to default values when the device is offline.
@dgibbs64
Copy link
Copy Markdown
Author

dgibbs64 commented Jan 9, 2026

@tolwi I have had a good crack at this with my very limited knowledge. I have been using it live for a few days now and seems pretty good. It would be great if you could take a look and tidy up anything you think needs doing to get it merged. If you don't have a stream series, I give you access to my api key for testing if that helps 😄

@TelosNox
Copy link
Copy Markdown

TelosNox commented Feb 9, 2026

This request is stuck for a month now. Is there anything we can do to help with approval? Only reason to use the EF app currently is the missing historic data. So this will help a lot, especially with that bug that makes api non responsive when EF app is opened.

Removes the KiloWattHourEnergySensorEntity and uses EnergySensorEntity directly,
changing the unit of measurement to Wh. This simplifies the sensor
implementation and avoids unnecessary conversion.
Fixes an issue in Stream AC historical battery metrics where charge and discharge values were incorrectly assigned due to reversed `extra` values.

Observed in the EcoFlow app, `extra="1"` signifies charging and `extra="2"` signifies discharging, which was the opposite of what was previously implemented.
Merged AC, PRO, ULTRA into one "Stream Battery" as they are not different and is just confusing for the end user
Enhances device type identification during configuration.

Prioritizes API-reported device types, falling back to name-based
heuristics when necessary, especially when the API returns "undefined".
Also probes the device via /device/quota/all to further determine the device type based on available identifiers.

Avoids displaying "(undefined)" in device labels and allows users
to select a device type, even if the integration cannot infer it.

This addresses issues where the integration couldn't accurately
determine device types, especially for "Stream" devices.
Ensures data update coordinator detects updates
even when the holder object identity is stable.

This allows for a periodic status sensor update.
@dgibbs64
Copy link
Copy Markdown
Author

looks like @tolwi is working on a version of the historic entities that will probably be much better than what I was able to bodge together 😄.

@tolwi feel free to pick out anything you need from this PR. I have added a few fixes that seem to help with the entity stalling issue and help with device type detection. You will definitely do a much better cleaner job than I did but hopefully this PR might give you a few ideas to help. I look forward to seeing your output. Thanks 😃

@dgibbs64 dgibbs64 force-pushed the feat/missing-entities branch from aeb6c22 to 9c7503a Compare April 9, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants