arduino-heatpumpir icon indicating copy to clipboard operation
arduino-heatpumpir copied to clipboard

Min and Max Temperature coding error

Open Nateonas opened this issue 9 months ago • 0 comments

Today I set my Mishubishi Heavy Heatpump to cooling at 17C. In stead of cooling it started heating to 30C. What happened!?

I did a code-review on MitsubishiHeavyHeatpumpIR.cpp and found:

uint8_t temperature = 23; ... if ( temperatureCmd > 17 && temperatureCmd < 31) { temperature = (~((temperatureCmd - 17) << 4)) & 0xF0; }

I believe this is incorrect: temperature is binary operated, but ONLY if it meets the conditions >17 and <31. Otherwise it just remains 23 (B00010111 in stead of B01100000)! Later on, when operating byte 9, the (unadjusted) temperature is controlling operatingMode and powerMode: ... MitsubishiHeavyZJTemplate[9] |= operatingMode | powerMode | temperature; ...

This should be corrected, for example:

uint8_t temperature = ( ~ ((23 - 17) << 4)) & 0xF0; // default for 23C = B01100000 ... // temperature must be between 18 and 30 degrees if ( temperatureCmd < 18) { temperatureCmd = 18; } if (temperatureCmd > 30) { temperatureCmd = 30; } temperature = (~((temperatureCmd - 17) << 4)) & 0xF0;

I see this error not only with Mitsubishi heavy and also in other xxx-heatpumpIR sources! I currently don't have a development environment set up, so I log the error here for reference. The workaround is to prevent sending temperature-commands below 18C or over 30C.

Nateonas avatar May 05 '24 11:05 Nateonas