Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Convert to HA supported fan modes #274

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mitsubishi2mqtt/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/*#define MY_LANGUAGE fr-FR // define your language*/

const PROGMEM char* m2mqtt_version = "2023.8.0";
const PROGMEM char* m2mqtt_version = "2024.8.1";

//Define global variables for files
#ifdef ESP32
Expand Down
2 changes: 1 addition & 1 deletion src/mitsubishi2mqtt/languages/da-DA.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ const char txt_upload_refresh[] PROGMEM = "Refresh in";
//Page Init
const char txt_init_title[] PROGMEM = "Initial setup";
const char txt_init_reboot_mes[] PROGMEM = "Rebooting and connecting to your WiFi network! You should see it listed in on your access point.";
const char txt_init_reboot[] PROGMEM = "Rebooting...";
const char txt_init_reboot[] PROGMEM = "Rebooting...";
2 changes: 1 addition & 1 deletion src/mitsubishi2mqtt/languages/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ const char txt_upload_refresh[] PROGMEM = "Aktualisierung in";
//Page Init
const char txt_init_title[] PROGMEM = "Ersteinrichtung";
const char txt_init_reboot_mes[] PROGMEM = "Neustart und Verbindung zu deinem WLAN-Netzwerk wird hergestellt! Du solltest es in deiner AccessPoint Auflistung sehen.";
const char txt_init_reboot[] PROGMEM = "Neustart...";
const char txt_init_reboot[] PROGMEM = "Neustart...";
2 changes: 1 addition & 1 deletion src/mitsubishi2mqtt/languages/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ const char txt_upload_refresh[] PROGMEM = "Rafaichissement dans ";
//Page Init
const char txt_init_title[] PROGMEM = "Initialisation";
const char txt_init_reboot_mes[] PROGMEM = "Redémarrage et connexion à votre WIFI. L'appareil doit apparaitre dans votre réseau";
const char txt_init_reboot[] PROGMEM = "Redémarrage...";
const char txt_init_reboot[] PROGMEM = "Redémarrage...";
2 changes: 1 addition & 1 deletion src/mitsubishi2mqtt/languages/ja-JP.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ const char txt_upload_refresh[] PROGMEM = "再読込中";
//Page Init
const char txt_init_title[] PROGMEM = "初期設定";
const char txt_init_reboot_mes[] PROGMEM = "Rebooting and connecting to your WiFi network! You should see it listed in on your access point.";
const char txt_init_reboot[] PROGMEM = "Rebooting...";
const char txt_init_reboot[] PROGMEM = "Rebooting...";
51 changes: 40 additions & 11 deletions src/mitsubishi2mqtt/mitsubishi2mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void setup() {
heatpumpSettings currentSettings = hp.getSettings();
rootInfo["roomTemperature"] = convertCelsiusToLocalUnit(currentStatus.roomTemperature, useFahrenheit);
rootInfo["temperature"] = convertCelsiusToLocalUnit(currentSettings.temperature, useFahrenheit);
rootInfo["fan"] = currentSettings.fan;
rootInfo["fan"] = hpGetFan(currentSettings);
rootInfo["vane"] = currentSettings.vane;
rootInfo["wideVane"] = currentSettings.wideVane;
rootInfo["mode"] = hpGetMode(currentSettings);
Expand Down Expand Up @@ -1291,7 +1291,7 @@ void readHeatPumpSettings() {

rootInfo.clear();
rootInfo["temperature"] = convertCelsiusToLocalUnit(currentSettings.temperature, useFahrenheit);
rootInfo["fan"] = currentSettings.fan;
rootInfo["fan"] = hpGetFan(currentSettings);
rootInfo["vane"] = currentSettings.vane;
rootInfo["wideVane"] = currentSettings.wideVane;
rootInfo["mode"] = hpGetMode(currentSettings);
Expand All @@ -1313,7 +1313,7 @@ void hpSettingsChanged() {

String hpGetMode(heatpumpSettings hpSettings) {
// Map the heat pump state to one of HA's HVAC_MODE_* values.
// https://github.com/home-assistant/core/blob/master/homeassistant/components/climate/const.py#L3-L23
// https://github.com/home-assistant/core/blob/master/homeassistant/components/climate/const.py#L17-L37

String hppower = String(hpSettings.power);
if (hppower.equalsIgnoreCase("off")){
Expand All @@ -1328,6 +1328,21 @@ String hpGetMode(heatpumpSettings hpSettings) {
else return hpmode; // cool, heat, dry
}

String hpGetFan(heatpumpSettings hpSettings) {
// Map the fan speed to one of HA's FAN_* values.
// https://github.com/home-assistant/core/blob/master/homeassistant/components/climate/const.py#L75-L85

String hpfan = String(hpSettings.fan);
hpfan.toLowerCase();

if (hpfan == "quiet") return "diffuse";
else if (hpfan == "1") return "low";
else if (hpfan == "2") return "middle";
else if (hpfan == "3") return "medium";
else if (hpfan == "4") return "high";
else return hpfan; // auto
}

String hpGetAction(heatpumpStatus hpStatus, heatpumpSettings hpSettings) {
// Map heat pump state to one of HA's CURRENT_HVAC_* values.
// https://github.com/home-assistant/core/blob/master/homeassistant/components/climate/const.py#L80-L86
Expand Down Expand Up @@ -1361,7 +1376,7 @@ void hpStatusChanged(heatpumpStatus currentStatus) {
rootInfo.clear();
rootInfo["roomTemperature"] = convertCelsiusToLocalUnit(currentStatus.roomTemperature, useFahrenheit);
rootInfo["temperature"] = convertCelsiusToLocalUnit(currentSettings.temperature, useFahrenheit);
rootInfo["fan"] = currentSettings.fan;
rootInfo["fan"] = hpGetFan(currentSettings);
rootInfo["vane"] = currentSettings.vane;
rootInfo["wideVane"] = currentSettings.wideVane;
rootInfo["mode"] = hpGetMode(currentSettings);
Expand Down Expand Up @@ -1483,9 +1498,23 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
hp.setTemperature(temperature_c);
}
else if (strcmp(topic, ha_fan_set_topic.c_str()) == 0) {
String fanUpper = message;
fanUpper.toUpperCase();
String fanSpeed = fanUpper;
if (fanUpper == "DIFFUSE") {
fanSpeed = "QUIET";
} else if (fanUpper == "LOW") {
fanSpeed = "1";
} else if (fanUpper == "MIDDLE") {
fanSpeed = "2";
} else if (fanUpper == "MEDIUM") {
fanSpeed = "3";
} else if (fanUpper == "HIGH") {
fanSpeed = "4";
}
rootInfo["fan"] = (String) message;
hpSendLocalState();
hp.setFanSpeed(message);
hp.setFanSpeed(fanSpeed.c_str());
}
else if (strcmp(topic, ha_vane_set_topic.c_str()) == 0) {
rootInfo["vane"] = (String) message;
Expand Down Expand Up @@ -1606,12 +1635,12 @@ void haConfig() {
haConfig["temperature_unit"] = useFahrenheit ? "F" : "C";

JsonArray haConfigFan_modes = haConfig.createNestedArray("fan_modes");
haConfigFan_modes.add("AUTO");
haConfigFan_modes.add("QUIET");
haConfigFan_modes.add("1");
haConfigFan_modes.add("2");
haConfigFan_modes.add("3");
haConfigFan_modes.add("4");
haConfigFan_modes.add("auto");
haConfigFan_modes.add("diffuse");
haConfigFan_modes.add("low");
haConfigFan_modes.add("middle");
haConfigFan_modes.add("medium");
haConfigFan_modes.add("high");

haConfig["fan_mode_cmd_t"] = ha_fan_set_topic;
haConfig["fan_mode_stat_t"] = ha_state_topic;
Expand Down
Loading