diff --git a/driver.h b/driver.h index e3114e5..61e7a1c 100755 --- a/driver.h +++ b/driver.h @@ -278,6 +278,46 @@ struct Driver return ret_val; }; + esphome::optional get_615B(std::vector &telegram) { + esphome::optional ret_val{}; + uint32_t temperature = 0; + size_t i = 11; + uint32_t temperature_register = 0x615B; + while (i < telegram.size()) { + uint32_t c = (((uint32_t) telegram[i + 0] << 8) | ((uint32_t) telegram[i + 1])); + if (c == temperature_register) { + i += 2; + temperature = ((uint32_t) telegram[i + 0]); + // in celcius degrees + ret_val = temperature / 1.0; + ESP_LOGVV(TAG, "Found register '615B' with '%d'->'%f'", temperature, ret_val.value()); + break; + } + i++; + } + return ret_val; + }; + + esphome::optional get_6167(std::vector &telegram) { + esphome::optional ret_val{}; + uint32_t temperature = 0; + size_t i = 11; + uint32_t temperature_register = 0x6167; + while (i < telegram.size()) { + uint32_t c = (((uint32_t) telegram[i + 0] << 8) | ((uint32_t) telegram[i + 1])); + if (c == temperature_register) { + i += 2; + temperature = ((uint32_t) telegram[i + 0]); + // in celcius degrees + ret_val = temperature / 1.0; + ESP_LOGVV(TAG, "Found register '6167' with '%d'->'%f'", temperature, ret_val.value()); + break; + } + i++; + } + return ret_val; + }; + esphome::optional get_040F(std::vector &telegram) { esphome::optional ret_val{}; uint32_t usage = 0; diff --git a/driver_multical21.h b/driver_multical21.h index 8c9a36f..93467e9 100644 --- a/driver_multical21.h +++ b/driver_multical21.h @@ -16,10 +16,10 @@ struct Multical21: Driver virtual esphome::optional> get_values(std::vector &telegram) override { std::map ret_val{}; - add_to_map(ret_val, "total_water_m3", this->get_0413(telegram)); - add_to_map(ret_val, "target_water_m3", this->get_4413(telegram)); - // add_to_map(ret_val, "flow_temperature_c", this->get_615B(telegram)); - // add_to_map(ret_val, "external_temperature_c", this->get_6167(telegram)); + add_to_map(ret_val, "total_water_m3", this->get_total_water_m3(telegram)); + add_to_map(ret_val, "target_water_m3", this->get_target_water_m3(telegram)); + add_to_map(ret_val, "flow_temperature_c", this->get_flow_temperature_c(telegram)); + add_to_map(ret_val, "external_temperature_c", this->get_external_temperature_c(telegram)); if (ret_val.size() > 0) { return ret_val; @@ -30,4 +30,87 @@ struct Multical21: Driver }; private: + esphome::optional get_total_water_m3(std::vector &telegram) { + esphome::optional ret_val{}; + uint8_t tpl_ci_field = telegram[19]; + + if (tpl_ci_field == 0x78) { + return this->get_0413(telegram); + } + + if (tpl_ci_field == 0x79) { // check !!!! + uint32_t total_water{0}; + uint8_t i = 26; // check !!!! + total_water = ((uint32_t) telegram[i + 3] << 24) | ((uint32_t) telegram[i + 2] << 16) | + ((uint32_t) telegram[i + 1] << 8) | ((uint32_t) telegram[i + 0]); + // in m3 + ret_val = total_water / 1000.0; + ESP_LOGVV(TAG, "Found total_water_consumption with '%d'->'%f'", total_water, ret_val.value()); + } + + return ret_val; + }; + + esphome::optional get_target_water_m3(std::vector &telegram) { + esphome::optional ret_val{}; + uint8_t tpl_ci_field = telegram[19]; + + if (tpl_ci_field == 0x78) { + return this->get_4413(telegram); + } + + if (tpl_ci_field == 0x79) { // check !!!! + uint32_t target_water{0}; + uint8_t i = 30; // check !!!! + target_water = ((uint32_t) telegram[i + 3] << 24) | ((uint32_t) telegram[i + 2] << 16) | + ((uint32_t) telegram[i + 1] << 8) | ((uint32_t) telegram[i + 0]); + // in m3 + ret_val = target_water / 1000.0; + ESP_LOGVV(TAG, "Found target_water_consumption with '%d'->'%f'", target_water, ret_val.value()); + } + + return ret_val; + }; + + esphome::optional get_flow_temperature_c(std::vector &telegram) { + esphome::optional ret_val{}; + uint8_t l_field = telegram[0]; + uint8_t tpl_ci_field = telegram[19]; + + if ((tpl_ci_field == 0x78) && (l_field >= 39)) { + return this->get_615B(telegram); + } + + if ((tpl_ci_field == 0x79) && (l_field >= 34)) { // check !!!! + uint32_t temperature{0}; + uint8_t i = 34; // check !!!! + temperature = ((uint32_t) telegram[i + 0]); + // in celcius degrees + ret_val = temperature / 1.0; + ESP_LOGVV(TAG, "Found flow_temperature_c with '%d'->'%f'", temperature, ret_val.value()); + } + + return ret_val; + }; + + esphome::optional get_external_temperature_c(std::vector &telegram) { + esphome::optional ret_val{}; + uint8_t l_field = telegram[0]; + uint8_t tpl_ci_field = telegram[19]; + + if ((tpl_ci_field == 0x78) && (l_field >= 42)) { + return this->get_6167(telegram); + } + + if ((tpl_ci_field == 0x79) && (l_field >= 35)) { // check !!!! + uint32_t temperature{0}; + uint8_t i = 35; // check !!!! + temperature = ((uint32_t) telegram[i + 0]); + // in celcius degrees + ret_val = temperature / 1.0; + ESP_LOGVV(TAG, "Found external_temperature_c with '%d'->'%f'", temperature, ret_val.value()); + } + + return ret_val; + }; }; \ No newline at end of file