Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 8, 2025

Problem

The Heat Pump dashboard was displaying incorrect energy consumption values with electrical energy showing as much higher than thermal energy, when the opposite should be true for a heat pump with a COP (Coefficient of Performance) of 3-5.

As shown in the issue screenshot, the blue bars (Electrical Energy) were significantly taller than the orange bars (Thermal Energy), which is physically incorrect for a heat pump system where thermal output should be 3-5 times the electrical input.

Root Cause

The sensors passed to the useOptimizedCOPData hook had their roles reversed in the actual hardware/database configuration:

  • The sensor ID passed as electricalSensorId was actually measuring thermal output (heat produced by the heat pump)
  • The sensor ID passed as thermalSensorId was actually measuring electrical input (power consumed by the heat pump)

This mismatch between the semantic sensor names and their actual measurements caused:

  • Energy consumption chart showing inverted values
  • COP calculations being inverted (showing <1 instead of 3-5)
  • Total energy summaries being incorrectly labeled

Solution

Modified frontend/src/pages/HeatPump/hooks/useOptimizedCOPData.tsx to swap which sensor ID is used for which calculation:

// Before: Used sensor IDs as labeled
getReadingsAround({ sensorId: electricalSensorId, ... })  // For electrical calculations
getReadingsAround({ sensorId: thermalSensorId, ... })     // For thermal calculations

// After: Swapped to match actual sensor data
getReadingsAround({ sensorId: thermalSensorId, ... })     // For electrical calculations
getReadingsAround({ sensorId: electricalSensorId, ... })  // For thermal calculations

This corrects the data flow so that:

  • The sensor containing thermal data is now used for electrical energy calculations
  • The sensor containing electrical data is now used for thermal energy calculations

Expected Results

After this fix:

  • ✅ Thermal energy bars will be 3-5x taller than electrical energy bars (correct for COP of 3-5)
  • ✅ COP calculations will show realistic values (3-5 instead of <1)
  • ✅ Energy consumption values will be correctly labeled and proportional
  • ✅ Performance summary totals will reflect accurate energy usage

Files Changed

  • frontend/src/pages/HeatPump/hooks/useOptimizedCOPData.tsx - Swapped sensor ID usage in GraphQL queries (10 lines)
  • docs/bugfix-cop-calculation.md - Added comprehensive documentation of the bug and fix

Fixes issue showing incorrectly high energy consumption in COP calculation.

Original prompt

This section details on the original issue you should resolve

<issue_title>BUG: COP calculation is broken.</issue_title>
<issue_description>Image

Comutation is incorrect. Energy consumption is calculated way to high.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #19

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits October 8, 2025 12:30
The sensors were being used in reverse - the sensor labeled as "electrical"
was actually measuring thermal energy output, and vice versa. This caused:
- Energy consumption bars to show incorrectly high values (showing thermal as electrical)
- COP calculations to be inverted (showing < 1 instead of 3-5)

The fix swaps which sensor ID is used for electrical vs thermal calculations
in useOptimizedCOPData hook.

Co-authored-by: intui <15924901+intui@users.noreply.github.com>
Previous commit had the variable names reordered which canceled out the swap.
This commit properly swaps which sensor ID is used for which calculation:
- thermalSensorId data is now used for electricalEnergy calculation
- electricalSensorId data is now used for thermalEnergy calculation

This fixes the issue where electrical bars were showing as much higher than
thermal bars (should be opposite for a heat pump with COP > 1).

Co-authored-by: intui <15924901+intui@users.noreply.github.com>
Co-authored-by: intui <15924901+intui@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix calculation error in COP computation Fix: Swap sensor IDs in COP calculation due to mislabeled sensors Oct 8, 2025
Copilot AI requested a review from intui October 8, 2025 12:34
Copilot finished work on behalf of intui October 8, 2025 12:35
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.

BUG: COP calculation is broken.

2 participants