Skip to content

Commit

Permalink
Adds power sensors for fan and el. heating
Browse files Browse the repository at this point in the history
  • Loading branch information
kr0ner committed Nov 28, 2024
1 parent 2e6a9ab commit 5b4f711
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/callback_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@

class CallbackHandler {
public:
/**
* @brief For every given key adds a callback that will be executed every time a CAN message
* with the specified \c Property is received for the given \c CanMember. The callback
* needs to ensure that only one source is actively handled at a time to prevent toggling.
*/
void addCallbacks(const std::vector<std::pair<CanMember, Property>>& keys,
std::function<void(const SimpleVariant&)> callback) {
for (const auto& key : keys) {
addCallback(key, callback);
}
}

/**
* @brief Adds a callback that will be executed every time a CAN message with the specified
* \c Property is received for the given \c CanMember. The callback usually takes care of
Expand Down
43 changes: 43 additions & 0 deletions yaml/wp_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ esphome:
id(LUEFTUNG).publish_state(zuluftIst > 0U);
});
CallbackHandler::instance().addCallbacks({std::make_pair(Kessel,Property::kABLUFT_SOLL),
std::make_pair(Kessel,Property::kZULUFT_SOLL)},
[](const SimpleVariant&) {
const auto airflowIn{id(ZULUFT_SOLL).state};
const auto airflowOut{id(ABLUFT_SOLL).state};
auto getPower = [](const float airflow){
if(airflow < 0.1f) {
return 0.0f;
}
/* This equation is base on the following measurement:
* airflow (l/min) : 0 140 190 220 300
* combined fan power (W): 0 30 50 80 170
* @note: the last value is taken as from the THZ504 specification.
*/
return (0.00005f * std::pow(airflow, 2.5f) + 3.0f);
};
id(FAN_POWER).publish_state(getPower(airflowIn) + getPower(airflowOut));
});
id(ELEKTRISCHE_NACHERWAERMUNG).add_on_state_callback([](const bool state){
const auto electricHeatingPower = state ? id(NE_STUFE_WW).state * 230.0 /*V*/ * 16.0 /*A*/ : 0.0f;
id(ELECTRIC_HEATING_POWER).publish_state(electricHeatingPower);
});
#########################################
# #
# Selects #
Expand Down Expand Up @@ -62,6 +86,25 @@ switch:
- lambda: |-
sendData(HK1, Property::kKUEHLMODE, static_cast<std::uint16_t>(false));
#########################################
# #
# Template Sensors #
# #
#########################################
sensor:
- platform: template
name: "FAN POWER"
id: FAN_POWER
state_class: measurement
device_class: power
unit_of_measurement: "W"
- platform: template
name: "ELECTRIC HEATING POWER"
id: ELECTRIC_HEATING_POWER
state_class: measurement
device_class: power
unit_of_measurement: "W"

#########################################
# #
# Packages #
Expand Down
6 changes: 6 additions & 0 deletions yaml/wp_ventilation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ fan:
const auto fan_speed = std::min(3, x);
ESP_LOGI("fan", "Speed set %d", fan_speed);
sendData(Kessel, Property::k${property}, fan_speed);
queueRequest(Kessel, Property::kZULUFT_SOLL);
queueRequest(Kessel, Property::kABLUFT_SOLL);
on_turn_off:
- lambda: |-
ESP_LOGI("fan", "Fan turned off!");
sendData(Kessel, Property::k${property}, 0U);
queueRequest(Kessel, Property::kZULUFT_SOLL);
queueRequest(Kessel, Property::kABLUFT_SOLL);
on_turn_on:
- lambda: |-
ESP_LOGI("fan", "Fan turned on!");
sendData(Kessel, Property::k${property}, id(${property}).speed);
queueRequest(Kessel, Property::kZULUFT_SOLL);
queueRequest(Kessel, Property::kABLUFT_SOLL);
esphome:
on_boot:
Expand Down

0 comments on commit 5b4f711

Please sign in to comment.