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

P093 Mitsubishi HeatPump #4813

Merged
merged 10 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changelog is supposed to be from the top from new to old... 😉 I see why this one can be confusing, but the Start message should have been the giveaway 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified ;-)

*/

/** 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);

Copy link
Contributor Author

@jfmennedy jfmennedy Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need Help here...

When i put line 382 to 384

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

sendPacket(packet, PACKET_LEN);

under line 404 remote temperature works, but not the other commands (line 347 to 380).. if these lines are like this the other commands work, but not remote temperature...

What am I missing???

Sorry I am not a programmer, i try just to help myself out on an issue i opened long time ago...

Thx for your help...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you are moving those lines from 382-384 to below where the remoteTemperature value is put into the packet buffer?
This could mean that, besides the other commands, also the remoteTemperature is put into the packet buffer, causing the other commands to be overwritten/changed by that data.
Some generic improvements can be made to this plugin, like initializing float values with a float 0 constant: 0.0f, and compare these values using a special float comparator, I'll mark those lines in the .h file, below (and can also be applied to the other 2 float values).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that´s right.. I also tried with another buffer called packet2, which is just handled after the if (_writeStatus.isDirty(RemoteTemperature)) section.. but same behaviour, i can set the hp on /off etc, but not the remote temp. I can just set remote temperature when it is buffer called packet behind if (_writeStatus.isDirty(RemoteTemperature))...
I also tried to set the buffer in each if(_writeStatus.isDirty(...)) and just execute sendPacket(packet, PACKET_LEN); in the end of this block.. but than only remote remote is handled no other command...

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

packet[5] |= 0x07;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An improvement might be to re-initialize the packet buffer by inserting memset(packet + 6, 0, 15); before the (corrected) assignment here: packet[5] = 0x07; as using command mode 0x01 (probably) isn't compatible with command mode 0x07, required for setting the remoteTemperature value. Multiple values can be sent in a single command, it seems, as most values go into different positions.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?
A logic OR with 0 doesn't change anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it´s not intended, will be fixed...

packet[8] |= 0x80; //MHK1 send 80, even though it could be 00, since ControlByte is 00
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code has a simple assignment operator here, not an OR-assign, though effectively it doesn't make a difference, best would be to use just =.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i wondered why in the whole code the or assignment was used... thats why i choose this on also for the modification..

Copy link
Contributor

@tonhuisman tonhuisman Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this specific case it should be an assignment, the other places should keep |= as multiple settings can be sent in a single packet, and some set a different bit in that offset.

}

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfmennedy these flags are being used as a bitmap, not as a numeric value. If you change this to 0x30 the temperature, power and mode commands should start to work as intended again 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will try this now.. saw this comment too late before my last commit and comment...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That´s it :-) It is working :-) Thank you sooooo much :-)


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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be initialized with a float zero value: 0.0f (can also be applied to the other 2 float values temperature and roomTemperature)

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 ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can use a specific, more accurate, float compare function:
!essentiallyEqual(remoteTemperature, rhs.remoteTemperature)
(can also be applied to the other 2 float values temperature and roomTemperature)

operating != rhs.operating ||
compressorFrequency != rhs.compressorFrequency;
}
Expand Down