From 5b4f71179dddf3394290fa73aa4910bcc484f252 Mon Sep 17 00:00:00 2001 From: kr0ner Date: Sat, 23 Nov 2024 23:50:15 +0100 Subject: [PATCH] Adds power sensors for fan and el. heating --- src/callback_handler.h | 12 +++++++++++ yaml/wp_base.yaml | 43 ++++++++++++++++++++++++++++++++++++++++ yaml/wp_ventilation.yaml | 6 ++++++ 3 files changed, 61 insertions(+) diff --git a/src/callback_handler.h b/src/callback_handler.h index 45b8de8..6956681 100644 --- a/src/callback_handler.h +++ b/src/callback_handler.h @@ -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>& keys, + std::function 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 diff --git a/yaml/wp_base.yaml b/yaml/wp_base.yaml index 1a80022..67227d0 100644 --- a/yaml/wp_base.yaml +++ b/yaml/wp_base.yaml @@ -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 # @@ -62,6 +86,25 @@ switch: - lambda: |- sendData(HK1, Property::kKUEHLMODE, static_cast(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 # diff --git a/yaml/wp_ventilation.yaml b/yaml/wp_ventilation.yaml index 33c023d..3c17787 100644 --- a/yaml/wp_ventilation.yaml +++ b/yaml/wp_ventilation.yaml @@ -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: