Skip to content

Commit

Permalink
Merge pull request #4813 from jfmennedy/dev
Browse files Browse the repository at this point in the history
P093 Mitsubishi HeatPump
  • Loading branch information
TD-er authored Oct 22, 2023
2 parents 1f32e86 + 06a2009 commit 41e1c13
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
8 changes: 7 additions & 1 deletion docs/source/Plugin/P093.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ See: :ref:`SerialHelper_page`

Once we hit submit, the plugin will start sending messages through controller, i.e. MQTT with payload:

``{"roomTemperature":25.5,"wideVane":"|","power":"OFF","mode":"COOL","fan":"AUTO","vane":"AUTO","iSee":true,"operating":true,"compressorFrequency":5,"temperature":24.0}``
``{"roomTemperature":19.5,"wideVane":"|","power":"OFF","mode":"HEAT","fan":"AUTO","vane":"AUTO","iSee":false,"operating":false,"compressorFrequency":2,"temperature":22.0,"remoteTemperature":19.5}``

Message is send every time a change is detected (i.e. one changes settings using IR remote control) and every X seconds, as set in the settings (60 seconds in above screenshot).

Expand Down Expand Up @@ -127,6 +127,12 @@ Special thanks
Change log
----------

.. versionchanged:: 2023/09/25
...

|added|
Set Remote Temperature. (value > 0: Use external temperature sensor, value = 0: Use internal temperature sensor)

.. versionchanged:: 2021/08/03
...

Expand Down
5 changes: 5 additions & 0 deletions docs/source/Plugin/P093_commands.repl
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@
","
Value = ``<<``, ``<``, ``|``, ``>``, ``>>``, ``<>`` or ``SWING``
"
"
``MitsubishiHP,remotetemperature,<value>``
","
Value > ``0.0``: Use external temperature sensor, Value = ``0.0``: Use internal temperature sensor.
"
6 changes: 6 additions & 0 deletions docs/source/Plugin/P093_config_values.repl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
| ``[<taskname>#roomTemperature]``
","
| Value as received from the connected device, includes 1 decimal.
| When Remote Temperature is used, received value is rounded to the nearest 0.5 C.
"
"
| ``[<taskname>#wideVane]``
Expand Down Expand Up @@ -52,3 +53,8 @@
","
| Value as received from the connected device, when ``Include AC status`` is enabled.
"
"
| ``[<taskname>#remoteTemperature]``
","
| Value as received from the connected device, includes 1 decimal.
"
2 changes: 2 additions & 0 deletions src/_P093_MitsubishiHP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// #######################################################################################################

/** Changelog:
* 2023-09-21 jfmennedy: Add support for "SetRemoteTemperature" Issue#4711
* 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
*/
Expand All @@ -14,6 +15,7 @@
* Usage: [<taskname>#<configName>]
* Supported configNames are: (not case-sensitive)
* - roomTemperature
* - remoteTemperature
* - wideVane
* - power
* - mode
Expand Down
42 changes: 40 additions & 2 deletions src/src/PluginStructs/P093_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*
* Plugin is based on "Arduino library to control Mitsubishi Heat Pumps" from
* https://github.com/SwiCago/HeatPump.
*
* SetRemoteTemperature is based on following Issue and Resolve
* https://github.com/SwiCago/HeatPump/pull/144#issue-514996963
* https://github.com/SwiCago/HeatPump/pull/144/commits/c50372c7632b9e7324caf0c0fc0773871645688e
*
*/

Expand Down Expand Up @@ -78,7 +82,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 +126,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 +158,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 +310,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 @@ -359,8 +379,26 @@ void P093_data_struct::applySettings() {
packet[7] |= 0x01;
}

if (_writeStatus.isDirty(RemoteTemperature)) {
memset(packet + 6, 0, 15);
packet[5] = 0x07;
if(_wantedSettings.remoteTemperature > 0) {
packet[6] |= 0x01;
_wantedSettings.remoteTemperature = _wantedSettings.remoteTemperature * 2;
_wantedSettings.remoteTemperature = round(_wantedSettings.remoteTemperature);
_wantedSettings.remoteTemperature = _wantedSettings.remoteTemperature / 2;
if (_tempMode) { //units that don't support 0.5 increment
packet[8] = static_cast<uint8_t>(_wantedSettings.remoteTemperature * 2.0f + 128.0f);
} else { //units that do support 0.5 increment
packet[7] = static_cast<uint8_t>(3.0f + ((_wantedSettings.remoteTemperature - 10.0f) * 2.0f));
}
}
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);
}

Expand Down
24 changes: 14 additions & 10 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 = 0x30;

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

Values() :
power(0),
iSee(false),
mode(0),
temperature(0),
temperature(0.0f),
fan(0),
vane(0),
wideVane(0),
roomTemperature(0),
roomTemperature(0.0f),
remoteTemperature(0.0f),
operating(false),
compressorFrequency(0) {}

bool operator!=(const Values& rhs) const {
return power != rhs.power ||
mode != rhs.mode ||
temperature != rhs.temperature ||
!essentiallyEqual(temperature, rhs.temperature) ||
fan != rhs.fan ||
vane != rhs.vane ||
wideVane != rhs.wideVane ||
iSee != rhs.iSee ||
roomTemperature != rhs.roomTemperature ||
!essentiallyEqual(roomTemperature, rhs.roomTemperature) ||
!essentiallyEqual(remoteTemperature, rhs.remoteTemperature) ||
operating != rhs.operating ||
compressorFrequency != rhs.compressorFrequency;
}
Expand Down

0 comments on commit 41e1c13

Please sign in to comment.