Skip to content

Commit 3298f09

Browse files
authored
Merge pull request #39 from eman/fix/temperature-conversion
Fix: Correct temperature conversion logic in models
2 parents ab93e01 + 08757e4 commit 3298f09

5 files changed

Lines changed: 248 additions & 125 deletions

File tree

docs/protocol/data_conversions.rst

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,25 @@ Raw Encoding Strategies
1818

1919
The device uses several encoding schemes to minimize transmission overhead:
2020

21-
1. **Offset Encoding** (add_20)
22-
- Applied to most temperature fields
23-
- Formula: ``displayed_value = raw_value + 20``
24-
- Purpose: Negative temperatures stored as positive integers
25-
- Range: Typically -4°F (-20°C) to 149°F (65°C)
26-
- Example: Raw 100 → 120°F display value
27-
28-
2. **Tenths Encoding** (div_10)
21+
1. **Half-degree Celsius to Fahrenheit** (HalfCelsiusToF)
22+
- Applied to most temperature fields that are not scaled by other factors.
23+
- Formula: ``displayed_value = (raw_value / 2.0) * 9/5 + 32``
24+
- Purpose: Converts raw values, which are in half-degrees Celsius, to Fahrenheit.
25+
- Example: Raw 122 -> (122 / 2) * 9/5 + 32 = 141.8°F
26+
27+
2. **Scaled Celsius to Fahrenheit** (PentaCelsiusToF)
28+
- Applied to refrigerant and evaporator temperatures.
29+
- Formula: ``displayed_value = (raw_value / 5.0) * 9/5 + 32``
30+
- Purpose: Converts raw values, which are scaled by a factor of 5, to Fahrenheit.
31+
- Example: Raw 250 -> (250 / 5) * 9/5 + 32 = 122°F
32+
33+
3. **Tenths Encoding** (div_10)
2934
- Applied to decimal precision values
3035
- Formula: ``displayed_value = raw_value / 10.0``
3136
- Purpose: Preserve decimal precision in integer storage
3237
- Common for flow rates and differential temperatures
3338
- Example: Raw 125 → 12.5 GPM
3439

35-
3. **Decicelsius to Fahrenheit** (decicelsius_to_f)
36-
- Applied to refrigerant and evaporator temperatures
37-
- Formula: ``displayed_value = (raw_value / 10) * 9/5 + 32``
38-
- Purpose: Convert Celsius tenths to Fahrenheit
39-
- Example: Raw 250 (25°C) → 77°F
40-
4140
4. **Boolean Encoding** (device_bool)
4241
- Applied to all status flags
4342
- Formula: ``displayed_value = (raw_value == 2)``
@@ -66,23 +65,23 @@ DHW (Domestic Hot Water) Temperatures
6665
- Display Unit
6766
- Description
6867
* - ``dhwTemperature``
69-
- add_20
68+
- HalfCelsiusToF
7069
- °F
7170
- **Current outlet temperature** of hot water being delivered to fixtures. Real-time measurement. Typically 90-150°F.
7271
* - ``dhwTemperature2``
73-
- add_20
72+
- HalfCelsiusToF
7473
- °F
7574
- **Secondary DHW temperature sensor** reading (redundancy/averaging). May differ slightly from primary sensor during temperature transitions.
7675
* - ``dhwTemperatureSetting``
77-
- add_20
76+
- HalfCelsiusToF
7877
- °F
7978
- **User-configured target temperature** for DHW delivery. Adjustable range: 95-150°F. Default: 120°F. This is the setpoint users configure in the app.
8079
* - ``currentInletTemperature``
8180
- div_10
8281
- °F
8382
- **Cold water inlet temperature** to the water heater. Affects heating performance and recovery time. Typically 40-80°F depending on season and location.
8483
* - ``dhwTargetTemperatureSetting``
85-
- add_20
84+
- HalfCelsiusToF
8685
- °F
8786
- **Duplicate of dhwTemperatureSetting** for legacy API compatibility.
8887

@@ -98,11 +97,11 @@ Tank Temperature Sensors
9897
- Display Unit
9998
- Description
10099
* - ``tankUpperTemperature``
101-
- decicelsius_to_f
100+
- PentaCelsiusToF
102101
- °F
103102
- **Upper tank sensor temperature**. Indicates stratification - hot water at top for quick delivery. Typically hottest point in tank.
104103
* - ``tankLowerTemperature``
105-
- decicelsius_to_f
104+
- PentaCelsiusToF
106105
- °F
107106
- **Lower tank sensor temperature**. Indicates bulk tank temperature and heating progress. Typically cooler than upper sensor.
108107

@@ -122,27 +121,27 @@ These temperatures monitor the heat pump refrigerant circuit health and performa
122121
- Display Unit
123122
- Description
124123
* - ``dischargeTemperature``
125-
- decicelsius_to_f
124+
- PentaCelsiusToF
126125
- °F
127126
- **Compressor discharge temperature**. Temperature of refrigerant exiting the compressor. Typically 120-180°F. High values indicate high system pressure; low values indicate efficiency issues.
128127
* - ``suctionTemperature``
129-
- decicelsius_to_f
128+
- PentaCelsiusToF
130129
- °F
131130
- **Compressor suction temperature**. Temperature of refrigerant entering the compressor. Typically 40-60°F. Affects superheat calculation.
132131
* - ``evaporatorTemperature``
133-
- decicelsius_to_f
132+
- PentaCelsiusToF
134133
- °F
135134
- **Evaporator coil temperature**. Where heat is extracted from ambient air. Typically 20-50°F. Lower outdoor air temperature reduces evaporator efficiency.
136135
* - ``ambientTemperature``
137-
- decicelsius_to_f
136+
- PentaCelsiusToF
138137
- °F
139138
- **Ambient air temperature** measured at heat pump inlet. Directly affects system performance. At freezing (32°F), heat pump efficiency drops significantly.
140139
* - ``targetSuperHeat``
141-
- decicelsius_to_f
140+
- PentaCelsiusToF
142141
- °F
143142
- **Target superheat setpoint**. Desired temperature difference between suction and evaporator ensuring complete refrigerant vaporization. Typically 10-20°F.
144143
* - ``currentSuperHeat``
145-
- decicelsius_to_f
144+
- PentaCelsiusToF
146145
- °F
147146
- **Measured superheat value**. Actual temperature difference. Deviation from target indicates EEV (Electronic Expansion Valve) control issues.
148147

@@ -166,19 +165,19 @@ Electric heating elements are controlled via thermostat ranges. Two sensors (upp
166165
- Display Unit
167166
- Description
168167
* - ``heUpperOnTempSetting``
169-
- add_20
168+
- HalfCelsiusToF
170169
- °F
171170
- **Upper element ON threshold**. Upper tank temp must fall below this to activate upper heating element.
172171
* - ``heUpperOffTempSetting``
173-
- add_20
172+
- HalfCelsiusToF
174173
- °F
175174
- **Upper element OFF threshold**. Upper tank temp rises above this to deactivate upper element (hysteresis).
176175
* - ``heLowerOnTempSetting``
177-
- add_20
176+
- HalfCelsiusToF
178177
- °F
179178
- **Lower element ON threshold**. Lower tank temp must fall below this to activate lower element.
180179
* - ``heLowerOffTempSetting``
181-
- add_20
180+
- HalfCelsiusToF
182181
- °F
183182
- **Lower element OFF threshold**. Lower tank temp rises above this to deactivate lower element.
184183
* - ``heUpperOnDiffTempSetting``
@@ -198,7 +197,7 @@ Electric heating elements are controlled via thermostat ranges. Two sensors (upp
198197
- °F
199198
- **Lower element differential** variation.
200199
* - ``heatMinOpTemperature``
201-
- add_20
200+
- HalfCelsiusToF
202201
- °F
203202
- **Minimum heat pump operation temperature**. Lowest tank temperature setpoint allowed in the current operating mode. Range: 95-113°F. Default: 95°F. When set, the user can only set the target tank temperature at or above this threshold, ensuring minimum system operating conditions.
204203

@@ -216,19 +215,19 @@ Heat pump stages are similarly controlled via thermostat ranges:
216215
- Display Unit
217216
- Description
218217
* - ``hpUpperOnTempSetting``
219-
- add_20
218+
- HalfCelsiusToF
220219
- °F
221220
- **Upper heat pump ON**. Upper tank falls below this to activate heat pump for upper tank heating.
222221
* - ``hpUpperOffTempSetting``
223-
- add_20
222+
- HalfCelsiusToF
224223
- °F
225224
- **Upper heat pump OFF**. Upper tank rises above this to stop upper tank heat pump operation.
226225
* - ``hpLowerOnTempSetting``
227-
- add_20
226+
- HalfCelsiusToF
228227
- °F
229228
- **Lower heat pump ON**. Lower tank falls below this to activate heat pump for lower tank heating.
230229
* - ``hpLowerOffTempSetting``
231-
- add_20
230+
- HalfCelsiusToF
232231
- °F
233232
- **Lower heat pump OFF**. Lower tank rises above this to stop lower tank heat pump operation.
234233
* - ``hpUpperOnDiffTempSetting``
@@ -264,15 +263,15 @@ Freeze Protection Temperatures
264263
- Boolean
265264
- **Freeze protection enabled flag**. When True, triggers anti-freeze operation below threshold.
266265
* - ``freezeProtectionTemperature``
267-
- add_20
266+
- HalfCelsiusToF
268267
- °F
269268
- **Freeze protection temperature setpoint**. Range: 43-50°F (6-10°C). Default: 43°F (6°C). When tank temperature drops below this, electric heating activates automatically to prevent freezing.
270269
* - ``freezeProtectionTempMin``
271-
- add_20
270+
- HalfCelsiusToF
272271
- °F
273272
- **Minimum freeze protection temperature limit** (lower boundary). Fixed at 43°F (6°C).
274273
* - ``freezeProtectionTempMax``
275-
- add_20
274+
- HalfCelsiusToF
276275
- °F
277276
- **Maximum freeze protection temperature limit** (upper boundary). Fixed at 50°F (10°C).
278277

@@ -290,18 +289,19 @@ For systems with recirculation pumps (optional feature):
290289
- Display Unit
291290
- Description
292291
* - ``recircTemperature``
293-
- add_20
292+
- HalfCelsiusToF
294293
- °F
295294
- **Recirculation loop current temperature**. Temperature of water being circulated back to tank.
296295
* - ``recircFaucetTemperature``
297-
- add_20
296+
- HalfCelsiusToF
298297
- °F
299298
- **Recirculation faucet outlet temperature**. How hot water is at the furthest fixture during recirculation.
300299
* - ``recircTempSetting``
301-
- add_20
300+
- HalfCelsiusToF
302301
- °F
303302
- **Recirculation target temperature**. What temperature to maintain in the recirculation line.
304303

304+
305305
Flow Rate Fields
306306
----------------
307307

@@ -613,8 +613,8 @@ Temperature Unit Notes
613613
* **Fahrenheit** conversions assume target display is °F as configured in the device
614614
* **Celsius calculations** can be derived by reversing the conversions:
615615

616-
- From ``add_20`` fields: ``celsius = (fahrenheit - 20) * 5/9``
617-
- From ``decicelsius_to_f`` fields: ``celsius = (fahrenheit - 32) * 5/9``
616+
- From ``HalfCelsiusToF`` fields: ``celsius = (fahrenheit - 32) * 5/9 * 2``
617+
- From ``PentaCelsiusToF`` fields: ``celsius = (fahrenheit - 32) * 5/9 * 5``
618618
- From ``div_10`` fields: ``celsius = value_celsius / 10.0``
619619

620620
* **Sensor Accuracy**: Typically ±2°F for tank sensors, ±3°F for refrigerant sensors

docs/protocol/device_status.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ This document lists the fields found in the ``status`` object of device status m
7777
- integer
7878
- °F
7979
- Current Domestic Hot Water (DHW) outlet temperature.
80-
- ``raw + 20``
80+
- HalfCelsiusToF
8181
* - ``dhwTemperatureSetting``
8282
- integer
8383
- °F
8484
- Target DHW temperature setting. Range: 95°F (35°C) to 150°F (65.5°C). Default: 120°F (49°C).
85-
- ``raw + 20``
85+
- HalfCelsiusToF
8686
* - ``programReservationUse``
8787
- bool
8888
- None
@@ -117,42 +117,42 @@ This document lists the fields found in the ``status`` object of device status m
117117
- integer
118118
- °F
119119
- The target DHW temperature setting (same as dhwTemperatureSetting).
120-
- ``raw + 20``
120+
- HalfCelsiusToF
121121
* - ``tankUpperTemperature``
122122
- integer
123123
- °F
124124
- Temperature of the upper part of the tank.
125-
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
125+
- PentaCelsiusToF
126126
* - ``tankLowerTemperature``
127127
- integer
128128
- °F
129129
- Temperature of the lower part of the tank.
130-
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
130+
- PentaCelsiusToF
131131
* - ``dischargeTemperature``
132132
- integer
133133
- °F
134134
- Compressor discharge temperature - temperature of refrigerant leaving the compressor.
135-
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
135+
- PentaCelsiusToF
136136
* - ``suctionTemperature``
137137
- integer
138138
- °F
139139
- Compressor suction temperature - temperature of refrigerant entering the compressor.
140-
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
140+
- PentaCelsiusToF
141141
* - ``evaporatorTemperature``
142142
- integer
143143
- °F
144144
- Evaporator temperature - temperature where heat is absorbed from ambient air.
145-
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
145+
- PentaCelsiusToF
146146
* - ``ambientTemperature``
147147
- integer
148148
- °F
149149
- Ambient air temperature measured at the heat pump air intake.
150-
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
150+
- PentaCelsiusToF
151151
* - ``targetSuperHeat``
152152
- integer
153153
- °F
154154
- Target superheat value - the desired temperature difference ensuring complete refrigerant vaporization.
155-
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
155+
- PentaCelsiusToF
156156
* - ``compUse``
157157
- bool
158158
- None
@@ -212,7 +212,7 @@ This document lists the fields found in the ``status`` object of device status m
212212
- integer
213213
- °F
214214
- Freeze protection temperature setpoint. Range: 43-50°F (6-10°C), Default: 43°F. When tank temperature drops below this, electric heating activates automatically to prevent freezing.
215-
- ``raw + 20``
215+
- HalfCelsiusToF
216216
* - ``antiLegionellaUse``
217217
- bool
218218
- None
@@ -287,7 +287,7 @@ This document lists the fields found in the ``status`` object of device status m
287287
- integer
288288
- °F
289289
- Second DHW temperature reading.
290-
- ``raw + 20``
290+
- HalfCelsiusToF
291291
* - ``currentDhwFlowRate``
292292
- float
293293
- GPM
@@ -307,7 +307,7 @@ This document lists the fields found in the ``status`` object of device status m
307307
- integer
308308
- °F
309309
- Current superheat value - actual temperature difference between suction and evaporator temperatures.
310-
- ``(raw / 10) * 9/5 + 32`` (decicelsius to Fahrenheit)
310+
- PentaCelsiusToF
311311
* - ``heatUpperUse``
312312
- bool
313313
- None
@@ -357,42 +357,42 @@ This document lists the fields found in the ``status`` object of device status m
357357
- integer
358358
- °F
359359
- Heat pump upper on temperature setting.
360-
- ``raw + 20``
360+
- HalfCelsiusToF
361361
* - ``hpUpperOffTempSetting``
362362
- integer
363363
- °F
364364
- Heat pump upper off temperature setting.
365-
- ``raw + 20``
365+
- HalfCelsiusToF
366366
* - ``hpLowerOnTempSetting``
367367
- integer
368368
- °F
369369
- Heat pump lower on temperature setting.
370-
- ``raw + 20``
370+
- HalfCelsiusToF
371371
* - ``hpLowerOffTempSetting``
372372
- integer
373373
- °F
374374
- Heat pump lower off temperature setting.
375-
- ``raw + 20``
375+
- HalfCelsiusToF
376376
* - ``heUpperOnTempSetting``
377377
- integer
378378
- °F
379379
- Heater element upper on temperature setting.
380-
- ``raw + 20``
380+
- HalfCelsiusToF
381381
* - ``heUpperOffTempSetting``
382382
- integer
383383
- °F
384384
- Heater element upper off temperature setting.
385-
- ``raw + 20``
385+
- HalfCelsiusToF
386386
* - ``heLowerOnTempSetting``
387387
- integer
388388
- °F
389389
- Heater element lower on temperature setting.
390-
- ``raw + 20``
390+
- HalfCelsiusToF
391391
* - ``heLowerOffTempSetting``
392392
- integer
393393
- °F
394394
- Heater element lower off temperature setting.
395-
- ``raw + 20``
395+
- HalfCelsiusToF
396396
* - ``hpUpperOnDiffTempSetting``
397397
- float
398398
- °F
@@ -437,7 +437,7 @@ This document lists the fields found in the ``status`` object of device status m
437437
- float
438438
- °F
439439
- Minimum heat pump operation temperature. Lowest tank temperature setpoint allowed in the current operating mode (95-113°F, default 95°F). When set, users can only set the target tank temperature at or above this threshold.
440-
- ``raw + 20``
440+
- HalfCelsiusToF
441441
* - ``drOverrideStatus``
442442
- integer
443443
- None
@@ -730,7 +730,7 @@ Technical Notes
730730

731731
* Tank temperature sensors operate within -4°F to 149°F (-20°C to 65°C)
732732
* Outside normal range, system may operate with reduced capacity using opposite heating element
733-
* All tank temperature readings use conversion formula: ``display_temp = raw + 20``
733+
734734

735735
**Heating Elements:**
736736

0 commit comments

Comments
 (0)