From 26ec1efa75e120ab0c38591e46978f15b1a5a5ad Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 29 Dec 2020 13:21:15 +0100 Subject: [PATCH] Thermostats: Adjust to new thermostat interface --- .../integrationplugingenericthings.cpp | 49 ++++++++--- .../integrationplugingenericthings.json | 81 +++++++++++++++++-- 2 files changed, 114 insertions(+), 16 deletions(-) diff --git a/genericthings/integrationplugingenericthings.cpp b/genericthings/integrationplugingenericthings.cpp index cb96c4a..601ecb3 100644 --- a/genericthings/integrationplugingenericthings.cpp +++ b/genericthings/integrationplugingenericthings.cpp @@ -642,12 +642,19 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info) Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); } else if (thing->thingClassId() == thermostatThingClassId) { - if (action.actionTypeId() == thermostatTemperatureSensorInputActionTypeId) { - thing->setStateValue(thermostatTemperatureSensorInputStateTypeId, action.param(thermostatTemperatureSensorInputActionTemperatureSensorInputParamTypeId).value()); + if (action.actionTypeId() == thermostatTemperatureActionTypeId) { + thing->setStateValue(thermostatTemperatureStateTypeId, action.param(thermostatTemperatureActionTemperatureParamTypeId).value()); } else if (action.actionTypeId() == thermostatTargetTemperatureActionTypeId) { - thing->setStateValue(thermostatTargetTemperatureStateTypeId, action.param(thermostatTargetTemperatureActionTargetTemperatureParamTypeId).value()); - } else if (action.actionTypeId() == thermostatPowerActionTypeId) { - thing->setStateValue(thermostatPowerStateTypeId, action.param(thermostatPowerActionPowerParamTypeId).value()); + double minSetting = thing->setting(thermostatSettingsMinTargetTemperatureParamTypeId).toDouble(); + double maxSetting = thing->setting(thermostatSettingsMaxTargetTemperatureParamTypeId).toDouble(); + double newTemp = action.param(thermostatTargetTemperatureActionTargetTemperatureParamTypeId).value().toDouble(); + newTemp = qMax(newTemp, minSetting); + newTemp = qMin(newTemp, maxSetting); + thing->setStateValue(thermostatTargetTemperatureStateTypeId, newTemp); + } else if (action.actionTypeId() == thermostatHeatingOnActionTypeId) { + thing->setStateValue(thermostatHeatingOnStateTypeId, action.param(thermostatHeatingOnActionHeatingOnParamTypeId).value()); + } else if (action.actionTypeId() == thermostatCoolingOnActionTypeId) { + thing->setStateValue(thermostatCoolingOnStateTypeId, action.param(thermostatCoolingOnActionCoolingOnParamTypeId).value()); } else { Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); } @@ -655,6 +662,24 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info) info->finish(Thing::ThingErrorNoError); return; + } else if (thing->thingClassId() == heatingThingClassId) { + if (action.actionTypeId() == heatingPowerActionTypeId) { + thing->setStateValue(heatingPowerStateTypeId, action.paramValue(heatingPowerActionPowerParamTypeId).toBool()); + } else { + Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); + } + info->finish(Thing::ThingErrorNoError); + return; + + } else if (thing->thingClassId() == coolingThingClassId) { + if (action.actionTypeId() == coolingPowerActionTypeId) { + thing->setStateValue(coolingPowerStateTypeId, action.paramValue(coolingPowerActionPowerParamTypeId).toBool()); + } else { + Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); + } + info->finish(Thing::ThingErrorNoError); + return; + } else if (thing->thingClassId() == sgReadyThingClassId) { if (action.actionTypeId() == sgReadyRelay1ActionTypeId) { thing->setStateValue(sgReadyRelay1StateTypeId, action.param(sgReadyRelay1ActionRelay1ParamTypeId).value()); @@ -851,15 +876,17 @@ void IntegrationPluginGenericThings::moveBlindToAngle(Action action, Thing *thin void IntegrationPluginGenericThings::thermostatCheckPowerOutputState(Thing *thing) { double targetTemperature = thing->stateValue(thermostatTargetTemperatureStateTypeId).toDouble(); - double actualTemperature = thing->stateValue(thermostatTemperatureSensorInputStateTypeId).toDouble(); + double actualTemperature = thing->stateValue(thermostatTemperatureStateTypeId).toDouble(); double temperatureDifference = thing->setting(thermostatSettingsTemperatureDifferenceParamTypeId).toDouble(); if (actualTemperature <= (targetTemperature-temperatureDifference)) { - thing->setStateValue(thermostatPowerStateTypeId, true); + thing->setStateValue(thermostatHeatingOnStateTypeId, true); } else if (actualTemperature >= targetTemperature) { - thing->setStateValue(thermostatPowerStateTypeId, false); - } else { - //Keep actual state - //Possible improvement add boost action where powerState = true is forced inside the hysteresis + thing->setStateValue(thermostatHeatingOnStateTypeId, false); + } + if (actualTemperature >= (targetTemperature+temperatureDifference)) { + thing->setStateValue(thermostatCoolingOnStateTypeId, true); + } else if (actualTemperature <= targetTemperature) { + thing->setStateValue(thermostatCoolingOnStateTypeId, false); } } diff --git a/genericthings/integrationplugingenericthings.json b/genericthings/integrationplugingenericthings.json index 54a6097..2f17bc8 100644 --- a/genericthings/integrationplugingenericthings.json +++ b/genericthings/integrationplugingenericthings.json @@ -1035,7 +1035,7 @@ "name": "thermostat", "displayName": "Generic thermostat", "createMethods": ["user"], - "interfaces": ["thermostat", "heating"], + "interfaces": ["thermostat"], "settingsTypes": [ { "id": "64bf308f-a543-4e02-b787-1a1714c1f978", @@ -1045,12 +1045,32 @@ "unit": "DegreeCelsius", "minValue": 0.00, "defaultValue": 2.00 + }, + { + "id": "67451c97-50e1-4ea6-ac43-4386fbd26698", + "name": "minTargetTemperature", + "displayName": "Minimum temperature", + "type": "double", + "unit": "DegreeCelsius", + "minValue": -20, + "maxValue": 49, + "defaultValue": -20 + }, + { + "id": "85608dd5-7e67-4c98-9e62-b97411681048", + "name": "maxTargetTemperature", + "displayName": "Maximum temperature", + "type": "double", + "unit": "DegreeCelsius", + "minValue": -19, + "maxValue": 50, + "defaultValue": 50 } ], "stateTypes": [ { "id": "0f808803-0e63-47df-b024-9685998ba663", - "name": "temperatureSensorInput", + "name": "temperature", "displayName": "Temperature sensor input", "displayNameEvent": "Temperature sensor input changed", "displayNameAction": "Set temperature sensor input", @@ -1078,10 +1098,61 @@ }, { "id": "1f6a0c39-4417-4e31-86db-9926cf81c345", + "name": "heatingOn", + "displayName": "Heating On/off", + "displayNameEvent": "Heating turned on/off", + "displayNameAction": "Turn heating on/off", + "type": "bool", + "defaultValue": false, + "writable": true, + "ioType": "digitalInput" + }, + { + "id": "cab7d4bd-f612-4d12-b3a4-0649e189810f", + "name": "coolingOn", + "displayName": "Cooling On/off", + "displayNameEvent": "Cooling turned on/off", + "displayNameAction": "Turn cooling on/off", + "type": "bool", + "defaultValue": false, + "writable": true, + "ioType": "digitalInput" + } + ] + }, + { + "id": "e808fc5b-12fb-46d4-bb5d-25a4586bc0ba", + "name": "heating", + "displayName": "Generic heater", + "createMethods": ["user"], + "interfaces": ["heating"], + "stateTypes": [ + { + "id": "bb6b5e3a-d4d9-4440-a098-0720c14ad679", "name": "power", - "displayName": "On/off", - "displayNameEvent": "Turned on/off", - "displayNameAction": "Turn on/off", + "displayName": "Heater on/off", + "displayNameEvent": "Heater turned on/off", + "displayNameAction": "Turn heater on/off", + "type": "bool", + "defaultValue": false, + "writable": true, + "ioType": "digitalInput" + } + ] + }, + { + "id": "09edbc07-d382-48a4-9b16-99992014aff9", + "name": "cooling", + "displayName": "Generic cooler", + "createMethods": ["user"], + "interfaces": ["cooling"], + "stateTypes": [ + { + "id": "918cfd2c-6692-4faa-acc6-18ebf93611ec", + "name": "power", + "displayName": "Cooler on/off", + "displayNameEvent": "Cooler turned on/off", + "displayNameAction": "Turn cooler on/off", "type": "bool", "defaultValue": false, "writable": true,