From 1de9ab5abe8df3ea8c7a2fb84d92cc7b8e0d1dfe Mon Sep 17 00:00:00 2001 From: blacklizard Date: Mon, 30 Aug 2021 00:56:29 +0800 Subject: [PATCH 1/2] expiremantal power consumption CZ-TACG1 --- components/panasonic_ac/climate.py | 13 +++++++++++++ components/panasonic_ac/esppac.cpp | 11 +++++++++++ components/panasonic_ac/esppac.h | 19 +++++++++++-------- components/panasonic_ac/esppac_cnt.cpp | 11 ++++++++++- components/panasonic_ac/esppac_cnt.h | 1 + 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/components/panasonic_ac/climate.py b/components/panasonic_ac/climate.py index d6a0b09..0d02fc1 100644 --- a/components/panasonic_ac/climate.py +++ b/components/panasonic_ac/climate.py @@ -1,8 +1,10 @@ from esphome.const import ( CONF_ID, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, + UNIT_WATT, ) import esphome.codegen as cg import esphome.config_validation as cv @@ -36,6 +38,7 @@ CONF_ECO_SWITCH = "eco_switch" CONF_ECONAVI_SWITCH = "econavi_switch" CONF_MILD_DRY_SWITCH = "mild_dry_switch" +CONF_CURRENT_POWER_CONSUMPTION = "current_power_consumption" CONF_WLAN = "wlan" CONF_CNT = "cnt" @@ -86,6 +89,12 @@ cv.Optional(CONF_ECONAVI_SWITCH): SWITCH_SCHEMA, cv.Optional(CONF_MILD_DRY_SWITCH): SWITCH_SCHEMA, cv.Optional(CONF_CURRENT_TEMPERATURE_SENSOR): cv.use_id(sensor.Sensor), + cv.Optional(CONF_CURRENT_POWER_CONSUMPTION): sensor.sensor_schema( + unit_of_measurement=UNIT_WATT, + accuracy_decimals=0, + device_class=DEVICE_CLASS_POWER, + state_class=STATE_CLASS_MEASUREMENT, + ), } ), } @@ -125,3 +134,7 @@ async def to_code(config): if CONF_CURRENT_TEMPERATURE_SENSOR in config: sens = await cg.get_variable(config[CONF_CURRENT_TEMPERATURE_SENSOR]) cg.add(var.set_current_temperature_sensor(sens)) + + if CONF_CURRENT_POWER_CONSUMPTION in config: + sens = await sensor.new_sensor(config[CONF_CURRENT_POWER_CONSUMPTION]) + cg.add(var.set_current_power_consumption_sensor(sens)) diff --git a/components/panasonic_ac/esppac.cpp b/components/panasonic_ac/esppac.cpp index 35e1b27..0284551 100644 --- a/components/panasonic_ac/esppac.cpp +++ b/components/panasonic_ac/esppac.cpp @@ -153,6 +153,13 @@ climate::ClimateAction PanasonicAC::determine_action() { } } +void PanasonicAC::update_current_power_consumption(int16_t power) { + if (this->current_power_consumption_sensor_ != nullptr && this->current_power_consumption_sensor_->state != power) { + this->current_power_consumption_sensor_->publish_state( + power); // Set current power consumption + } +} + /* * Sensor handling */ @@ -225,6 +232,10 @@ void PanasonicAC::set_mild_dry_switch(switch_::Switch *mild_dry_switch) { }); } +void PanasonicAC::set_current_power_consumption_sensor(sensor::Sensor *current_power_consumption_sensor) { + this->current_power_consumption_sensor_ = current_power_consumption_sensor; +} + /* * Debugging */ diff --git a/components/panasonic_ac/esppac.h b/components/panasonic_ac/esppac.h index bc25850..8735d03 100644 --- a/components/panasonic_ac/esppac.h +++ b/components/panasonic_ac/esppac.h @@ -39,6 +39,7 @@ class PanasonicAC : public Component, public uart::UARTDevice, public climate::C void set_eco_switch(switch_::Switch *eco_switch); void set_econavi_switch(switch_::Switch *econavi_switch); void set_mild_dry_switch(switch_::Switch *mild_dry_switch); + void set_current_power_consumption_sensor(sensor::Sensor *current_power_consumption_sensor); void set_current_temperature_sensor(sensor::Sensor *current_temperature_sensor); @@ -46,14 +47,15 @@ class PanasonicAC : public Component, public uart::UARTDevice, public climate::C void loop() override; protected: - sensor::Sensor *outside_temperature_sensor_ = nullptr; // Sensor to store outside temperature from queries - select::Select *vertical_swing_select_ = nullptr; // Select to store manual position of vertical swing - select::Select *horizontal_swing_select_ = nullptr; // Select to store manual position of horizontal swing - switch_::Switch *nanoex_switch_ = nullptr; // Switch to toggle nanoeX on/off - switch_::Switch *eco_switch_ = nullptr; // Switch to toggle eco mode on/off - switch_::Switch *econavi_switch_ = nullptr; // Switch to toggle econavi mode on/off - switch_::Switch *mild_dry_switch_ = nullptr; // Switch to toggle mild dry mode on/off - sensor::Sensor *current_temperature_sensor_ = nullptr; // Sensor to use for current temperature where AC does not report + sensor::Sensor *outside_temperature_sensor_ = nullptr; // Sensor to store outside temperature from queries + select::Select *vertical_swing_select_ = nullptr; // Select to store manual position of vertical swing + select::Select *horizontal_swing_select_ = nullptr; // Select to store manual position of horizontal swing + switch_::Switch *nanoex_switch_ = nullptr; // Switch to toggle nanoeX on/off + switch_::Switch *eco_switch_ = nullptr; // Switch to toggle eco mode on/off + switch_::Switch *econavi_switch_ = nullptr; // Switch to toggle econavi mode on/off + switch_::Switch *mild_dry_switch_ = nullptr; // Switch to toggle mild dry mode on/off + sensor::Sensor *current_temperature_sensor_ = nullptr; // Sensor to use for current temperature where AC does not report + sensor::Sensor *current_power_consumption_sensor_ = nullptr; // Sensor to store current power consumption from queries std::string vertical_swing_state_; std::string horizontal_swing_state_; @@ -88,6 +90,7 @@ class PanasonicAC : public Component, public uart::UARTDevice, public climate::C void update_eco(bool eco); void update_econavi(bool econavi); void update_mild_dry(bool mild_dry); + void update_current_power_consumption(int16_t power); virtual void on_horizontal_swing_change(const std::string &swing) = 0; virtual void on_vertical_swing_change(const std::string &swing) = 0; diff --git a/components/panasonic_ac/esppac_cnt.cpp b/components/panasonic_ac/esppac_cnt.cpp index c68e0e7..5be8ef9 100644 --- a/components/panasonic_ac/esppac_cnt.cpp +++ b/components/panasonic_ac/esppac_cnt.cpp @@ -157,7 +157,7 @@ void PanasonicACCNT::set_data(bool set) { bool eco = determine_eco(this->data[8]); bool econavi = determine_econavi(this->data[5]); bool mildDry = determine_mild_dry(this->data[2]); - + this->update_target_temperature((int8_t) this->data[1]); if (set) { @@ -181,6 +181,11 @@ void PanasonicACCNT::set_data(bool set) { else ESP_LOGV(TAG, "Outside temperature is not supported"); } + + if(this->current_power_consumption_sensor_ != nullptr) { + uint16_t power_consumption = determine_power_consumption((int8_t)this->rx_buffer_[28], (int8_t)this->rx_buffer_[29], (int8_t)this->rx_buffer_[30]); + this->update_current_power_consumption(power_consumption); + } } if (verticalSwing == "auto" && horizontalSwing == "auto") @@ -457,6 +462,10 @@ bool PanasonicACCNT::determine_mild_dry(uint8_t value) { } } +uint16_t PanasonicACCNT::determine_power_consumption(uint8_t byte_28, uint8_t multiplier, uint8_t offset) { + return (uint16_t)(byte_28 + (multiplier * 255)) - offset; +} + /* * Sensor handling */ diff --git a/components/panasonic_ac/esppac_cnt.h b/components/panasonic_ac/esppac_cnt.h index f90ea7d..63b7ab2 100644 --- a/components/panasonic_ac/esppac_cnt.h +++ b/components/panasonic_ac/esppac_cnt.h @@ -56,6 +56,7 @@ class PanasonicACCNT : public PanasonicAC { bool determine_eco(uint8_t value); bool determine_econavi(uint8_t value); bool determine_mild_dry(uint8_t value); + uint16_t determine_power_consumption(uint8_t byte_28, uint8_t multiplier, uint8_t offset); }; } // namespace CNT From 493e9621771cc02b5183f0275cd52ae05f53500f Mon Sep 17 00:00:00 2001 From: blacklizard Date: Mon, 4 Oct 2021 03:20:49 +0800 Subject: [PATCH 2/2] Update readme with config sample for power consumption and econavi --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f4fb585..f4f6a6d 100644 --- a/README.md +++ b/README.md @@ -59,11 +59,16 @@ Since Panasonic ACs support different features you can comment out the lines at # name: Panasonic AC NanoeX Switch # mild_dry_switch: # name: Panasonic AC Mild Dry Switch + # econavi_switch: + # name: Econavi switch + # current_power_consumption: + # name: Panasonic AC Power Consumption ``` In order to find out which features are supported by your AC, check the remote that came with it. Please note that eco switch and mild dry switch are not supported on DNSK-P11. **Enabling unsupported features can lead to undefined behavior and may damage your AC. Make sure to check your remote or manual first.** +**current_power_consumption is just as ESTIMATED value by the AC** ## Upgrading from 1.x to 2.x