Skip to content

Commit

Permalink
P093 Mitsubishi HeatPump
Browse files Browse the repository at this point in the history
Add Support for SetRemoteTemperature
Resolves P093 - Mitsubishi Heat Pump Add Remote Temperature letscontrolit#4711
  • Loading branch information
jfmennedy committed Sep 21, 2023
1 parent a97b76c commit 98af072
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/_P093_MitsubishiHP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
/** Changelog:
* 2023-05-04 tonhuisman: Add support for PLUGIN_GET_CONFIG_VALUE to enable fetching all available values (as included in the json)
* 2023-05-04 tonhuisman: Start Changelog
* 2023-09-21 jfmennedy: Add support for "SetRemoteTemperature" Issue#4711
*/

/** Get Config values:
* Usage: [<taskname>#<configName>]
* Supported configNames are: (not case-sensitive)
* - roomTemperature
* - remoteTemperature
* - wideVane
* - power
* - mode
Expand Down
41 changes: 40 additions & 1 deletion src/src/PluginStructs/P093_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ bool P093_data_struct::read(String& result) const {
result += _currentValues.compressorFrequency;
}
result += F(",\"temperature\":");
result += toString(_currentValues.temperature, 1) + '}';
result += toString(_currentValues.temperature, 1);
result += F(",\"remoteTemperature\":");
result += toString(_currentValues.remoteTemperature, 1) + '}';

return true;
}
Expand Down Expand Up @@ -120,6 +122,9 @@ bool P093_data_struct::plugin_get_config_value(struct EventStruct *event,
} else
if (_includeStatus && equals(command, F("compressorfrequency"))) {
string = _currentValues.compressorFrequency;
} else
if (equals(command, F("remotetemperature"))) {
string = toString(_currentValues.remoteTemperature, 1);
} else {
success = false;
}
Expand Down Expand Up @@ -149,6 +154,13 @@ void P093_data_struct::write(const String& command, const String& value) {
_writeStatus.set(Vane);
} else if ((equals(command, F("widevane"))) && lookup(value, _mappings.wideVane, _wantedSettings.wideVane)) {
_writeStatus.set(WideVane);
} else if (equals(command, F("remotetemperature"))) {
float remotetemperature = 0;

if (string2float(value, remotetemperature)) {
_wantedSettings.remoteTemperature = remotetemperature;
_writeStatus.set(RemoteTemperature);
}
}

# undef lookup
Expand Down Expand Up @@ -294,6 +306,10 @@ void P093_data_struct::applySettingsLocally() {
if (_writeStatus.isDirty(WideVane)) {
_currentValues.wideVane = _wantedSettings.wideVane;
}

if (_writeStatus.isDirty(RemoteTemperature)) {
_currentValues.remoteTemperature = _wantedSettings.remoteTemperature;
}
}

void P093_data_struct::cancelWaitingAndTransitTo(P093_data_struct::State state) {
Expand Down Expand Up @@ -362,6 +378,29 @@ void P093_data_struct::applySettings() {
packet[21] = checkSum(packet, 21);

sendPacket(packet, PACKET_LEN);

if (_writeStatus.isDirty(RemoteTemperature)) {
packet[PACKET_LEN] = {};

packet[5] |= 0x07;
if(_wantedSettings.remoteTemperature > 0) {
packet[6] |= 0x01;
if (_tempMode) {
packet[8] = static_cast<uint8_t>(_wantedSettings.remoteTemperature * 2.0f + 128.0f);
} else {
packet[7] = _wantedSettings.remoteTemperature;
}
}
else {
packet[6] |= 0x00;
packet[8] |= 0x80; //MHK1 send 80, even though it could be 00, since ControlByte is 00
}

packet[21] = checkSum(packet, 21);

sendPacket(packet, PACKET_LEN);
}

}

void P093_data_struct::connect() {
Expand Down
16 changes: 10 additions & 6 deletions src/src/PluginStructs/P093_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ struct P093_data_struct : public PluginTaskData_base {
ReadTimeout
};

static const uint8_t Temperature = 0x01;
static const uint8_t Power = 0x02;
static const uint8_t Mode = 0x04;
static const uint8_t Fan = 0x08;
static const uint8_t Vane = 0x10;
static const uint8_t WideVane = 0x20;
static const uint8_t Temperature = 0x01;
static const uint8_t Power = 0x02;
static const uint8_t Mode = 0x04;
static const uint8_t Fan = 0x08;
static const uint8_t Vane = 0x10;
static const uint8_t WideVane = 0x20;
static const uint8_t RemoteTemperature = 0x07;

struct WriteStatus {
WriteStatus() : _flags(0) {}
Expand Down Expand Up @@ -158,6 +159,7 @@ struct P093_data_struct : public PluginTaskData_base {
uint8_t vane;
uint8_t wideVane;
float roomTemperature;
float remoteTemperature;
bool operating;
uint8_t compressorFrequency;

Expand All @@ -170,6 +172,7 @@ struct P093_data_struct : public PluginTaskData_base {
vane(0),
wideVane(0),
roomTemperature(0),
remoteTemperature(0),
operating(false),
compressorFrequency(0) {}

Expand All @@ -182,6 +185,7 @@ struct P093_data_struct : public PluginTaskData_base {
wideVane != rhs.wideVane ||
iSee != rhs.iSee ||
roomTemperature != rhs.roomTemperature ||
remoteTemperature != rhs.remoteTemperature ||
operating != rhs.operating ||
compressorFrequency != rhs.compressorFrequency;
}
Expand Down

0 comments on commit 98af072

Please sign in to comment.