Energy dashboard: support cost tracking (entity/static price) for external statistics #3187
Unanswered
loganrosen
asked this question in
Core functionality
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
When an energy source uses an external statistic (e.g., from Opower —
opower:cned_elec_xxx_energy_consumption), the energy dashboard's "Use an entity with current price" and "Use a static price" options are disabled in the frontend. Users cannot set up cost tracking for any integration that provides external statistics rather than regular entities.This affects every Opower user whose utility doesn't provide cost data through the API — ConEd, National Grid, PECO, and others. See core#108551 (48 comments, 10 👍, open since Jan 2024) and this community forum thread.
Why it happens
EnergyCostSensorinhomeassistant/components/energy/sensor.pyis built around real-time entity state tracking:_process_sensor_data()callsvalid_entity_id(stat_energy)— this rejects external statistic IDs (which use:instead of.), so cost sensors are never created._update_cost()callshass.states.get()andasync_track_state_change_event()on the energy source — neither works for external statistics since they don't live in the state machine.The frontend disables the price options to match this backend limitation (
dialog-energy-grid-settings.ts).Secondary issue: WebSocket API allows invalid configuration silently
The
energy/save_prefsWebSocket API acceptsentity_energy_pricealongside an external statistic without any validation:energy/inforeturnscost_sensors: {}with no explanationThis creates a silent failure pit for anyone using the API directly. This issue is tracked in home-assistant/core#165581.
Proposed solution
Support cost calculation for external statistics. The cost sensor would need a statistics-based update path rather than entity state tracking:
get_last_statistics()periodically (e.g., hourly, matching typical external stat update frequency) instead of relying on state change eventsvalid_entity_id()gate in_process_sensor_datadisabledflag on price radio buttons for external statistics in the frontendAs a smaller complementary fix,
energy/save_prefsshould validate thatentity_energy_price/number_energy_pricearen't set whenstat_energy_fromis an external statistic, or at least log a warning — matching the frontend's existing behavior.Related
Beta Was this translation helpful? Give feedback.
All reactions