Skip to content

Commit

Permalink
Merge pull request #27 from disruptivepatternmaterial/main
Browse files Browse the repository at this point in the history
Standby Packet enhancement
  • Loading branch information
echavet authored Feb 19, 2024
2 parents 17ca971 + a0788ca commit a543ca0
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files.autoSave": "afterDelay"
}
Binary file added components/.DS_Store
Binary file not shown.
24 changes: 19 additions & 5 deletions components/cn105/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ static const int ROOM_TEMP_MAP[32] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2
static const uint8_t TIMER_MODE[4] = { 0x00, 0x01, 0x02, 0x03 };
static const char* TIMER_MODE_MAP[4] = { "NONE", "OFF", "ON", "BOTH" };

//added NET to work with additional data
static const uint8_t STAGE[6] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
static const char* STAGE_MAP[6] = { "STAGE 0", "STAGE 1", "STAGE 2", "STAGE 3", "STAGE 4", "STAGE 5" };
static const uint8_t SUB_MODE[4] = { 0x00, 0x02, 0x04, 0x08 };
static const char* SUB_MODE_MAP[4] = { "NORMAL", "DEFROST", "PREHEAT", "STANDBY"};
static const uint8_t AUTO_SUB_MODE[4] = { 0x00, 0x01, 0x02, 0x03 };
static const char* AUTO_SUB_MODE_MAP[4] = { "AUTO_OFF","AUTO_COOL", "AUTO_HEAT", "AUTO_LEADER"};

static const int TIMER_INCREMENT_MINUTES = 10;

static const uint8_t FUNCTIONS_SET_PART1 = 0x1F;
Expand All @@ -102,10 +110,10 @@ static const int RQST_PKT_ROOM_TEMP = 1;
static const int RQST_PKT_TIMERS = 3;
static const int RQST_PKT_STATUS = 4;
static const int RQST_PKT_STANDBY = 5;
static const int RQST_PKT_UNKNOWN = 2;


const uint8_t ESPMHP_MIN_TEMPERATURE = 16;
const uint8_t ESPMHP_MAX_TEMPERATURE = 31;
const uint8_t ESPMHP_MIN_TEMPERATURE = 16; //16
const uint8_t ESPMHP_MAX_TEMPERATURE = 26; //31
const float ESPMHP_TEMPERATURE_STEP = 0.5;


Expand All @@ -118,6 +126,9 @@ struct heatpumpSettings {
const char* wideVane; //horizontal vane, left/right
bool iSee; //iSee sensor, at the moment can only detect it, not set it
bool connected;
const char* stage;
const char* sub_mode;
const char* auto_sub_mode;

heatpumpSettings& operator=(const heatpumpSettings& other) {
if (this != &other) { // protection contre l'auto-affectation
Expand All @@ -129,6 +140,9 @@ struct heatpumpSettings {
wideVane = other.wideVane;
iSee = other.iSee;
connected = other.connected;
stage = other.stage;
sub_mode = other.sub_mode;
auto_sub_mode = other.auto_sub_mode;
}
return *this;
}
Expand Down Expand Up @@ -156,7 +170,7 @@ struct wantedHeatpumpSettings : heatpumpSettings {
uint8_t nb_deffered_requests;
long lastChange;
wantedHeatpumpSettings& operator=(const wantedHeatpumpSettings& other) {
if (this != &other) { // protection contre l'auto-affectation
if (this != &other) { // self-assignment protection
heatpumpSettings::operator=(other); // Appel à l'opérateur d'affectation de la classe de base
hasChanged = other.hasChanged;
hasBeenSent = other.hasBeenSent;
Expand All @@ -165,7 +179,7 @@ struct wantedHeatpumpSettings : heatpumpSettings {
}

wantedHeatpumpSettings& operator=(const heatpumpSettings& other) {
if (this != &other) { // protection contre l'auto-affectation
if (this != &other) { // self-assignment protection
heatpumpSettings::operator=(other); // Copie des membres de base
}
return *this;
Expand Down
14 changes: 14 additions & 0 deletions components/cn105/auto_sub_mode_sensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "esphome/components/text_sensor/text_sensor.h"
#include "esphome/core/component.h"


namespace esphome {

class AutoSubModSensor : public text_sensor::TextSensor, public Component {
public:
AutoSubModSensor() {}
};

}
45 changes: 41 additions & 4 deletions components/cn105/climate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import climate, uart, select, sensor, binary_sensor
from esphome.components import climate, uart, select, sensor, binary_sensor, text_sensor

from esphome.components.logger import HARDWARE_UART_TO_SERIAL
from esphome.components.uart import UARTParityOptions
Expand All @@ -23,9 +23,12 @@
CONF_VERTICAL_SWING_SELECT = "vertical_vane_select"
CONF_COMPRESSOR_FREQUENCY_SENSOR = "compressor_frequency_sensor"
CONF_ISEE_SENSOR = "isee_sensor"
CONF_STAGE_SENSOR = "stage_sensor"
CONF_SUB_MODE_SENSOR = "sub_mode_sensor"
CONF_AUTO_SUB_MODE_SENSOR = "auto_sub_mode_sensor"

DEFAULT_CLIMATE_MODES = ["COOL", "HEAT", "DRY", "FAN_ONLY"]
DEFAULT_FAN_MODES = ["AUTO", "QUIET", "LOW", "MEDIUM", "HIGH"]
DEFAULT_CLIMATE_MODES = ["AUTO", "COOL", "HEAT", "DRY", "FAN_ONLY"]
DEFAULT_FAN_MODES = ["AUTO", "MIDDLE", "QUIET", "LOW", "MEDIUM", "HIGH"]
DEFAULT_SWING_MODES = ["OFF", "VERTICAL", "HORIZONTAL", "BOTH"]


Expand All @@ -43,6 +46,9 @@
)

ISeeSensor = cg.global_ns.class_("ISeeSensor", binary_sensor.BinarySensor, cg.Component)
StageSensor = cg.global_ns.class_("StageSensor", text_sensor.TextSensor, cg.Component)
SubModSensor = cg.global_ns.class_("SubModSensor", text_sensor.TextSensor, cg.Component)
AutoSubModSensor = cg.global_ns.class_("AutoSubModSensor", text_sensor.TextSensor, cg.Component)


def valid_uart(uart):
Expand All @@ -68,6 +74,17 @@ def valid_uart(uart):
{cv.GenerateID(CONF_ID): cv.declare_id(ISeeSensor)}
)

STAGE_SENSOR_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend(
{cv.GenerateID(CONF_ID): cv.declare_id(StageSensor)}
)

SUB_MODE_SENSOR_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend(
{cv.GenerateID(CONF_ID): cv.declare_id(SubModSensor)}
)

AUTO_SUB_MODE_SENSOR_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend(
{cv.GenerateID(CONF_ID): cv.declare_id(AutoSubModSensor)}
)

CONFIG_SCHEMA = climate.CLIMATE_SCHEMA.extend(
{
Expand All @@ -85,6 +102,9 @@ def valid_uart(uart):
cv.Optional(CONF_VERTICAL_SWING_SELECT): SELECT_SCHEMA,
cv.Optional(CONF_COMPRESSOR_FREQUENCY_SENSOR): SENSOR_SCHEMA,
cv.Optional(CONF_ISEE_SENSOR): ISEE_SENSOR_SCHEMA,
cv.Optional(CONF_STAGE_SENSOR): STAGE_SENSOR_SCHEMA,
cv.Optional(CONF_SUB_MODE_SENSOR): SUB_MODE_SENSOR_SCHEMA,
cv.Optional(CONF_AUTO_SUB_MODE_SENSOR): AUTO_SUB_MODE_SENSOR_SCHEMA,
cv.Optional(CONF_REMOTE_TEMP_TIMEOUT, default="never"): cv.All(
cv.update_interval
),
Expand Down Expand Up @@ -160,10 +180,27 @@ def to_code(config):
yield cg.register_component(bsensor_, conf)
cg.add(var.set_isee_sensor(bsensor_))

if CONF_STAGE_SENSOR in config:
conf = config[CONF_STAGE_SENSOR]
tsensor_ = yield text_sensor.new_text_sensor(conf)
yield cg.register_component(tsensor_, conf)
cg.add(var.set_stage_sensor(tsensor_))

if CONF_SUB_MODE_SENSOR in config:
conf = config[CONF_SUB_MODE_SENSOR]
tsensor_ = yield text_sensor.new_text_sensor(conf)
yield cg.register_component(tsensor_, conf)
cg.add(var.set_sub_mode_sensor(tsensor_))

if CONF_AUTO_SUB_MODE_SENSOR in config:
conf = config[CONF_AUTO_SUB_MODE_SENSOR]
tsensor_ = yield text_sensor.new_text_sensor(conf)
yield cg.register_component(tsensor_, conf)
cg.add(var.set_auto_sub_mode_sensor(tsensor_))

yield cg.register_component(var, config)
yield climate.register_climate(var, config)


## cg.add_library(
## name="HeatPump",
## repository="https://github.com/SwiCago/HeatPump",
Expand Down
30 changes: 25 additions & 5 deletions components/cn105/climateControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ void CN105Climate::control(const esphome::climate::ClimateCall& call) {
controlTemperature();
}

if (call.get_target_temperature_low().has_value()) {
// Changer la température cible
ESP_LOGI("control", "Setting heatpump low setpoint : %.1f", *call.get_target_temperature_low());
this->target_temperature_low = *call.get_target_temperature_low();
updated = true;
controlTemperature();
}
if (call.get_target_temperature_high().has_value()) {
// Changer la température cible
ESP_LOGI("control", "Setting heatpump high setpoint : %.1f", *call.get_target_temperature_high());
this->target_temperature_high = *call.get_target_temperature_high();
updated = true;
controlTemperature();
}

if (call.get_fan_mode().has_value()) {
ESP_LOGD("control", "Fan change asked");
// Changer le mode de ventilation
Expand Down Expand Up @@ -150,6 +165,10 @@ void CN105Climate::controlFan() {
void CN105Climate::controlTemperature() {
float setting = this->target_temperature;

float cool_setpoint = this->target_temperature_low;
float heat_setpoint = this->target_temperature_high;
//float humidity_setpoint = this->target_humidity;

if (!this->tempMode) {
this->wantedSettings.temperature = this->lookupByteMapIndex(TEMP_MAP, 16, (int)(setting + 0.5)) > -1 ? setting : TEMP_MAP[0];
} else {
Expand Down Expand Up @@ -178,8 +197,8 @@ void CN105Climate::controlMode() {
this->setModeSetting("DRY");
this->setPowerSetting("ON");
break;
case climate::CLIMATE_MODE_HEAT_COOL:
ESP_LOGI("control", "changing mode to HEAT_COOL");
case climate::CLIMATE_MODE_AUTO:
ESP_LOGI("control", "changing mode to AUTO");
this->setModeSetting("AUTO");
this->setPowerSetting("ON");
break;
Expand All @@ -193,7 +212,7 @@ void CN105Climate::controlMode() {
this->setPowerSetting("OFF");
break;
default:
ESP_LOGW("control", "mode non pris en charge");
ESP_LOGW("control", "unsupported mode");
}
}

Expand Down Expand Up @@ -223,6 +242,7 @@ void CN105Climate::setActionIfOperatingAndCompressorIsActiveTo(climate::ClimateA
}
}

//inside the below we could implement an internal only HEAT_COOL doing the math with an offset or something
void CN105Climate::updateAction() {
ESP_LOGV(TAG, "updating action back to espHome...");
switch (this->mode) {
Expand All @@ -234,10 +254,10 @@ void CN105Climate::updateAction() {
//this->setActionIfOperatingAndCompressorIsActiveTo(climate::CLIMATE_ACTION_COOLING);
this->setActionIfOperatingTo(climate::CLIMATE_ACTION_COOLING);
break;
case climate::CLIMATE_MODE_HEAT_COOL:
case climate::CLIMATE_MODE_AUTO:
//this->setActionIfOperatingAndCompressorIsActiveTo(
this->setActionIfOperatingTo(
(this->current_temperature > this->target_temperature ?
(this->current_temperature > this->target_temperature ?
climate::CLIMATE_ACTION_COOLING :
climate::CLIMATE_ACTION_HEATING));
break;
Expand Down
10 changes: 4 additions & 6 deletions components/cn105/cn105.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CN105Climate::CN105Climate(uart::UARTComponent* uart) :


this->traits_.set_supported_modes({
//climate::CLIMATE_MODE_AUTO,
//climate::CLIMATE_MODE_HEAT_COOL,
climate::CLIMATE_MODE_COOL,
climate::CLIMATE_MODE_DRY,
climate::CLIMATE_MODE_FAN_ONLY,
Expand All @@ -25,19 +25,19 @@ CN105Climate::CN105Climate(uart::UARTComponent* uart) :

this->traits_.set_supported_fan_modes({
climate::CLIMATE_FAN_AUTO,
climate::CLIMATE_FAN_MIDDLE,
climate::CLIMATE_FAN_QUIET,
climate::CLIMATE_FAN_LOW,
climate::CLIMATE_FAN_HIGH,
climate::CLIMATE_FAN_MEDIUM });


this->traits_.set_supported_swing_modes({
//climate::CLIMATE_SWING_BOTH,
//climate::CLIMATE_SWING_HORIZONTAL,
climate::CLIMATE_SWING_BOTH,
climate::CLIMATE_SWING_HORIZONTAL,
climate::CLIMATE_SWING_VERTICAL,
climate::CLIMATE_SWING_OFF });


this->isConnected_ = false;
this->tempMode = false;
this->wideVaneAdj = false;
Expand All @@ -64,8 +64,6 @@ CN105Climate::CN105Climate(uart::UARTComponent* uart) :





void CN105Climate::set_baud_rate(int baud) {
this->baud_ = baud;
ESP_LOGI(TAG, "setting baud rate to: %d", baud);
Expand Down
22 changes: 13 additions & 9 deletions components/cn105/cn105.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
#include "heatpumpFunctions.h"
#include "van_orientation_select.h"
#include "compressor_frequency_sensor.h"
#include "auto_sub_mode_sensor.h"
#include "isee_sensor.h"
#include "stage_sensor.h"
#include "sub_mode_sensor.h"
#include <esphome/components/sensor/sensor.h>
#include <esphome/components/binary_sensor/binary_sensor.h>

using namespace esphome;


//class VaneOrientationSelect; // Déclaration anticipée, définie dans extraComponents



class CN105Climate : public climate::Climate, public Component, public uart::UARTDevice {

//friend class VaneOrientationSelect;
Expand All @@ -22,14 +22,20 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR

CN105Climate(uart::UARTComponent* hw_serial);


void set_vertical_vane_select(VaneOrientationSelect* vertical_vane_select);
void set_horizontal_vane_select(VaneOrientationSelect* horizontal_vane_select);
void set_compressor_frequency_sensor(esphome::sensor::Sensor* compressor_frequency_sensor);
void set_isee_sensor(esphome::binary_sensor::BinarySensor* iSee_sensor);
void set_stage_sensor(esphome::text_sensor::TextSensor* Stage_sensor);
void set_sub_mode_sensor(esphome::text_sensor::TextSensor* Sub_mode_sensor);
void set_auto_sub_mode_sensor(esphome::text_sensor::TextSensor* Auto_sub_mode_sensor);

//sensor::Sensor* compressor_frequency_sensor;
binary_sensor::BinarySensor* iSee_sensor_ = nullptr;
text_sensor::TextSensor* Stage_sensor_ = nullptr;
text_sensor::TextSensor* Sub_mode_sensor_ = nullptr;
text_sensor::TextSensor* Auto_sub_mode_sensor_ = nullptr;

//select::Select* van_orientation;


Expand Down Expand Up @@ -58,9 +64,6 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR
return setup_priority::AFTER_WIFI; // Configurez ce composant après le WiFi
}




void generateExtraComponents();

void setup() override;
Expand Down Expand Up @@ -148,6 +151,8 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR
void initBytePointer();
void processDataPacket();
void getDataFromResponsePacket();
void getAutoModeStateFromResponsePacket(); //NET added
void getPowerFromResponsePacket(); //NET added
void getSettingsFromResponsePacket();
void getRoomTemperatureFromResponsePacket();
void getOperatingAndCompressorFreqFromResponsePacket();
Expand All @@ -163,8 +168,8 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR
void setVaneSetting(const char* setting);
void setWideVaneSetting(const char* setting);
void setFanSpeed(const char* setting);
private:

private:
const char* lookupByteMapValue(const char* valuesMap[], const uint8_t byteMap[], int len, uint8_t byteValue, const char* debugInfo = "", const char* defaultValue = nullptr);
int lookupByteMapValue(const int valuesMap[], const uint8_t byteMap[], int len, uint8_t byteValue, const char* debugInfo = "");
int lookupByteMapIndex(const char* valuesMap[], int len, const char* lookupValue, const char* debugInfo = "");
Expand Down Expand Up @@ -205,7 +210,6 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR
heatpumpSettings currentSettings{};
wantedHeatpumpSettings wantedSettings{};


unsigned long lastResponseMs;

uint32_t remote_temp_timeout_;
Expand Down
5 changes: 3 additions & 2 deletions components/cn105/componentEntries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
*/
void CN105Climate::setup() {

ESP_LOGD(TAG, "Initialisation du composant: appel de setup()");
ESP_LOGD(TAG, "Component initialization: setup call");
this->current_temperature = NAN;

this->target_temperature = NAN;

this->fan_mode = climate::CLIMATE_FAN_OFF;
this->swing_mode = climate::CLIMATE_SWING_OFF;
this->initBytePointer();
Expand Down Expand Up @@ -56,7 +58,6 @@ void CN105Climate::loop() {
}



/**
* Programs the sending of a request
*/
Expand Down
Loading

0 comments on commit a543ca0

Please sign in to comment.