Skip to content

Commit

Permalink
Merge pull request #29 from blacklizard/experimental/power_consumption
Browse files Browse the repository at this point in the history
Experimental/power consumption for CZ-TACG1
  • Loading branch information
DomiStyle authored Oct 4, 2021
2 parents 4a36613 + 493e962 commit ad894f4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions components/panasonic_ac/climate.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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,
),
}
),
}
Expand Down Expand Up @@ -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))
11 changes: 11 additions & 0 deletions components/panasonic_ac/esppac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down
19 changes: 11 additions & 8 deletions components/panasonic_ac/esppac.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,23 @@ 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);

void setup() override;
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_;
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion components/panasonic_ac/esppac_cnt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions components/panasonic_ac/esppac_cnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad894f4

Please sign in to comment.