MikeJMcGuire / hass-actronque

Actron Que/Neo Air Conditioner Add-On for Home Assistant
GNU General Public License v3.0
13 stars 5 forks source link

Temperature setpoint looses sync between Actronque and mqtt/HA #4

Closed DanielNagy closed 3 years ago

DanielNagy commented 3 years ago

From Que App - change heat set point from 20c to 17c. With the "Control All Zones" option enabled.

Following event message is seen and parsed.

{
         "id":"A0000017b2b216200|0934fd65-0a74-451b-96d0-e495c3b1b57b",
         "type":"status-change-broadcast",
         "pairedUserId":"1108a6e0-a347-4491-9a1f-8e5102413b2e",
         "timestamp":"2021-08-09T13:36:53.2484103+00:00",
         "data":{
            "RemoteZoneInfo[0].MaxHeatSetpoint":17,
            "RemoteZoneInfo[0].MinHeatSetpoint":15,
            "RemoteZoneInfo[0].TemperatureSetpoint_Heat_oC":17,
            "RemoteZoneInfo[1].MaxHeatSetpoint":17,
            "RemoteZoneInfo[1].MinHeatSetpoint":15,
            "RemoteZoneInfo[1].TemperatureSetpoint_Heat_oC":17,
            "RemoteZoneInfo[2].MaxHeatSetpoint":17,
            "RemoteZoneInfo[2].MinHeatSetpoint":15,
            "RemoteZoneInfo[2].TemperatureSetpoint_Heat_oC":17,
            "RemoteZoneInfo[3].MaxHeatSetpoint":17,
            "RemoteZoneInfo[3].MinHeatSetpoint":15,
            "RemoteZoneInfo[3].TemperatureSetpoint_Heat_oC":17,
            "RemoteZoneInfo[4].MaxHeatSetpoint":17,
            "RemoteZoneInfo[4].MinHeatSetpoint":15,
            "RemoteZoneInfo[4].TemperatureSetpoint_Heat_oC":17,
            "RemoteZoneInfo[5].MaxHeatSetpoint":17,
            "RemoteZoneInfo[5].MinHeatSetpoint":15,
            "RemoteZoneInfo[5].TemperatureSetpoint_Heat_oC":17,
            "RemoteZoneInfo[6].MaxHeatSetpoint":17,
            "RemoteZoneInfo[6].MinHeatSetpoint":15,
            "RemoteZoneInfo[6].TemperatureSetpoint_Heat_oC":17,
            "RemoteZoneInfo[7].MaxHeatSetpoint":17,
            "RemoteZoneInfo[7].MinHeatSetpoint":15,
            "RemoteZoneInfo[7].TemperatureSetpoint_Heat_oC":17,
            "UserAirconSettings.TemperatureSetpoint_Heat_oC":17
         }
      }

What is observed.

actronque/zoneX/settemperature mqtt topic is correctly updated to 17c for zones that are turned on. actronque/zoneX/settemperature mqtt topic is incorrectly updated to 22.5c for zones that are turned off. The turned off zones show 22.5c, calculated by "Que.GetSetTemperature()" function using Cool mode 28c, Heat mode 17c on the following line.

https://github.com/MikeJMcGuire/hass-actronque/blob/9403799e1a9cd33e3a396ddf16bc23c7e4fd95e7/hass-actronque/Que.cs#L1343

Line 1343 needs additional switch logic from _airConditionerData.Mode to determine if COOL or HEAT setpoint should be used, to maintain syncronised data in mqtt, vs the actron master controller / app.

DanielNagy commented 3 years ago

My Code suggestion Replace the entire If statement from line L1340 to L1344, with the following code.

https://github.com/MikeJMcGuire/HASSAddons/blob/5d82077c2dc04c48629e5f059072172556a4698e/hass-actronque/hass-actronque/Que.cs#L1340

Essentially the zones correct HEAT / COOL set point can still be shown for the OFF Zone (handled by case COOL and HEAT in the switch statement), whilst the unit is still ON for other zones.

if (!_airConditionerData.On)
{
    MQTT.SendMessage(string.Format("actronque/zone{0}/mode", iIndex), "off");
    MQTT.SendMessage(string.Format("actronque/zone{0}/settemperature", iIndex), GetSetTemperature(_airConditionerZones[iIndex].SetTemperatureHeating, _airConditionerZones[iIndex].SetTemperatureCooling).ToString("N1"));
}

if (!_airConditionerZones[iIndex].State)
{
    MQTT.SendMessage(string.Format("actronque/zone{0}/mode", iIndex), "off");

    switch (_airConditionerData.Mode)
    {
        case "AUTO":
            MQTT.SendMessage(string.Format("actronque/zone{0}/settemperature", iIndex), GetSetTemperature(_airConditionerZones[iIndex].SetTemperatureHeating, _airConditionerZones[iIndex].SetTemperatureCooling).ToString("N1"));
            break;

        case "COOL":
            MQTT.SendMessage(string.Format("actronque/zone{0}/settemperature", iIndex), _airConditionerZones[iIndex].SetTemperatureCooling.ToString("N1"));
            break;

        case "HEAT":
            MQTT.SendMessage(string.Format("actronque/zone{0}/settemperature", iIndex), _airConditionerZones[iIndex].SetTemperatureHeating.ToString("N1"));
            break;

        case "FAN":
            MQTT.SendMessage(string.Format("actronque/zone{0}/settemperature", iIndex), GetSetTemperature(_airConditionerZones[iIndex].SetTemperatureHeating, _airConditionerZones[iIndex].SetTemperatureCooling).ToString("N1"));
            break;

        default:
            Logging.WriteDebugLog("Que.MQTTUpdateData() Unexpected Mode: {0}", _airConditionerData.Mode);
            break;
    }

}
MikeJMcGuire commented 3 years ago

Just testing the changes now. I've gone through the logic, slightly different solution, but only different in style.

Zones that are off, will now receive updates to temperature set point, based on the overall mode.

MikeJMcGuire commented 3 years ago

Updated the blog entry to refer to the new items and your fix for the zones. Let me know how you go, the new version is up now.