diff --git a/src/mitsubishi2mqtt/mitsubishi2mqtt.ino b/src/mitsubishi2mqtt/mitsubishi2mqtt.ino index 07aa1c7..eff7937 100644 --- a/src/mitsubishi2mqtt/mitsubishi2mqtt.ino +++ b/src/mitsubishi2mqtt/mitsubishi2mqtt.ino @@ -33,6 +33,8 @@ ESP8266WebServer server(80); // ESP8266 web #include // MQTT: PubSubClient 2.8.0 #include // DNS for captive portal #include // for rounding to Fahrenheit values +#include +#include // For roundf function #include // for OTA #include // SwiCago library: https://github.com/SwiCago/HeatPump @@ -747,7 +749,7 @@ void handleUnit() { if (!checkLogin()) return; if (server.method() == HTTP_POST) { - saveUnit(server.arg("tu"), server.arg("md"), server.arg("lpw"), (String)convertLocalUnitToCelsius(server.arg("min_temp").toInt(), useFahrenheit), (String)convertLocalUnitToCelsius(server.arg("max_temp").toInt(), useFahrenheit), server.arg("temp_step")); + saveUnit(server.arg("tu"), server.arg("md"), server.arg("lpw"), (String)convertLocalUnitToCelsius(server.arg("min_temp").toFloat(), useFahrenheit), (String)convertLocalUnitToCelsius(server.arg("max_temp").toFloat(), useFahrenheit), server.arg("temp_step")); rebootAndSendPage(); } else { @@ -1264,7 +1266,7 @@ heatpumpSettings change_states(heatpumpSettings settings) { update = true; } if (server.hasArg("TEMP")) { - settings.temperature = convertLocalUnitToCelsius(server.arg("TEMP").toInt(), useFahrenheit); + settings.temperature = convertLocalUnitToCelsius(server.arg("TEMP").toFloat(), useFahrenheit); update = true; } if (server.hasArg("FAN")) { @@ -1772,15 +1774,51 @@ bool connectWifi() { return true; } -// temperature helper functions -float toFahrenheit(float fromCelcius) { - return round(1.8 * fromCelcius + 32.0); +// temperature helper these are direct mappings based on the remote +float toFahrenheit(float fromCelsius) { + // Lookup table for specific mappings + const std::map lookupTable = { + {16.0, 61}, {16.5, 62}, {17.0, 63}, {17.5, 64}, {18.0, 65}, + {18.5, 66}, {19.0, 67}, {20.0, 68}, {21.0, 69}, {21.5, 70}, + {22.0, 71}, {22.5, 72}, {23.0, 73}, {23.5, 74}, {24.0, 75}, + {24.5, 76}, {25.0, 77}, {25.5, 78}, {26.0, 79}, {26.5, 80}, + {27.0, 81}, {27.5, 82}, {28.0, 83}, {28.5, 84}, {29.0, 85}, + {29.5, 86}, {30.0, 87}, {30.5, 88} + }; + + // Check if the input is in the lookup table + auto it = lookupTable.find(fromCelsius); + if (it != lookupTable.end()) { + return it->second; + } + + // Default conversion and rounding to nearest integer + return roundf(fromCelsius * 1.8 + 32.0); } +// temperature helper these are direct mappings based on the remote float toCelsius(float fromFahrenheit) { - return (fromFahrenheit - 32.0) / 1.8; + // Lookup table for specific mappings + const std::map lookupTable = { + {61, 16.0}, {62, 16.5}, {63, 17.0}, {64, 17.5}, {65, 18.0}, + {66, 18.5}, {67, 19.0}, {68, 20.0}, {69, 21.0}, {70, 21.5}, + {71, 22.0}, {72, 22.5}, {73, 23.0}, {74, 23.5}, {75, 24.0}, + {76, 24.5}, {77, 25.0}, {78, 25.5}, {79, 26.0}, {80, 26.5}, + {81, 27.0}, {82, 27.5}, {83, 28.0}, {84, 28.5}, {85, 29.0}, + {86, 29.5}, {87, 30.0}, {88, 30.5} + }; + + // Check if the input is in the lookup table + auto it = lookupTable.find(static_cast(fromFahrenheit)); + if (it != lookupTable.end()) { + return it->second; + } + + // Default conversion and rounding to nearest 0.5 + return roundf((fromFahrenheit - 32.0) / 1.8 * 2) / 2.0; } + float convertCelsiusToLocalUnit(float temperature, bool isFahrenheit) { if (isFahrenheit) { return toFahrenheit(temperature);